--- trunk/lib/Frey/Run.pm 2008/11/06 18:03:06 324 +++ trunk/lib/Frey/Run.pm 2008/11/16 19:57:00 365 @@ -1,10 +1,14 @@ package Frey::Run; use Moose; -extends 'Frey::ClassLoader'; +#extends 'Frey::ClassLoader'; +extends 'Frey::PPI'; with 'Frey::Web'; with 'Frey::Config'; with 'Frey::Escape'; +use Data::Dump qw/dump/; +use Frey::Dumper; + =head1 NAME Frey::Run - display required form field for Class and run it @@ -16,7 +20,11 @@ =cut -sub runnable { qw/data markup/ } +use Moose::Util::TypeConstraints; + +enum 'Runnable' => qw/data markup sponge/; + +sub runnable { qw/data markup sponge/ } has 'class' => ( is => 'rw', @@ -30,7 +38,11 @@ default => sub { {} }, ); -use Data::Dump qw/dump/; +has 'run' => ( + is => 'rw', + isa => 'Runnable', + default => 'markup', +); sub html { my ( $self ) = @_; @@ -56,37 +68,76 @@ warn "# $class config = ",dump( $values ); if ( @required ) { - $html = qq|
$@
};
+ eval {
+ my $o;
+ $o = $class->new( %{ $self->params } );
+ $o->depends if $o->can('depends');
+
+ if ( $self->run eq 'markup' ) {
+ warn "## using ",ref($o), "->markup";
+ $html = $o->markup;
+ warn ">>> markup $class ",length( $html ), " bytes\n";
+ } elsif ( $self->run eq 'sponge' ) {
+ my $data = $o->sponge;
+ confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
+ my $rows = $#{ $data->{rows} } + 1;
+ $rows ||= 'no';
+ $html .= "$rows rows from $class->new" . dump( $self->params ) . "->sponge
";
+ $html .= '' . join(' | ', @{$data->{NAME}} ) . ' |
---|---|
' . join(' | ', @$_ ) . ' |
' . $self->html_dump( $data ) . '
';
+ } else {
+ $html = $self->error( "IGNORE: $class ", $o->dump );
}
- warn ">>> markup $class ",length( $html ), " bytes\n";
- } elsif ( $o->can('data') ) {
- $html = '' . $self->html_escape( dump( $o->data ) ) . '
';
- } else {
- $html = "IGNORE: $class ", $o->dump;
- warn $html;
- }
+ };
+
+ $html .= $self->error( $@ ) if $@;
}
+ return $self->page( %$html ) if ref($html) eq 'HASH';
return $self->page( title => $class, body => $html );
}