--- trunk/lib/Frey/Run.pm 2008/11/15 23:52:22 348
+++ trunk/lib/Frey/Run.pm 2008/11/16 17:50:25 363
@@ -20,6 +20,10 @@
=cut
+use Moose::Util::TypeConstraints;
+
+enum 'Runnable' => qw/data markup sponge/;
+
sub runnable { qw/data markup sponge/ }
has 'class' => (
@@ -34,6 +38,12 @@
default => sub { {} },
);
+has 'run' => (
+ is => 'rw',
+ isa => 'Runnable',
+ default => 'markup',
+);
+
sub html {
my ( $self ) = @_;
@@ -79,8 +89,12 @@
qq||
} @$values
) . qq||;
- } else {
- $value = $attr->default( $name ) if $attr->has_default;
+ } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
+ $value_html = qq||;
+ } elsif ( $attr->has_default ) {
+ $value = $attr->default( $name );
}
$value_html = qq|| unless $value_html;
@@ -89,32 +103,38 @@
}
$html .= qq||;
} else {
- my $o = $class->new( %{ $self->params } );
- $o->depends if $o->can('depends');
- if ( $o->can('markup') ) {
- warn "## using ",ref($o), "->markup";
- $html = eval { $o->markup };
- if ( $@ ) {
- warn $@;
- $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 .= '
';
+ $html .= '' . join(' | ', @{$data->{NAME}} ) . ' |
';
+ $html .= '' . join(' | ', @$_ ) . ' |
' foreach @{ $data->{rows} };
+ $html .= '
';
+ } 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 );
}
- warn ">>> markup $class ",length( $html ), " bytes\n";
- } elsif ( $o->can('sponge') ) {
- my $data = $o->sponge;
- $html .= '';
- $html .= '' . join(' | ', @{$data->{NAME}} ) . ' |
';
- $html .= '' . join(' | ', @$_ ) . ' |
' foreach @{ $data->{rows} };
- $html .= '
';
- } elsif ( $o->can('data') ) {
- my $data = $o->data;
- $html .= Frey::Dumper->new( data => $data )->markup;
- $html .= '
' . $self->html_dump( $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 );
}