--- trunk/lib/Frey/Run.pm 2008/11/01 13:17:45 229 +++ trunk/lib/Frey/Run.pm 2008/11/17 14:37:48 369 @@ -1,10 +1,13 @@ package Frey::Run; use Moose; -extends 'Frey'; +#extends 'Frey::ClassLoader'; +extends 'Frey::Action'; 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 @@ -12,11 +15,19 @@ =head1 DESCRIPTION This object will try to run other Moose objects from your application. It -will try to invoke C, C or C method on the. +will try to invoke C, and C method on the. + +=head1 SEE ALSO + +L which creates form for params =cut -sub execute { qw/data markup request/ } +use Moose::Util::TypeConstraints; + +enum 'Runnable' => qw/data markup sponge/; + +sub runnable { qw/data markup sponge/ } has 'class' => ( is => 'rw', @@ -24,57 +35,61 @@ required => 1, ); -use Data::Dump qw/dump/; - -sub request { - my ( $self, $req ) = @_; - - my %params = $req->params; - my $class = $self->class; +has 'params' => ( + is => 'rw', + isa => 'HashRef', + default => sub { {} }, +); - my @required = - grep { - defined $_ && !defined( $params{$_} ) - } - map { - my $attr = $class->meta->get_attribute($_); - $attr->is_required && $_ - } $class->meta->get_attribute_list; +has 'run' => ( + is => 'rw', + isa => 'Runnable', + default => 'markup', +); - warn "## required = ",dump( @required ); - warn "## params = ",dump( %params ); +sub html { + my ( $self ) = @_; my $html; - my $values = $self->config($class); - $values = {} if $@; + eval { + my $class = $self->class; + $self->load_class( $class ); - if ( @required ) { - $html = qq|

Required params for $class

|; - foreach my $name ( @required ) { - my $type = $name =~ m/^pass/ ? 'password' : 'text'; - my $value = $values ? $values->{$name} : ''; - $html .= qq||; - } - $html .= qq|
|; - } else { - my $o = $class->new( %params ); - $o->depends if $o->can('depends'); - if ( $o->can('request') ) { - warn "## turning over to $o->request"; - $o->request( $req ); - } elsif ( $o->can('markup') ) { - warn "## using ",ref($o), "->markup"; - $html = $o->markup; - warn ">>> markup $class ",length( $html ), " bytes\n"; - } elsif ( $o->can('data') ) { - $html = '' . $self->html_escape( dump( $o->data ) ) . ''; + if ( $html = $self->params_form ) { + warn "got params form for $class"; } else { - $html = "IGNORE: $class ", $o->dump; - warn $html; - } - } + 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 .= ''; + $html .= ''; + $html .= '' foreach @{ $data->{rows} }; + $html .= '
' . join('', @{$data->{NAME}} ) . '
' . join('', @$_ ) . '
'; + } elsif ( $self->run eq 'data' ) { + my $data = $o->data; + $html .= Frey::Dumper->new( data => $data )->markup; + $html .= '
dump' . $self->html_dump( $data ) . ''; + } else { + $html = $self->error( "IGNORE: $class ", $o->dump ); + } + }; + + }; + $html .= $self->error( $@ ) if $@; - $req->print( $self->page( title => $class, body => $html ) ); + return $self->page( %$html ) if ref($html) eq 'HASH'; + return $self->page( title => $self->class, body => $html ); } 1;