/[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 591 by dpavlin, Fri Nov 28 16:39:37 2008 UTC revision 887 by dpavlin, Wed Dec 24 13:51:59 2008 UTC
# Line 1  Line 1 
1  package Frey::Run;  package Frey::Run;
2  use Moose;  use Moose;
3  #extends 'Frey::ClassLoader';  #extends 'Frey::Class::Loader';
4  extends 'Frey::Action';  extends 'Frey::Action';
5  with 'Frey::Session';  with 'Frey::Session';
6    
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
 use Frey::View::Dumper;  
8  use JSON;  use JSON;
9  use YAML;  use YAML;
10    
11    use lib 'lib';
12    use Frey::View::Dumper;
13    
14  =head1 NAME  =head1 NAME
15    
16  Frey::Run - display required form field for Class and run it  Frey::Run - display required form field for Class and run it
# Line 25  L<Frey::Action> which creates form for p Line 27  L<Frey::Action> which creates form for p
27  =cut  =cut
28    
29  use Moose::Util::TypeConstraints;  use Moose::Util::TypeConstraints;
30    use Frey::Class::Loader; # class_runnable_re
31    
32  subtype 'Runnable'  subtype 'Runnable'
33          => as 'Str',          => as 'Str',
34          => where sub { m{^as_} || m{_as_} };          => where sub { Frey::Class::Loader::class_runnable_re };
35    
36  sub formats_available { qw/html js json yaml yml/ }  sub formats_available { qw/html js json yaml yml/ }
37  enum 'Formats' => formats_available;  enum 'Formats' => formats_available;
# Line 57  has 'format' => ( Line 60  has 'format' => (
60          default => 'html',          default => 'html',
61  );  );
62    
63    has 'request_url' => (
64            documentation => 'Take url from params if not specified',
65            is => 'rw',
66            isa => 'Uri', coerce => 1,
67            lazy => 1,
68            default => sub {
69                    my $self = shift;
70                    $self->params->{request_url};
71            },
72    );
73    
74  sub html {  sub html {
75          my ( $self ) = @_;          my ( $self ) = @_;
76    
# Line 73  sub html { Line 87  sub html {
87                          $self->usage->{ $class }++;                          $self->usage->{ $class }++;
88    
89  =begin remove  =begin remove
90    
91                          my $o;                          my $o;
92                          my ( $meta, $is_role, $instance ) = $self->class_meta( $class );                          my ( $meta, $is_role, $instance ) = $self->class_meta( $class );
93                          if ( $is_role ) {                          if ( $is_role ) {
# Line 92  sub html { Line 107  sub html {
107    
108                          if ( $self->run =~ m{as_markup} ) {                          if ( $self->run =~ m{as_markup} ) {
109                                  $html = $o->page( run => $self->run );                                  $html = $o->page( run => $self->run );
110                          } elsif ( $self->run =~ m{as_sponge} ) {                          } elsif ( $self->run =~ m{(.*as_sponge)} ) {
111                                  $data = $o->as_sponge;                                  $data = $o->$1;
112                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
113                                  if ( $self->format eq 'html' ) {                                  if ( $self->format eq 'html' ) {
114                                          my $rows = $#{ $data->{rows} } + 1;                                          my $rows = $#{ $data->{rows} } + 1;
# Line 104  sub html { Line 119  sub html {
119                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
120                                          $body .= '</table>';                                          $body .= '</table>';
121                                  }                                  }
122                          } elsif ( $self->run =~ m{as_data} ) {                          } elsif ( $self->run =~ m{(as_data|sql)} ) {
123                                  $data = $o->{$self->run}();                                  my $run = $self->run;
124                                  warn "no data from ", $self->run;                                  $data = $o->$run;
125                                  $data ||= $o->as_data();                                  confess "no data for $class->$run" unless defined $data;
                                 confess "no data for $class->" . $self->run . " from " . $self->html_dump( $data ) unless $data;  
126                                  $self->add_status( { $self->run => $data } );                                  $self->add_status( { $self->run => $data } );
127                          } else {                          } else {
128                                  $body = $self->error( "IGNORE: $class ", $o->dump );                                  $body = $self->error( "IGNORE: $class ", $o->dump );
# Line 123  sub html { Line 137  sub html {
137                                  $body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data;                                  $body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data;
138                          }                          }
139    
140                          $self->title( $class );                          $o->title( $class );
141    
142                          $html = $o->page( body => $body ) if $body && !$html;                          $html = $o->page( body => $body ) if $body && !$html;
143                                    $self->content_type( $o->content_type );
144    
145                          confess "no html output for $class ", $o->dump unless defined $html;                          confess "no html output for $class ", $o->dump unless defined $html;
146                  };                  };
147    
# Line 135  sub html { Line 150  sub html {
150          $self->status_parts;          $self->status_parts;
151    
152          if ( $@ ) {          if ( $@ ) {
153                    my $error = $@;
154                  my $o = Frey->new;                  my $o = Frey->new;
155                    $o->{request_url} = $self->request_url; # sigh, this is dynamic languge, right?
156                  Frey::Web->meta->apply( $o );                  Frey::Web->meta->apply( $o );
157                  $html = $o->page( body => $self->error( $@ ) );                  $html = $o->page( body => $self->error( $error, undef ) );
158          }          }
159    
160          warn $self->class, " produced ", length($html), " bytes";          warn $self->class, " produced ", length($html), " bytes of ", $self->content_type;
161    
162          return $html;          return $html;
163  }  }

Legend:
Removed from v.591  
changed lines
  Added in v.887

  ViewVC Help
Powered by ViewVC 1.1.26