/[Frey]/branches/mojo/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 /branches/mojo/lib/Frey/Run.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 243 - (show annotations)
Sun Nov 2 21:24:04 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1899 byte(s)
a swipe of refactoring to run under Mojo and Continuity with same REST API

- all objects are now invoked using URL path as object name and param
  (which doesn't work with Mojo as of this commit)
- Frey::Run is now usable Moose object for both servers
- move handling of Continuity bits into Frey::Server only
1 package Frey::Run;
2 use Moose;
3 extends 'Frey';
4 with 'Frey::Web';
5 with 'Frey::Config';
6 with 'Frey::Escape';
7
8 =head1 NAME
9
10 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
18
19 sub execute { qw/data markup/ }
20
21 has 'class' => (
22 is => 'rw',
23 isa => 'Str',
24 required => 1,
25 );
26
27 has 'params' => (
28 is => 'rw',
29 isa => 'HashRef',
30 default => sub { {} },
31 );
32
33 use Data::Dump qw/dump/;
34
35 sub html {
36 my ( $self ) = @_;
37
38 my $class = $self->class;
39
40 my @required =
41 grep {
42 defined $_ && !defined( $self->params->{$_} )
43 }
44 map {
45 my $attr = $class->meta->get_attribute($_);
46 $attr->is_required && $_
47 } $class->meta->get_attribute_list;
48
49 warn "## required = ",dump( @required );
50
51 my $html;
52 my $values = {};
53 my $values = $self->config($class) if $self->can('config');
54
55 if ( @required ) {
56 $html = qq|<h1>Required params for $class</h1><form method="post">|;
57 foreach my $name ( @required ) {
58 my $type = $name =~ m/^pass/ ? 'password' : 'text';
59 my $value = $values ? $values->{$name} : '';
60 $html .= qq|<label for="$name">$name</label><input type="$type" name="$name" value="$value">|;
61 }
62 $html .= qq|<input type="submit" value="Run $class"></form>|;
63 } else {
64 my $o = $class->new( %{ $self->params } );
65 $o->depends if $o->can('depends');
66 if ( $o->can('markup') ) {
67 warn "## using ",ref($o), "->markup";
68 $html = eval { $o->markup };
69 if ( $@ ) {
70 warn $@;
71 $html .= qq{<code>$@</code>};
72 }
73 warn ">>> markup $class ",length( $html ), " bytes\n";
74 } elsif ( $o->can('data') ) {
75 $html = '<code>' . $self->html_escape( dump( $o->data ) ) . '</code>';
76 } else {
77 $html = "IGNORE: $class ", $o->dump;
78 warn $html;
79 }
80 }
81
82 return $self->page( title => $class, body => $html );
83 }
84
85 1;

  ViewVC Help
Powered by ViewVC 1.1.26