/[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 327 by dpavlin, Thu Nov 6 20:56:44 2008 UTC revision 348 by dpavlin, Sat Nov 15 23:52:22 2008 UTC
# Line 1  Line 1 
1  package Frey::Run;  package Frey::Run;
2  use Moose;  use Moose;
3  extends 'Frey::ClassLoader';  #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';
# Line 19  will try to invoke C<data>, and C<markup Line 20  will try to invoke C<data>, and C<markup
20    
21  =cut  =cut
22    
23  sub runnable { qw/data markup/ }  sub runnable { qw/data markup sponge/ }
24    
25  has 'class' => (  has 'class' => (
26          is => 'rw',          is => 'rw',
# Line 57  sub html { Line 58  sub html {
58          warn "# $class config = ",dump( $values );          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} :                          my $value_html = '';
73                                  $attr->has_default ? $attr->default( $name ) :                          if ( ref($values) eq 'HASH' ) {
74                                  '';                                  $value = $values->{$name};
75                            } elsif ( ref($values) eq 'ARRAY' ) {
76                                    $value_html = qq|<select name="$name">| . join("\n",
77                                            map {
78                                                    my $v = $_->{$name};
79                                                    qq|<option value="$v">$v</option>|
80                                            } @$values
81                                    ) . qq|</select>|;
82                            } else {
83                                    $value = $attr->default( $name ) if $attr->has_default;
84                            }
85                            $value_html = qq|<input type="$type" name="$name" value="$value">| unless $value_html;
86    
87  #warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );  #warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );
88                          $html .= qq|<label for="$name">$name</label><input type="$type" name="$name" value="$value">|;                          $html .= qq|<label for="$name">$name</label>| . $value_html;
89                  }                  }
90                  $html .= qq|<input type="submit" value="Run $class"></form>|;                  $html .= qq|<input type="submit" value="Run $class"></form>|;
91          } else {          } else {
# Line 80  sub html { Line 99  sub html {
99                                  $html .= qq{<code>$@</code>};                                  $html .= qq{<code>$@</code>};
100                          }                          }
101                          warn ">>> markup $class ",length( $html ), " bytes\n";                          warn ">>> markup $class ",length( $html ), " bytes\n";
102                    } elsif ( $o->can('sponge') ) {
103                            my $data = $o->sponge;
104                            $html .= '<table>';
105                            $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
106                            $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
107                            $html .= '</table>';
108                  } elsif ( $o->can('data') ) {                  } elsif ( $o->can('data') ) {
109                          my $data = $o->data;                          my $data = $o->data;
110                          $html .= Frey::Dumper->new( data => $data )->markup;                          $html .= Frey::Dumper->new( data => $data )->markup;

Legend:
Removed from v.327  
changed lines
  Added in v.348

  ViewVC Help
Powered by ViewVC 1.1.26