/[Frey]/trunk/lib/Frey/Run.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Run.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 339 by dpavlin, Sat Nov 8 23:34:43 2008 UTC revision 351 by dpavlin, Sun Nov 16 13:01:56 2008 UTC
# Line 20  will try to invoke C<data>, and C<markup Line 20  will try to invoke C<data>, and C<markup
20    
21  =cut  =cut
22    
23    use Moose::Util::TypeConstraints;
24    
25    enum 'Runnable' => qw/data markup sponge/;
26    
27  sub runnable { qw/data markup sponge/ }  sub runnable { qw/data markup sponge/ }
28    
29  has 'class' => (  has 'class' => (
# Line 34  has 'params' => ( Line 38  has 'params' => (
38          default => sub { {} },          default => sub { {} },
39  );  );
40    
41    has 'run' => (
42            is => 'rw',
43            isa => 'Runnable',
44            default => 'markup',
45    );
46    
47  sub html {  sub html {
48          my ( $self ) = @_;          my ( $self ) = @_;
49    
# Line 68  sub html { Line 78  sub html {
78                  foreach my $name ( @attrs ) {                  foreach my $name ( @attrs ) {
79                          my $attr = $class->meta->get_attribute( $name );                          my $attr = $class->meta->get_attribute( $name );
80                          my $type = $name =~ m/^pass/ ? 'password' : 'text';                          my $type = $name =~ m/^pass/ ? 'password' : 'text';
81                          my $value =                          my $value = '';
82                                  $values ? $values->{$name} :                          my $value_html = '';
83                                  $attr->has_default ? $attr->default( $name ) :                          if ( ref($values) eq 'HASH' ) {
84                                  '';                                  $value = $values->{$name};
85                            } elsif ( ref($values) eq 'ARRAY' ) {
86                                    $value_html = qq|<select name="$name">| . join("\n",
87                                            map {
88                                                    my $v = $_->{$name};
89                                                    qq|<option value="$v">$v</option>|
90                                            } @$values
91                                    ) . qq|</select>|;
92                            } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
93                                    $value_html = qq|<select name="$name">| . join("\n",
94                                            map { qq|<option value="$_">$_</option>| } @{ $attr->type_constraint->values }
95                                    ) . qq|</select>|;
96                            } elsif ( $attr->has_default ) {
97                                    $value = $attr->default( $name );
98                            }
99                            $value_html = qq|<input type="$type" name="$name" value="$value">| unless $value_html;
100    
101  #warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );  #warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );
102                          $html .= qq|<label for="$name">$name</label><input type="$type" name="$name" value="$value">|;                          $html .= qq|<label for="$name">$name</label>| . $value_html;
103                  }                  }
104                  $html .= qq|<input type="submit" value="Run $class"></form>|;                  $html .= qq|<input type="submit" value="Run $class"></form>|;
105          } else {          } else {
106                  my $o = $class->new( %{ $self->params } );                  my $o;
107                    eval { $o = $class->new( %{ $self->params } ); };
108                    if ( $@ ) {
109                            return $self->page( title => $class, body => $self->error( $@ ) );
110                    }
111                  $o->depends if $o->can('depends');                  $o->depends if $o->can('depends');
112                  if ( $o->can('markup') ) {  
113                    if ( $self->run eq 'markup' ) {
114                          warn "## using ",ref($o), "->markup";                          warn "## using ",ref($o), "->markup";
115                          $html = eval { $o->markup };                          $html = eval { $o->markup };
116                            $html .= $self->error( $@ ) if $@;
117                            warn ">>> markup $class ",length( $html ), " bytes\n";
118                    } elsif ( $self->run eq 'sponge' ) {
119                            my $data = eval { $o->sponge };
120                          if ( $@ ) {                          if ( $@ ) {
121                                  warn $@;                                  $html .= $self->error( $@ );
122                                  $html .= qq{<code>$@</code>};                          } else {
123                                    $html .= '<table>';
124                                    $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
125                                    $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
126                                    $html .= '</table>';
127                            }
128                    } elsif ( $self->run eq 'data' ) {
129                            my $data = eval { $o->data; };
130                            if ( $@ ) {
131                                    $html .= $self->error( $@ );
132                            } else {
133                                    $html .= Frey::Dumper->new( data => $data )->markup;
134                                    $html .= '<hr/><code>' . $self->html_dump( $data ) . '</code>';
135                          }                          }
                         warn ">>> markup $class ",length( $html ), " bytes\n";  
                 } elsif ( $o->can('sponge') ) {  
                         my $data = $o->sponge;  
                         $html .= '<table>';  
                         $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';  
                         $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };  
                         $html .= '</table>';  
                 } elsif ( $o->can('data') ) {  
                         my $data = $o->data;  
                         $html .= Frey::Dumper->new( data => $data )->markup;  
                         $html .= '<hr/><code>' . $self->html_dump( $data ) . '</code>';  
136                  } else {                  } else {
137                          $html = "IGNORE: $class ", $o->dump;                          $html = $self->error( "IGNORE: $class ", $o->dump );
                         warn $html;  
138                  }                  }
139          }          }
140    

Legend:
Removed from v.339  
changed lines
  Added in v.351

  ViewVC Help
Powered by ViewVC 1.1.26