--- trunk/lib/Frey/Run.pm 2008/11/27 22:11:13 570
+++ trunk/lib/Frey/Run.pm 2008/11/28 13:16:47 581
@@ -2,7 +2,6 @@
use Moose;
#extends 'Frey::ClassLoader';
extends 'Frey::Action';
-with 'Frey::Web';
with 'Frey::Session';
use Data::Dump qw/dump/;
@@ -29,7 +28,7 @@
subtype 'Runnable'
=> as 'Str',
- => where sub { m{^as_} };
+ => where sub { m{^as_} || m{_as_} };
sub formats_available { qw/html js json yaml yml/ }
enum 'Formats' => formats_available;
@@ -66,7 +65,8 @@
my $class = $self->class;
$self->load_class( $class );
- if ( $body = $self->params_form ) {
+ if ( $self->params_form ) {
+ $html = $self->page;
warn "got required params form for $class ", $self->run, " format: ", $self->format;
} else {
@@ -82,15 +82,11 @@
$o->depends if $o->can('depends');
- my @status;
+ $o->add_status( { $self->editor( $class ) => $self->params } );
- push @status, { $self->editor( $class ) => $self->params };
-
- if ( $self->run eq 'as_markup' && ! $o->can('page') ) {
- 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' ) {
+ if ( $self->run =~ m{as_markup} ) {
+ $html = $o->page;
+ } elsif ( $self->run =~ m{as_sponge} ) {
$data = $o->as_sponge;
confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
if ( $self->format eq 'html' ) {
@@ -102,7 +98,7 @@
$body .= '
' . join(' | ', @$_ ) . ' |
' foreach @{ $data->{rows} };
$body .= '';
}
- } elsif ( $self->run eq 'as_data' ) {
+ } elsif ( $self->run =~ m{as_data} ) {
$data = $o->as_data;
} else {
$body = $self->error( "IGNORE: $class ", $o->dump );
@@ -111,42 +107,25 @@
if ( defined $data ) {
$html .= to_json( $data ) if $self->format =~ m{js(on)?};
$html .= Dump( $data ) if $self->format =~ m{ya?ml};
- push @status, { 'data' => $data };
+ $self->add_status( { 'data' => $data } );
}
if ( ! $html ) {
$body = Frey::View::Dumper->new( data => $body )->as_markup if ref $body;
$body .= Frey::View::Dumper->new( data => $data )->as_markup if defined $data;
}
- 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;
- }
-
$self->title( $class );
- };
- if ( ref($body) eq 'HASH' ) {
- $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";
+ $html = $o->page( body => $body ) if $body && !$html;
};
+
};
$self->status_parts;
- $html = $self->page( title => $self->class, body => $self->error( $@ ) ) if $@;
+ $html = $self->error( $@ ) if $@;
+
+ warn $self->class, " produced ", length($html), " bytes";
return $html;
}