[Bps-public-commit] r17103 - in Prophet/branches/actions: lib/Prophet lib/Prophet/Server lib/Prophet/Server/ViewHelpers

jesse at bestpractical.com jesse at bestpractical.com
Thu Dec 4 14:46:44 EST 2008


Author: jesse
Date: Thu Dec  4 14:46:43 2008
New Revision: 17103

Added:
   Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/
   Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Function.pm
   Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm
Modified:
   Prophet/branches/actions/lib/Prophet/Server.pm
   Prophet/branches/actions/lib/Prophet/Server/Controller.pm
   Prophet/branches/actions/lib/Prophet/Server/ViewHelpers.pm
   Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm

Log:
snapshot

Modified: Prophet/branches/actions/lib/Prophet/Server.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server.pm	(original)
+++ Prophet/branches/actions/lib/Prophet/Server.pm	Thu Dec  4 14:46:43 2008
@@ -5,6 +5,7 @@
 use Prophet::Server::Controller;
 use Prophet::Server::View;
 use Prophet::Server::Dispatcher;
+use Prophet::Server::Controller;
 use Params::Validate qw/:all/;
 use JSON;
 

Modified: Prophet/branches/actions/lib/Prophet/Server/Controller.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server/Controller.pm	(original)
+++ Prophet/branches/actions/lib/Prophet/Server/Controller.pm	Thu Dec  4 14:46:43 2008
@@ -44,7 +44,7 @@
     my @actions = $self->_find_actions_from_cgi_params($params);
     foreach my $param (@$params) {
         my $action = $self->_parse_cgi_param_name($param);
-        $bundles->{$action};
+        $bundles->{$action} = 'XXX TODO';
     }
     
 

Modified: Prophet/branches/actions/lib/Prophet/Server/ViewHelpers.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server/ViewHelpers.pm	(original)
+++ Prophet/branches/actions/lib/Prophet/Server/ViewHelpers.pm	Thu Dec  4 14:46:43 2008
@@ -8,6 +8,9 @@
 use Template::Declare::Tags;
 use Prophet::Web::Field;
 our @EXPORT = qw(page content widget function);
+use Prophet::Server::ViewHelpers::Widget;
+use Prophet::Server::ViewHelpers::Function;
+
 
 sub page (&;$) {
     unshift @_, undef if $#_ == 0;
@@ -38,57 +41,15 @@
 }
 
 sub function {
-    my %args = validate(
-        @_,
-        {   action => { regex => qr/^(?:create|update|delete)$/ },
-            record => 1,
-            order  => 0,
-            name   => {
-                regex    => qr/^(?:|[\w\d]+)$/,
-                optional => 1
-            },
-        }
-    );
-
-    my %bits = {
-        order => $args{order},
-        name  => $args{'name'},
-        uuid  => $args{'record'}->uuid
-    };
-
-    my $string
-        = "|"
-        . join( "|", map { $args{$_} ? $_ . "-" . $args{$_} : '' } keys %bits )
-        . "|";
-
-    input {
-        attr {
-            type => 'hidden',
-            name => "prophet-action|" . $string,
-
-            value => $args{'action'}
-        };
-    };
-
+    my $f = Prophet::Server::ViewHelpers::Function->new(@_);
+    $f->render;
+    return $f;
 }
 
 sub widget {
-    my %args = validate( @_, { prop => 1, record => 1 } );
-
-    my $f = Prophet::Web::Field->new(
-        name   => Prophet::Server::ViewHelpers->_generate_name(%args),
-        record => $args{record},
-        label  => $args{prop},
-        value  => $args{record}->prop( $args{'prop'} )
-    );
-    outs_raw($f->render);
-}
-
-sub _generate_name {
-    my $class = shift;
-    my %args = validate( @_, { prop => 1, record => 1 } );
-    my $r = $args{'record'};
-    return "prophet-field||uuid-".$r->uuid."|prop-".$args{prop}."|";
+    my $w = Prophet::Server::ViewHelpers::Widget->new(@_);
+    $w->render;
+    return $w;
 }
 
 1;

