/[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 180 by dpavlin, Sun Aug 31 18:02:50 2008 UTC revision 229 by dpavlin, Sat Nov 1 13:17:45 2008 UTC
# Line 2  package Frey::Run; Line 2  package Frey::Run;
2  use Moose;  use Moose;
3  extends 'Frey';  extends 'Frey';
4  with 'Frey::Web';  with 'Frey::Web';
5    with 'Frey::Config';
6    with 'Frey::Escape';
7    
8  =head1 NAME  =head1 NAME
9    
10  Frey::Run - display required form field for Class and run it  Frey::Run - display required form field for Class and run it
11    
12    =head1 DESCRIPTION
13    
14    This object will try to run other Moose objects from your application. It
15    will try to invoke C<data>, C<html> or C<markup> method on the.
16    
17  =cut  =cut
18    
19    sub execute { qw/data markup request/ }
20    
21  has 'class' => (  has 'class' => (
22          is => 'rw',          is => 'rw',
23          isa => 'Str',          isa => 'Str',
# Line 17  has 'class' => ( Line 26  has 'class' => (
26    
27  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
28    
29  sub html {  sub request {
30          my ( $self, $req ) = @_;          my ( $self, $req ) = @_;
31    
32          my %params = $req->params;          my %params = $req->params;
# Line 36  sub html { Line 45  sub html {
45                  warn "## params = ",dump( %params );                  warn "## params = ",dump( %params );
46    
47          my $html;          my $html;
48            my $values = $self->config($class);
49            $values = {} if $@;
50    
51          if ( @required ) {          if ( @required ) {
52                  $html = qq|<h1>Required params for $class</h1><form method="post">|;                  $html = qq|<h1>Required params for $class</h1><form method="post">|;
53                  $html .= qq|<label for="$_">$_</label><input type="text" name="$_">| foreach @required;                  foreach my $name ( @required ) {
54                            my $type = $name =~ m/^pass/ ? 'password' : 'text';
55                            my $value = $values ? $values->{$name} : '';
56                            $html .= qq|<label for="$name">$name</label><input type="$type" name="$name" value="$value">|;
57                    }
58                  $html .= qq|<input type="submit" value="Run $class"></form>|;                  $html .= qq|<input type="submit" value="Run $class"></form>|;
59          } else {          } else {
60                  my $o = $class->new( %params );                  my $o = $class->new( %params );
61                  $o->depends if $o->can('depends');                  $o->depends if $o->can('depends');
62                  $html = $o->markup;                  if ( $o->can('request') ) {
63                            warn "## turning over to $o->request";
64                            $o->request( $req );
65                    } elsif ( $o->can('markup') ) {
66                            warn "## using ",ref($o), "->markup";
67                            $html = $o->markup;
68                            warn ">>> markup $class ",length( $html ), " bytes\n";
69                    } elsif ( $o->can('data') ) {
70                            $html = '<code>' . $self->html_escape( dump( $o->data ) ) . '</code>';
71                    } else {
72                            $html = "IGNORE: $class ", $o->dump;
73                            warn $html;
74                    }
75          }          }
76    
         warn ">>> markup $class ",length( $html ), " bytes\n";  
77          $req->print( $self->page( title => $class, body => $html ) );          $req->print( $self->page( title => $class, body => $html ) );
78  }  }
79    

Legend:
Removed from v.180  
changed lines
  Added in v.229

  ViewVC Help
Powered by ViewVC 1.1.26