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