Added: Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Function.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Function.pm	Thu Dec  4 14:46:43 2008
@@ -0,0 +1,81 @@
+package Prophet::Server::ViewHelpers::Function;
+
+=head1 NAME
+
+=head1 METHODS
+
+=head1 DESCRIPTION
+
+=cut
+
+=head1 METHODS
+
+=cut
+
+use Template::Declare::Tags;
+
+BEGIN {
+ delete ${__PACKAGE__."::"}{meta};
+ delete ${__PACKAGE__."::"}{with};
+ }
+
+use Moose;
+use Moose::Util::TypeConstraints;
+
+
+has record => (
+    isa => 'Prophet::Record',
+    is  => 'ro'
+);
+
+has action => (
+    isa => ( enum [qw(create update delete)] ),
+    is => 'ro'
+);
+
+has order => ( isa => 'Int', is => 'ro' );
+
+has name => (
+    isa => 'Str',
+    is  => 'rw',
+
+    #regex    => qr/^(?:|[\w\d]+)$/,
+);
+
+
+
+
+
+ sub new {
+    my $self = shift->SUPER::new(@_);
+    $self->name ( $self->record->uuid . "-" . $self->action ) unless ($self->name);
+    return $self;
+};
+
+sub render {
+    my $self = shift;
+    my %bits =( 
+        order  => $self->order,
+        action => $self->action,
+        uuid   => $self->record->uuid
+    );
+
+    my $string
+        = "|"
+        . join( "|", map { $bits{$_} ? $_ . "-" . $bits{$_} : '' } keys %bits )
+        . "|";
+
+    input {
+        attr {
+            type  => 'hidden',
+            name  => "prophet-action|" . $self->name,
+            value => $string
+        };
+    };
+}
+
+
+    __PACKAGE__->meta->make_immutable;
+    no Moose;
+1;
+

Added: Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm	Thu Dec  4 14:46:43 2008
@@ -0,0 +1,68 @@
+package Prophet::Server::ViewHelpers::Widget;
+
+use Template::Declare::Tags;
+
+BEGIN { delete ${__PACKAGE__."::"}{meta}; 
+ delete ${__PACKAGE__."::"}{with};
+}
+
+use Moose;
+
+use Moose::Util::TypeConstraints;
+
+
+=head1 NAME
+
+=head1 METHODS
+
+=head1 DESCRIPTION
+
+=cut
+
+
+has function => (
+    isa => 'Prophet::Server::ViewHelpers::Function',
+    is  => 'ro'
+);
+has name => ( isa => 'Str', is => 'rw' );
+has prop => ( isa => 'Str', is => 'ro' );
+
+
+
+
+sub render {
+    my $self = shift;
+
+    my $f = Prophet::Web::Field->new(
+        name       => $self->_generate_name(),
+            record => $self->function->record,
+        label => $self->prop,
+        value => $self->function->record->prop( $self->prop )
+    );
+    outs_raw( $f->render );
+}
+
+
+
+
+sub _generate_name {
+    my $self = shift;
+    return
+          "prophet-field||function-"
+        . $self->function->name
+        . "|prop-"
+        . $self->prop . "|";
+}
+
+=head1 METHODS
+
+=cut
+
+
+
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+

Modified: Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm
==============================================================================
--- Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm	(original)
+++ Prophet/branches/actions/t/WebToy/lib/App/WebToy/Server/View.pm	Thu Dec  4 14:46:43 2008
@@ -24,8 +24,8 @@
     my $r = $c->items->[0];
     h1 { $r->prop('title')};
     form {
-    function( record => $r, action => 'update');
-        widget( record => $r, prop => 'title');
+        my $f = function( record => $r, action => 'update');
+        widget( function => $f, prop => 'title');
 
         input {attr { label => 'save', type => 'submit'}};
     }



More information about the Bps-public-commit mailing list