/[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 225 by dpavlin, Sat Nov 1 00:59:02 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 39  sub html { Line 48  sub html {
48    
49          if ( @required ) {          if ( @required ) {
50                  $html = qq|<h1>Required params for $class</h1><form method="post">|;                  $html = qq|<h1>Required params for $class</h1><form method="post">|;
51                  $html .= qq|<label for="$_">$_</label><input type="text" name="$_">| foreach @required;                  foreach my $name ( @required ) {
52                            my $type = $name =~ m/^pass/ ? 'password' : 'text';
53                            my $value = $self->config($class)->{$name};
54                            $html .= qq|<label for="$name">$name</label><input type="$type" name="$name" value="$value">|;
55                    }
56                  $html .= qq|<input type="submit" value="Run $class"></form>|;                  $html .= qq|<input type="submit" value="Run $class"></form>|;
57          } else {          } else {
58                  my $o = $class->new( %params );                  my $o = $class->new( %params );
59                  $o->depends if $o->can('depends');                  $o->depends if $o->can('depends');
60                  $html = $o->markup;                  if ( $o->can('request') ) {
61                            warn "## turning over to $o->request";
62                            $o->request( $req );
63                    } elsif ( $o->can('markup') ) {
64                            warn "## using $o->markup";
65                            $html = $o->markup;
66                            warn ">>> markup $class ",length( $html ), " bytes\n";
67                    } elsif ( $o->can('data') ) {
68                            $html = '<code>' . $self->html_escape( dump( $o->data ) ) . '</code>';
69                    } else {
70                            $html = "IGNORE: $class ", $o->dump;
71                            warn $html;
72                    }
73          }          }
74    
         warn ">>> markup $class ",length( $html ), " bytes\n";  
75          $req->print( $self->page( title => $class, body => $html ) );          $req->print( $self->page( title => $class, body => $html ) );
76  }  }
77    

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

  ViewVC Help
Powered by ViewVC 1.1.26