/[Frey]/trunk/lib/Frey/Run.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Run.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 285 by dpavlin, Wed Nov 5 08:20:57 2008 UTC revision 339 by dpavlin, Sat Nov 8 23:34:43 2008 UTC
# Line 1  Line 1 
1  package Frey::Run;  package Frey::Run;
2  use Moose;  use Moose;
3  extends 'Frey';  #extends 'Frey::ClassLoader';
4    extends 'Frey::PPI';
5  with 'Frey::Web';  with 'Frey::Web';
6  with 'Frey::Config';  with 'Frey::Config';
7  with 'Frey::Escape';  with 'Frey::Escape';
8    
9    use Data::Dump qw/dump/;
10    use Frey::Dumper;
11    
12  =head1 NAME  =head1 NAME
13    
14  Frey::Run - display required form field for Class and run it  Frey::Run - display required form field for Class and run it
# Line 12  Frey::Run - display required form field Line 16  Frey::Run - display required form field
16  =head1 DESCRIPTION  =head1 DESCRIPTION
17    
18  This object will try to run other Moose objects from your application. It  This object will try to run other Moose objects from your application. It
19  will try to invoke C<data>, C<html> or C<markup> method on the.  will try to invoke C<data>, and C<markup> method on the.
20    
21  =cut  =cut
22    
23  sub execute { qw/data markup/ }  sub runnable { qw/data markup sponge/ }
24    
25  has 'class' => (  has 'class' => (
26          is => 'rw',          is => 'rw',
# Line 30  has 'params' => ( Line 34  has 'params' => (
34          default => sub { {} },          default => sub { {} },
35  );  );
36    
 use Data::Dump qw/dump/;  
   
37  sub html {  sub html {
38          my ( $self ) = @_;          my ( $self ) = @_;
39    
40          my $class = $self->class;          my $class = $self->class;
41    
42            $self->load_class( $class );
43    
44          my @required =          my @required =
45                  grep {                  grep {
46                          defined $_ && $_->can('name') && !defined( $self->params->{ $_->name } )                          defined $_ && $_->can('name') && !defined( $self->params->{ $_->name } )
# Line 50  sub html { Line 54  sub html {
54    
55          my $html;          my $html;
56          my $values = {};          my $values = {};
57          my $values = $self->config($class) if $self->can('config');          $values = $self->config($class);
58            warn "# $class config = ",dump( $values );
59    
60          if ( @required ) {          if ( @required ) {
61                  $html = qq|<h1>Required params for $class</h1><form method="post">|;                  $html = qq|<h1>$class params</h1><form method="post">|;
62                  foreach my $attr ( @required ) {  
63                          my $name = $attr->name;                  my $a;
64                    my @attrs = map {  $a->{$_}++; $_ } $self->attribute_order;
65                    push @attrs, $_ foreach grep { ! $a->{$_} } map { $_->name } @required;
66                    warn "# attrs = ",dump( @attrs );
67    
68                    foreach my $name ( @attrs ) {
69                            my $attr = $class->meta->get_attribute( $name );
70                          my $type = $name =~ m/^pass/ ? 'password' : 'text';                          my $type = $name =~ m/^pass/ ? 'password' : 'text';
71                          my $value =                          my $value =
72                                  $values ? $values->{$name} :                                  $values ? $values->{$name} :
# Line 76  sub html { Line 87  sub html {
87                                  $html .= qq{<code>$@</code>};                                  $html .= qq{<code>$@</code>};
88                          }                          }
89                          warn ">>> markup $class ",length( $html ), " bytes\n";                          warn ">>> markup $class ",length( $html ), " bytes\n";
90                    } elsif ( $o->can('sponge') ) {
91                            my $data = $o->sponge;
92                            $html .= '<table>';
93                            $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
94                            $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
95                            $html .= '</table>';
96                  } elsif ( $o->can('data') ) {                  } elsif ( $o->can('data') ) {
97                          $html = '<code>' . $self->html_escape( dump( $o->data ) ) . '</code>';                          my $data = $o->data;
98                            $html .= Frey::Dumper->new( data => $data )->markup;
99                            $html .= '<hr/><code>' . $self->html_dump( $data ) . '</code>';
100                  } else {                  } else {
101                          $html = "IGNORE: $class ", $o->dump;                          $html = "IGNORE: $class ", $o->dump;
102                          warn $html;                          warn $html;

Legend:
Removed from v.285  
changed lines
  Added in v.339

  ViewVC Help
Powered by ViewVC 1.1.26