/[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 457 by dpavlin, Wed Nov 19 16:53:13 2008 UTC revision 592 by dpavlin, Fri Nov 28 16:44:16 2008 UTC
# Line 2  package Frey::Run; Line 2  package Frey::Run;
2  use Moose;  use Moose;
3  #extends 'Frey::ClassLoader';  #extends 'Frey::ClassLoader';
4  extends 'Frey::Action';  extends 'Frey::Action';
 with 'Frey::Web';  
 with 'Frey::Escape';  
5  with 'Frey::Session';  with 'Frey::Session';
6    
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8  use Frey::Dumper;  use Frey::View::Dumper;
9  use JSON;  use JSON;
10  use YAML;  use YAML;
11    
# Line 30  use Moose::Util::TypeConstraints; Line 28  use Moose::Util::TypeConstraints;
28    
29  subtype 'Runnable'  subtype 'Runnable'
30          => as 'Str',          => as 'Str',
31          => where sub { m{^as_} };          => where sub { m{^as_} || m{_as_} };
32    
33  sub formats_available { qw/html js json yaml yml/ }  sub formats_available { qw/html js json yaml yml/ }
34  enum 'Formats' => formats_available;  enum 'Formats' => formats_available;
# Line 67  sub html { Line 65  sub html {
65                  my $class = $self->class;                  my $class = $self->class;
66                  $self->load_class( $class );                  $self->load_class( $class );
67    
68                  if ( $body = $self->params_form ) {                  if ( my $form = $self->params_form ) {
69                            $html = $self->page( body => $form );
70                          warn "got required params form for $class ", $self->run, " format: ", $self->format;                          warn "got required params form for $class ", $self->run, " format: ", $self->format;
71                  } else {                  } else {
72    
73                          $self->usage->{ $class }++;                          $self->usage->{ $class }++;
74    
75    =begin remove
76    
77                          my $o;                          my $o;
78                          my ( $meta, $is_role, $instance ) = $self->class_meta( $class );                          my ( $meta, $is_role, $instance ) = $self->class_meta( $class );
79                          if ( $is_role ) {                          if ( $is_role ) {
80                                  $o = $instance;                                  $o = $instance;
81                                    if ( $o->can('add_status') ) {
82                                            $self->TODO("missing add_status in $o");
83                                            Frey::Web->meta->apply( $o );
84                                            warn "# apply Frey::Web to $class instance $o";
85                                    }
86                          } else {                          } else {
87                                  $o = $self->new_frey_class( $class, $self->params );                                  $o = $self->new_frey_class( $class, $self->params );
88                          }                          }
89    =cut
90    
91                            my $o = $self->new_frey_class( $class, $self->params );
92                          $o->depends if $o->can('depends');                          $o->depends if $o->can('depends');
93    
94                          push @{ $self->status }, { qq|<a target="editor" href="/editor+$class+1">$class</a>| => $self->params };                          if ( $self->run =~ m{as_markup} ) {
95                                    $html = $o->page( run => $self->run );
96                          if ( $self->run eq 'as_markup' ) {                          } elsif ( $self->run =~ m{as_sponge} ) {
                                 warn "## using ",ref($o), "->as_markup";  
                                 if ( $o->can('page') ) {  
                                         $html = $o->page;  
                                 }  
                                 $body = $o->as_markup unless $html;  
   
                                 warn ">>> markup $class ",length( $html || $body ), " ", $html ? 'html' : 'body', " bytes";  
                         } elsif ( $self->run eq 'as_sponge' ) {  
97                                  $data = $o->as_sponge;                                  $data = $o->as_sponge;
98                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
99                                  if ( $self->format eq 'html' ) {                                  if ( $self->format eq 'html' ) {
# Line 105  sub html { Line 105  sub html {
105                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
106                                          $body .= '</table>';                                          $body .= '</table>';
107                                  }                                  }
108                          } elsif ( $self->run eq 'as_data' ) {                          } elsif ( $self->run =~ m{as_data} ) {
109                                  $data = $o->as_data;                                  $data = $o->{$self->run}();
110                                    warn "no data from ", $self->run;
111                                    $data ||= $o->as_data();
112                                    confess "no data for $class->" . $self->run . " from " . $self->html_dump( $data ) unless $data;
113                                    $self->add_status( { $self->run => $data } );
114                          } else {                          } else {
115                                  $body = $self->error( "IGNORE: $class ", $o->dump );                                  $body = $self->error( "IGNORE: $class ", $o->dump );
116                          }                          }
# Line 114  sub html { Line 118  sub html {
118                          if ( defined $data ) {                          if ( defined $data ) {
119                                  $html .= to_json( $data ) if $self->format =~ m{js(on)?};                                  $html .= to_json( $data ) if $self->format =~ m{js(on)?};
120                                  $html .= Dump( $data )    if $self->format =~ m{ya?ml};                                  $html .= Dump( $data )    if $self->format =~ m{ya?ml};
                                 push @{ $self->status }, { 'data' => $data };  
121                          }                          }
122                          if ( ! $html ) {                          if ( ! $html ) {
123                                  $body .= Frey::Dumper->new( data => $data )->as_markup;                                  $body  = Frey::View::Dumper->new( data => $body )->as_markup if ref $body;
124                                    $body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data;
125                          }                          }
126    
127                          # override our status with one from object                          $self->title( $class );
                         eval {  
                                 $self->status( $o->status );  
                         };  
                         warn "can't override status: $@" if $@;  
                 };  
   
128    
129                  if ( ref($body) eq 'HASH' ) {                          $html = $o->page( body => $body ) if $body && !$html;
130                          $html = $self->page( %$body );          
131                  } elsif ( $body && ! $html ) {                          confess "no html output for $class ", $o->dump unless defined $html;
                         $html = $self->page( title => $self->class . ' run', body => $body );  
132                  };                  };
133    
134          };          };
135    
136          $html = $self->page( title => $self->class, body => $self->error( $@ ) ) if $@;          $self->status_parts;
137    
138            if ( $@ ) {
139                    my $o = Frey->new;
140                    Frey::Web->meta->apply( $o );
141                    $html = $o->page( body => $self->error( $@ ) );
142            }
143    
144            warn $self->class, " produced ", length($html), " bytes";
145    
146          return $html;          return $html;
147  }  }

Legend:
Removed from v.457  
changed lines
  Added in v.592

  ViewVC Help
Powered by ViewVC 1.1.26