/[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 317 by dpavlin, Wed Nov 5 22:05:02 2008 UTC revision 350 by dpavlin, Sun Nov 16 00:37:34 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';
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 16  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 30  has 'params' => ( Line 38  has 'params' => (
38          default => sub { {} },          default => sub { {} },
39  );  );
40    
41  use Data::Dump qw/dump/;  has 'run' => (
42            is => 'rw',
43            isa => 'Runnable',
44    );
45    
46  sub html {  sub html {
47          my ( $self ) = @_;          my ( $self ) = @_;
# Line 52  sub html { Line 63  sub html {
63    
64          my $html;          my $html;
65          my $values = {};          my $values = {};
66          $values = $self->config($class) if $self->can('config');          $values = $self->config($class);
67            warn "# $class config = ",dump( $values );
68    
69          if ( @required ) {          if ( @required ) {
70                  $html = qq|<h1>Required params for $class</h1><form method="post">|;                  $html = qq|<h1>$class params</h1><form method="post">|;
71                  foreach my $attr ( @required ) {  
72                          my $name = $attr->name;                  my $a;
73                    my @attrs = map {  $a->{$_}++; $_ } $self->attribute_order;
74                    push @attrs, $_ foreach grep { ! $a->{$_} } map { $_->name } @required;
75                    warn "# attrs = ",dump( @attrs );
76    
77                    foreach my $name ( @attrs ) {
78                            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 73  sub html { Line 107  sub html {
107                  if ( $o->can('markup') ) {                  if ( $o->can('markup') ) {
108                          warn "## using ",ref($o), "->markup";                          warn "## using ",ref($o), "->markup";
109                          $html = eval { $o->markup };                          $html = eval { $o->markup };
110                          if ( $@ ) {                          $html .= $self->error( $@ ) if $@;
                                 warn $@;  
                                 $html .= qq{<code>$@</code>};  
                         }  
111                          warn ">>> markup $class ",length( $html ), " bytes\n";                          warn ">>> markup $class ",length( $html ), " bytes\n";
112                    } elsif ( $o->can('sponge') ) {
113                            my $data = $o->sponge;
114                            $html .= '<table>';
115                            $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
116                            $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
117                            $html .= '</table>';
118                  } elsif ( $o->can('data') ) {                  } elsif ( $o->can('data') ) {
119                          $html = '<code>' . $self->html_escape( dump( $o->data ) ) . '</code>';                          my $data = $o->data;
120                            $html .= Frey::Dumper->new( data => $data )->markup;
121                            $html .= '<hr/><code>' . $self->html_dump( $data ) . '</code>';
122                  } else {                  } else {
123                          $html = "IGNORE: $class ", $o->dump;                          $html = "IGNORE: $class ", $o->dump;
124                          warn $html;                          warn $html;

Legend:
Removed from v.317  
changed lines
  Added in v.350

  ViewVC Help
Powered by ViewVC 1.1.26