/[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

Contents of /trunk/lib/Frey/Run.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 206 - (show annotations)
Thu Oct 30 22:35:11 2008 UTC (15 years, 6 months ago) by dpavlin
File size: 1471 byte(s)
restructure bookmarklets and put them in status bar with CSS popup
1 package Frey::Run;
2 use Moose;
3 extends 'Frey';
4 with 'Frey::Web';
5
6 =head1 NAME
7
8 Frey::Run - display required form field for Class and run it
9
10 =head1 DESCRIPTION
11
12 This object will try to run other Moose objects from your application. It
13 will try to invoke C<html> or C<markup> method on the.
14
15 =cut
16
17 has 'class' => (
18 is => 'rw',
19 isa => 'Str',
20 required => 1,
21 );
22
23 use Data::Dump qw/dump/;
24
25 sub html {
26 my ( $self, $req ) = @_;
27
28 my %params = $req->params;
29 my $class = $self->class;
30
31 my @required =
32 grep {
33 defined $_ && !defined( $params{$_} )
34 }
35 map {
36 my $attr = $class->meta->get_attribute($_);
37 $attr->is_required && $_
38 } $class->meta->get_attribute_list;
39
40 warn "## required = ",dump( @required );
41 warn "## params = ",dump( %params );
42
43 my $html;
44
45 if ( @required ) {
46 $html = qq|<h1>Required params for $class</h1><form method="post">|;
47 $html .= qq|<label for="$_">$_</label><input type="text" name="$_">| foreach @required;
48 $html .= qq|<input type="submit" value="Run $class"></form>|;
49 } else {
50 my $o = $class->new( %params );
51 $o->depends if $o->can('depends');
52 if ( $o->can('html') ) {
53 warn "## turning over to $o->html";
54 $o->html( $req );
55 } elsif ( $o->can('markup') ) {
56 warn "## using $o->markup";
57 $html = $o->markup;
58 warn ">>> markup $class ",length( $html ), " bytes\n";
59 } else {
60 $html = "IGNORE: $class ", $o->dump;
61 warn $html;
62 }
63 }
64
65 $req->print( $self->page( title => $class, body => $html ) );
66 }
67
68 1;

  ViewVC Help
Powered by ViewVC 1.1.26