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/; |
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; |
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 |
|
|
82 |
|
|
83 |
$o->depends if $o->can('depends'); |
$o->depends if $o->can('depends'); |
84 |
|
|
85 |
push @{ $self->status }, { $self->editor( $class ) => $self->params }; |
$o->add_status( { $self->editor( $class ) => $self->params } ); |
86 |
|
|
87 |
if ( $self->run eq 'as_markup' ) { |
if ( $self->run =~ m{as_markup} ) { |
88 |
warn "## using ",ref($o), "->as_markup"; |
$html = $o->page; |
89 |
if ( $o->can('page') ) { |
} elsif ( $self->run =~ m{as_sponge} ) { |
|
$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' ) { |
|
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' ) { |
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 ); |
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 @{ $self->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 |
|
|
117 |
# override our status with one from object |
$self->title( $class ); |
|
eval { |
|
|
$self->status( $o->status ); |
|
|
}; |
|
|
warn "can't override status: $@" if $@; |
|
|
}; |
|
|
|
|
118 |
|
|
119 |
if ( ref($body) eq 'HASH' ) { |
$html = $o->page( body => $body ) if $body && !$html; |
|
$html = $self->page( %$body ); |
|
|
} elsif ( $body && ! $html ) { |
|
|
$html = $self->page( title => $self->class . ' run', body => $body ); |
|
120 |
}; |
}; |
121 |
|
|
122 |
}; |
}; |
123 |
|
|
124 |
$html = $self->page( title => $self->class, body => $self->error( $@ ) ) if $@; |
$self->status_parts; |
125 |
|
|
126 |
|
$html = $self->error( $@ ) if $@; |
127 |
|
|
128 |
|
warn $self->class, " produced ", length($html), " bytes"; |
129 |
|
|
130 |
return $html; |
return $html; |
131 |
} |
} |