/[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 336 by dpavlin, Sat Nov 8 23:03:35 2008 UTC revision 349 by dpavlin, Sun Nov 16 00:25:39 2008 UTC
# Line 20  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/ }  use Moose::Util::TypeConstraints;
24    
25    enum 'Runnable' => qw/data markup sponge/;
26    
27    sub runnable { qw/data markup sponge/ }
28    
29  has 'class' => (  has 'class' => (
30          is => 'rw',          is => 'rw',
# Line 34  has 'params' => ( Line 38  has 'params' => (
38          default => sub { {} },          default => sub { {} },
39  );  );
40    
41    has 'run' => (
42            is => 'rw',
43            isa => 'Runnable',
44    );
45    
46  sub html {  sub html {
47          my ( $self ) = @_;          my ( $self ) = @_;
48    
# Line 68  sub html { Line 77  sub html {
77                  foreach my $name ( @attrs ) {                  foreach my $name ( @attrs ) {
78                          my $attr = $class->meta->get_attribute( $name );                          my $attr = $class->meta->get_attribute( $name );
79                          my $type = $name =~ m/^pass/ ? 'password' : 'text';                          my $type = $name =~ m/^pass/ ? 'password' : 'text';
80                          my $value =                          my $value = '';
81                                  $values ? $values->{$name} :                          my $value_html = '';
82                                  $attr->has_default ? $attr->default( $name ) :                          if ( ref($values) eq 'HASH' ) {
83                                  '';                                  $value = $values->{$name};
84                            } elsif ( ref($values) eq 'ARRAY' ) {
85                                    $value_html = qq|<select name="$name">| . join("\n",
86                                            map {
87                                                    my $v = $_->{$name};
88                                                    qq|<option value="$v">$v</option>|
89                                            } @$values
90                                    ) . qq|</select>|;
91                            } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
92                                    $value_html = qq|<select name="$name">| . join("\n",
93                                            map { qq|<option value="$_">$_</option>| } @{ $attr->type_constraint->values }
94                                    ) . qq|</select>|;
95                            } elsif ( $attr->has_default ) {
96                                    $value = $attr->default( $name );
97                            }
98                            $value_html = qq|<input type="$type" name="$name" value="$value">| unless $value_html;
99    
100  #warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );  #warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );
101                          $html .= qq|<label for="$name">$name</label><input type="$type" name="$name" value="$value">|;                          $html .= qq|<label for="$name">$name</label>| . $value_html;
102                  }                  }
103                  $html .= qq|<input type="submit" value="Run $class"></form>|;                  $html .= qq|<input type="submit" value="Run $class"></form>|;
104          } else {          } else {
# Line 87  sub html { Line 112  sub html {
112                                  $html .= qq{<code>$@</code>};                                  $html .= qq{<code>$@</code>};
113                          }                          }
114                          warn ">>> markup $class ",length( $html ), " bytes\n";                          warn ">>> markup $class ",length( $html ), " bytes\n";
115                    } elsif ( $o->can('sponge') ) {
116                            my $data = $o->sponge;
117                            $html .= '<table>';
118                            $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
119                            $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
120                            $html .= '</table>';
121                  } elsif ( $o->can('data') ) {                  } elsif ( $o->can('data') ) {
122                          my $data = $o->data;                          my $data = $o->data;
123                          $html .= Frey::Dumper->new( data => $data )->markup;                          $html .= Frey::Dumper->new( data => $data )->markup;

Legend:
Removed from v.336  
changed lines
  Added in v.349

  ViewVC Help
Powered by ViewVC 1.1.26