/[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 580 by dpavlin, Thu Nov 27 22:11:13 2008 UTC revision 581 by dpavlin, Fri Nov 28 13:16:47 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';  
5  with 'Frey::Session';  with 'Frey::Session';
6    
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
# Line 29  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 66  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 ( $self->params_form ) {
69                            $html = $self->page;
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    
# Line 82  sub html { Line 82  sub html {
82    
83                          $o->depends if $o->can('depends');                          $o->depends if $o->can('depends');
84    
85                          my @status;                          $o->add_status( { $self->editor( $class ) => $self->params } );
86    
87                          push @status, { $self->editor( $class ) => $self->params };                          if ( $self->run =~ m{as_markup} ) {
88                                    $html = $o->page;
89                          if ( $self->run eq 'as_markup' && ! $o->can('page') ) {                          } elsif ( $self->run =~ m{as_sponge} ) {
                                 warn "## using ",ref($o), "->as_markup";  
                                 $body = $o->as_markup unless $html;  
                                 warn ">>> markup $class ",length( $body ), " ", $html ? 'html' : 'body', " bytes";  
                         } elsif ( $self->run eq 'as_sponge' ) {  
90                                  $data = $o->as_sponge;                                  $data = $o->as_sponge;
91                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
92                                  if ( $self->format eq 'html' ) {                                  if ( $self->format eq 'html' ) {
# Line 102  sub html { Line 98  sub html {
98                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
99                                          $body .= '</table>';                                          $body .= '</table>';
100                                  }                                  }
101                          } elsif ( $self->run eq 'as_data' ) {                          } elsif ( $self->run =~ m{as_data} ) {
102                                  $data = $o->as_data;                                  $data = $o->as_data;
103                          } else {                          } else {
104                                  $body = $self->error( "IGNORE: $class ", $o->dump );                                  $body = $self->error( "IGNORE: $class ", $o->dump );
# Line 111  sub html { Line 107  sub html {
107                          if ( defined $data ) {                          if ( defined $data ) {
108                                  $html .= to_json( $data ) if $self->format =~ m{js(on)?};                                  $html .= to_json( $data ) if $self->format =~ m{js(on)?};
109                                  $html .= Dump( $data )    if $self->format =~ m{ya?ml};                                  $html .= Dump( $data )    if $self->format =~ m{ya?ml};
110                                  push @status, { 'data' => $data };                                  $self->add_status( { 'data' => $data } );
111                          }                          }
112                          if ( ! $html ) {                          if ( ! $html ) {
113                                  $body  = Frey::View::Dumper->new( data => $body )->as_markup if ref $body;                                  $body  = Frey::View::Dumper->new( data => $body )->as_markup if ref $body;
114                                  $body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data;                                  $body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data;
115                          }                          }
116    
                         warn "## status from $self ",dump(@status);  
   
                         if ( $o->can('add_status') ) {  
                                 $o->add_status($_) foreach @status;  
                         }  
   
                         if ( $self->run eq 'as_markup' && $o->can('page') ) {  
                                 $html = $o->page;  
                                 warn "got ", length($html), " for page from $o",  
                                         $self->debug ? " status " . dump( $o->status ) : '';  
                         } else {  
                                 $self->add_status($_) foreach @status;  
                         }  
   
117                          $self->title( $class );                          $self->title( $class );
                 };  
118    
119                  if ( ref($body) eq 'HASH' ) {                          $html = $o->page( body => $body ) if $body && !$html;
                         $html = $self->page( %$body );  
                         warn "WARNING: old calling convention with HASH which is depriciated but produced ", length($html), " bytes";  
                 } elsif ( $body && ! $html ) {  
                         $html = $self->page( title => $self->class . ' run', body => $body );  
                         warn "wrap body of ",length($body), " in page with ", length($html), " bytes";  
120                  };                  };
121    
122          };          };
123    
124          $self->status_parts;          $self->status_parts;
125    
126          $html = $self->page( title => $self->class, body => $self->error( $@ ) ) if $@;          $html = $self->error( $@ ) if $@;
127    
128            warn $self->class, " produced ", length($html), " bytes";
129    
130          return $html;          return $html;
131  }  }

Legend:
Removed from v.580  
changed lines
  Added in v.581

  ViewVC Help
Powered by ViewVC 1.1.26