/[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 351 by dpavlin, Sun Nov 16 13:01:56 2008 UTC revision 365 by dpavlin, Sun Nov 16 19:57:00 2008 UTC
# Line 71  sub html { Line 71  sub html {
71                  $html = qq|<h1>$class params</h1><form method="post">|;                  $html = qq|<h1>$class params</h1><form method="post">|;
72    
73                  my $a;                  my $a;
74                  my @attrs = map {  $a->{$_}++; $_ } $self->attribute_order;                  my @attrs = map {  $a->{$_}++; $_ } @{ $self->attribute_order };
75                  push @attrs, $_ foreach grep { ! $a->{$_} } map { $_->name } @required;                  push @attrs, $_ foreach grep { ! $a->{$_} } map { $_->name } @required;
76                  warn "# attrs = ",dump( @attrs );                  warn "# attrs = ",dump( @attrs );
77    
78                  foreach my $name ( @attrs ) {                  foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } @attrs ) {
                         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                          my $value_html = '';                          my $value_html = '';
# Line 89  sub html { Line 88  sub html {
88                                                  qq|<option value="$v">$v</option>|                                                  qq|<option value="$v">$v</option>|
89                                          } @$values                                          } @$values
90                                  ) . qq|</select>|;                                  ) . qq|</select>|;
91                          } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {                          } elsif ( my $attr = $class->meta->get_attribute( $name ) ) {
92                                  $value_html = qq|<select name="$name">| . join("\n",                                  if ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
93                                          map { qq|<option value="$_">$_</option>| } @{ $attr->type_constraint->values }                                          $value_html = qq|<select name="$name">| . join("\n",
94                                  ) . qq|</select>|;                                                  map { qq|<option value="$_">$_</option>| } @{ $attr->type_constraint->values }
95                          } elsif ( $attr->has_default ) {                                          ) . qq|</select>|;
96                                  $value = $attr->default( $name );                                  } elsif ( $attr->has_default ) {
97                                            $value = $attr->default( $name );
98                                    }
99                            } else {
100                                    warn "wired attribute $name";
101                          }                          }
102                          $value_html = qq|<input type="$type" name="$name" value="$value">| unless $value_html;                          $value_html = qq|<input type="$type" name="$name" value="$value">| unless $value_html;
103    
# Line 103  sub html { Line 106  sub html {
106                  }                  }
107                  $html .= qq|<input type="submit" value="Run $class"></form>|;                  $html .= qq|<input type="submit" value="Run $class"></form>|;
108          } else {          } else {
109                  my $o;                  eval {
110                  eval { $o = $class->new( %{ $self->params } ); };                          my $o;
111                  if ( $@ ) {                          $o = $class->new( %{ $self->params } );
112                          return $self->page( title => $class, body => $self->error( $@ ) );                          $o->depends if $o->can('depends');
113                  }  
114                  $o->depends if $o->can('depends');                          if ( $self->run eq 'markup' ) {
115                                    warn "## using ",ref($o), "->markup";
116                  if ( $self->run eq 'markup' ) {                                  $html = $o->markup;
117                          warn "## using ",ref($o), "->markup";                                  warn ">>> markup $class ",length( $html ), " bytes\n";
118                          $html = eval { $o->markup };                          } elsif ( $self->run eq 'sponge' ) {
119                          $html .= $self->error( $@ ) if $@;                                  my $data = $o->sponge;
120                          warn ">>> markup $class ",length( $html ), " bytes\n";                                  confess "invalid data from sponge = ", dump( $data ) unless ref($data) eq 'HASH';
121                  } elsif ( $self->run eq 'sponge' ) {                                  my $rows = $#{ $data->{rows} } + 1;
122                          my $data = eval { $o->sponge };                                  $rows ||= 'no';
123                          if ( $@ ) {                                  $html .= "<strong>$rows</strong> rows from <code>$class->new" . dump( $self->params ) . "->sponge</code>";
                                 $html .= $self->error( $@ );  
                         } else {  
124                                  $html .= '<table>';                                  $html .= '<table>';
125                                  $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';                                  $html .= '<tr><th>' . join('</th><th>', @{$data->{NAME}} ) . '</th></tr>';
126                                  $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };                                  $html .= '<tr><td>' . join('</td><td>', @$_ ) . '</td></tr>' foreach @{ $data->{rows} };
127                                  $html .= '</table>';                                  $html .= '</table>';
128                          }                          } elsif ( $self->run eq 'data' ) {
129                  } elsif ( $self->run eq 'data' ) {                                  my $data = $o->data;
                         my $data = eval { $o->data; };  
                         if ( $@ ) {  
                                 $html .= $self->error( $@ );  
                         } else {  
130                                  $html .= Frey::Dumper->new( data => $data )->markup;                                  $html .= Frey::Dumper->new( data => $data )->markup;
131                                  $html .= '<hr/><code>' . $self->html_dump( $data ) . '</code>';                                  $html .= '<hr/><span class="frey-popdown">dump<span><code>' . $self->html_dump( $data ) . '</code></span></span>';
132                            } else {
133                                    $html = $self->error( "IGNORE: $class ", $o->dump );
134                          }                          }
135                  } else {                  };
136                          $html = $self->error( "IGNORE: $class ", $o->dump );  
137                  }                  $html .= $self->error( $@ ) if $@;
138          }          }
139    
140            return $self->page( %$html ) if ref($html) eq 'HASH';
141          return $self->page( title => $class, body => $html );          return $self->page( title => $class, body => $html );
142  }  }
143    

Legend:
Removed from v.351  
changed lines
  Added in v.365

  ViewVC Help
Powered by ViewVC 1.1.26