/[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 835 by dpavlin, Sun Dec 14 14:13:35 2008 UTC revision 1128 by dpavlin, Tue Jun 30 14:13:15 2009 UTC
# Line 5  extends 'Frey::Action'; Line 5  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 72  sub html { Line 75  sub html {
75          my ( $self ) = @_;          my ( $self ) = @_;
76    
77          my ($html,$body,$data);          my ($html,$body,$data);
78    
79            my $current_status;
80            $current_status->{$_}++ foreach $self->status;
81    
82          eval {          eval {
83                  my $class = $self->class;                  my $class = $self->class;
84                  $self->load_class( $class );                  $self->load_class( $class );
85    
86                  if ( my $form = $self->params_form ) {                  if ( my $form = $self->params_form ) {
87                          $html = $self->page( body => $form );                          $html = $self->html_page( body => $form );
88                          warn "got required params form for $class ", $self->run, " format: ", $self->format;                          warn "missing required params form for $class ", $self->run, " format: ", $self->format;
89                  } else {                  } else {
90    
91                          $self->usage->{ $class }++;                          $self->usage->{ $class }++;
# Line 103  sub html { Line 110  sub html {
110                          $o->depends if $o->can('depends');                          $o->depends if $o->can('depends');
111    
112                          if ( $self->run =~ m{as_markup} ) {                          if ( $self->run =~ m{as_markup} ) {
113                                  $html = $o->page( run => $self->run );                                  $html = $o->html_page( run => $self->run );
114                          } elsif ( $self->run =~ m{as_sponge} ) {                          } elsif ( $self->run =~ m{(.*as_sponge)} ) {
115                                  $data = $o->as_sponge;                                  $data = $o->$1;
116                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
117                                  if ( $self->format eq 'html' ) {                                  if ( $self->format eq 'html' ) {
118                                          my $rows = $#{ $data->{rows} } + 1;                                          my $rows = $#{ $data->{rows} } + 1;
# Line 115  sub html { Line 122  sub html {
122                                          $body .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';                                          $body .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
123                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };                                          $body .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
124                                          $body .= '</table>';                                          $body .= '</table>';
125    
126                                            $self->add_css(qq|
127                                                    tr:nth-child(even) {
128                                                            background-color: #eee;
129                                                    }
130                                            |);
131    
132                                            delete( $data->{rows} ); # too much dumplication
133                                            $body .= Frey::View::Dumper->new( data => $data )->as_markup if $data;
134                                  }                                  }
135                          } elsif ( $self->run =~ m{as_data} ) {                          } elsif ( $self->run =~ m{(as_data|sql)} ) {
136                                  my $run = $self->run;                                  my $run = $self->run;
137                                  $data = $o->$run;                                  $data = $o->$run;
138                                  confess "no data for $class->$run" unless defined $data;                                  confess "no data for $class->$run" unless defined $data;
# Line 131  sub html { Line 147  sub html {
147                          }                          }
148                          if ( ! $html ) {                          if ( ! $html ) {
149                                  $body  = Frey::View::Dumper->new( data => $body )->as_markup if ref $body;                                  $body  = Frey::View::Dumper->new( data => $body )->as_markup if ref $body;
150                                  $body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data;                                  $body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data && ! defined $body;
151                          }                          }
152    
153                          $o->title( $class );                          $o->title( $class );
154    
155                          $html = $o->page( body => $body ) if $body && !$html;                          $html = $o->html_page( body => $body ) if $body && !$html;
156                          $self->content_type( $o->content_type );                          $self->content_type( $o->content_type );
157    
158                          confess "no html output for $class ", $o->dump unless defined $html;                          confess "no html output for $class ", $o->dump unless defined $html;
159    
160                            if ( $o->can('status') ) {
161                                    foreach ( $o->status ) {
162                                            next if $current_status->{$_}++;
163                                            $self->add_status( $_ );
164    #                                       warn "# run add_status: ", $self->dump( $_ ); # FIXME
165                                    }
166                            }
167    
168                  };                  };
169    
170          };          };
# Line 148  sub html { Line 173  sub html {
173    
174          if ( $@ ) {          if ( $@ ) {
175                  my $error = $@;                  my $error = $@;
176                    warn $error;
177    
178                    exit if $error =~ m{Attempt to reload \S+ aborted}; # FIXME Mojo can't reload DBIx::Class
179    
180                  my $o = Frey->new;                  my $o = Frey->new;
181                  $o->{request_url} = $self->request_url; # sigh, this is dynamic languge, right?                  $o->{request_url} = $self->request_url; # sigh, this is dynamic languge, right?
182                  Frey::Web->meta->apply( $o );                  Frey::Web->meta->apply( $o );
183                  $html = $o->page( body => $self->error( $error, undef ) );                  $html = $o->html_page( body => $self->error( $error, undef ) );
184          }          }
185    
186          warn $self->class, " produced ", length($html), " bytes of ", $self->content_type;          warn $self->class, " produced ", length($html), " bytes of ", $self->content_type;

Legend:
Removed from v.835  
changed lines
  Added in v.1128

  ViewVC Help
Powered by ViewVC 1.1.26