/[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 348 by dpavlin, Sat Nov 15 23:52:22 2008 UTC revision 358 by dpavlin, Sun Nov 16 16:36:53 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 79  sub html { Line 89  sub html {
89                                                  qq|<option value="$v">$v</option>|                                                  qq|<option value="$v">$v</option>|
90                                          } @$values                                          } @$values
91                                  ) . qq|</select>|;                                  ) . qq|</select>|;
92                          } else {                          } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
93                                  $value = $attr->default( $name ) if $attr->has_default;                                  $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;                          $value_html = qq|<input type="$type" name="$name" value="$value">| unless $value_html;
100    
# Line 89  sub html { Line 103  sub 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 } );                  eval {
107                  $o->depends if $o->can('depends');                          my $o;
108                  if ( $o->can('markup') ) {                          $o = $class->new( %{ $self->params } );
109                          warn "## using ",ref($o), "->markup";                          $o->depends if $o->can('depends');
110                          $html = eval { $o->markup };  
111                          if ( $@ ) {                          if ( $self->run eq 'markup' ) {
112                                  warn $@;                                  warn "## using ",ref($o), "->markup";
113                                  $html .= qq{<code>$@</code>};                                  $html = $o->markup;
114                                    warn ">>> markup $class ",length( $html ), " bytes\n";
115                            } elsif ( $self->run eq 'sponge' ) {
116                                    my $data = $o->sponge;
117                                    confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
118                                    $html .= "<strong>" . $#{ $data->{rows} } . "</strong> rows from <code>$class->new" . dump( $self->params ) . "->sponge</code>";
119                                    $html .= '<table>';
120                                    $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
121                                    $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
122                                    $html .= '</table>';
123                            } elsif ( $self->run eq 'data' ) {
124                                    my $data = $o->data;
125                                    $html .= Frey::Dumper->new( data => $data )->markup;
126                                    $html .= '<hr/><code>' . $self->html_dump( $data ) . '</code>';
127                            } else {
128                                    $html = $self->error( "IGNORE: $class ", $o->dump );
129                          }                          }
130                          warn ">>> markup $class ",length( $html ), " bytes\n";                  };
131                  } elsif ( $o->can('sponge') ) {  
132                          my $data = $o->sponge;                  $html .= $self->error( $@ ) if $@;
                         $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>';  
                 } else {  
                         $html = "IGNORE: $class ", $o->dump;  
                         warn $html;  
                 }  
133          }          }
134    
135            return $self->page( %$html ) if ref($html) eq 'HASH';
136          return $self->page( title => $class, body => $html );          return $self->page( title => $class, body => $html );
137  }  }
138    

Legend:
Removed from v.348  
changed lines
  Added in v.358

  ViewVC Help
Powered by ViewVC 1.1.26