[Bps-public-commit] r17219 - in Prophet/branches/actions/lib/Prophet: Server Server/ViewHelpers Web
jesse at bestpractical.com
jesse at bestpractical.com
Sun Dec 14 01:04:08 EST 2008
Author: jesse
Date: Sun Dec 14 01:04:08 2008
New Revision: 17219
Added:
Prophet/branches/actions/lib/Prophet/Web/FunctionResult.pm
Prophet/branches/actions/lib/Prophet/Web/Result.pm
Modified:
Prophet/branches/actions/lib/Prophet/Server.pm
Prophet/branches/actions/lib/Prophet/Server/Controller.pm
Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm
Prophet/branches/actions/lib/Prophet/Web/Field.pm
Log:
* first stab at making function results accessible from dispatcher
Modified: Prophet/branches/actions/lib/Prophet/Server.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Server.pm Sun Dec 14 01:04:08 2008
@@ -7,6 +7,8 @@
use Prophet::Server::Dispatcher;
use Prophet::Server::Controller;
use Prophet::Web::Menu;
+use Prophet::Web::Result;
+
use Params::Validate qw/:all/;
use File::ShareDir qw//;
use File::Spec ();
@@ -14,8 +16,15 @@
use JSON;
-my $PROPHET_STATIC_ROOT = Cwd::fast_abs_path( File::Spec->catdir( Prophet::Util->updir($INC{'Prophet.pm'}),"..","share","web","static"));
- $PROPHET_STATIC_ROOT= File::Spec->catfile( File::ShareDir::dist_dir('Prophet'),'web/static') if (!-d $PROPHET_STATIC_ROOT);
+my $PROPHET_STATIC_ROOT = Cwd::fast_abs_path(
+ File::Spec->catdir(
+ Prophet::Util->updir( $INC{'Prophet.pm'} ),
+ "..", "share", "web", "static"
+ )
+);
+$PROPHET_STATIC_ROOT
+ = File::Spec->catfile( File::ShareDir::dist_dir('Prophet'), 'web/static' )
+ if ( !-d $PROPHET_STATIC_ROOT );
has app_handle => (
isa => 'Prophet::App',
@@ -23,11 +32,11 @@
handles => [qw/handle/]
);
-has cgi => ( isa => 'Maybe[CGI]', is => 'rw' );
-has nav => ( isa => 'Maybe[Prophet::Web::Menu]', is => 'rw' );
-has read_only => ( is => 'rw', isa => 'Bool' );
-has view_class => ( isa => 'Str', is=> 'rw');
-
+has cgi => ( isa => 'Maybe[CGI]', is => 'rw' );
+has nav => ( isa => 'Maybe[Prophet::Web::Menu]', is => 'rw' );
+has read_only => ( is => 'rw', isa => 'Bool' );
+has view_class => ( isa => 'Str', is => 'rw' );
+has result => ( isa => 'Prophet::Web::Result', is => 'rw' );
sub run {
my $self = shift;
@@ -87,23 +96,30 @@
override handle_request => sub {
my ( $self, $cgi ) = validate_pos( @_, { isa => 'Prophet::Server' }, { isa => 'CGI' } );
$self->cgi($cgi);
- $self->nav(Prophet::Web::Menu->new( cgi => $self->cgi));
- if ($ENV{'PROPHET_DEVEL'}) { require 'Module::Refresh'; Module::Refresh->refresh(); }
-
-
+ $self->nav( Prophet::Web::Menu->new( cgi => $self->cgi ) );
+ $self->result( Prophet::Web::Result->new() );
+ if ( $ENV{'PROPHET_DEVEL'} ) {
+ require 'Module::Refresh';
+ Module::Refresh->refresh();
+ }
- my $controller = Prophet::Server::Controller->new(cgi => $self->cgi, app_handle => $self->app_handle);
+ my $controller = Prophet::Server::Controller->new(
+ cgi => $self->cgi,
+ app_handle => $self->app_handle,
+ result => $self->result
+ );
$controller->handle_actions();
- my $dispatcher_class = ref($self->app_handle) . "::Server::Dispatcher";
- if (!$self->app_handle->try_to_require($dispatcher_class)) {
- $dispatcher_class = "Prophet::Server::Dispatcher";
- }
-
-
- my $d =$dispatcher_class->new( server => $self );
+ warn YAML::Dump($self->result); use YAML;
+
+ my $dispatcher_class = ref( $self->app_handle ) . "::Server::Dispatcher";
+ if ( !$self->app_handle->try_to_require($dispatcher_class) ) {
+ $dispatcher_class = "Prophet::Server::Dispatcher";
+ }
+
+ my $d = $dispatcher_class->new( server => $self );
- $d->run( $cgi->request_method . $cgi->path_info, $d )
+ $d->run( $cgi->request_method . $cgi->path_info, $d )
|| $self->_send_404;
};
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 Sun Dec 14 01:04:08 2008
@@ -1,12 +1,15 @@
package Prophet::Server::Controller;
use Moose;
use Prophet::Util;
+use Prophet::Web::Result;
has cgi => (is => 'rw', isa => 'CGI');
-has failed => ( is => 'rw', isa => 'Bool');
has failure_message => ( is => 'rw', isa => 'Str');
has actions => (is => 'rw', isa => 'HashRef');
has app_handle => (is => 'rw', isa => 'Prophet::App');
+has result => ( is => 'ro', isa => 'Prophet::Web::Result');
+
+
=head1 NAME
@@ -32,6 +35,7 @@
my $action_data = $self->cgi->param($param);
my $attr = $self->string_to_hash($action_data);
+ $attr->{name} = $name;
$actions->{$name} = $attr;
$actions->{$name}->{params} = $self->params_for_action_from_cgi($name);
@@ -72,8 +76,8 @@
};
if (my $err = $@) {
- $self->failed(1);
- $self->failure_message($err);
+ $self->result->success(0);
+ $self->result->message($err);
}
}
@@ -135,8 +139,14 @@
}
);
- warn $val, $msg;
+ my $res = Prophet::Web::FunctionResult->new( function_name => $action->{name},
+ class => $action->{class},
+ success => $object->uuid? 1 :0,
+ record_uuid => $object->uuid,
+ msg => ($msg || 'Record created'));
+
+ $self->result->set($action->{name} => $res);
}
sub _exec_action_update {
@@ -144,7 +154,6 @@
my $action = shift;
my $object = Prophet::Util->instantiate_record( uuid => $action->{uuid}, class=>$action->{class}, app_handle=> $self->app_handle);
- warn "My reocrd is $object";
my ( $val, $msg ) = $object->set_props(
props => {
map {
@@ -153,7 +162,13 @@
}
);
- warn "Updated the record" . $val, $msg;
+ my $res = Prophet::Web::FunctionResult->new( function_name => $action->{name},
+ class => $action->{class},
+ success => $val? 1 :0,
+ record_uuid => $object->uuid,
+ msg => ($msg || 'Record updated'));
+
+ $self->result->set($action->{name} => $res);
}
Modified: Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Server/ViewHelpers/Widget.pm Sun Dec 14 01:04:08 2008
@@ -79,7 +79,7 @@
extraParams: {
"function": "'.$self->field->name.'",
"class": "'.ref($record).'",
- "uuid": "'.$record->uuid.'",
+ "uuid": "'.($record->uuid||'').'",
"type": "'.$record->type.'",
"prop": "'.$self->prop.'",
}
Modified: Prophet/branches/actions/lib/Prophet/Web/Field.pm
==============================================================================
--- Prophet/branches/actions/lib/Prophet/Web/Field.pm (original)
+++ Prophet/branches/actions/lib/Prophet/Web/Field.pm Sun Dec 14 01:04:08 2008
@@ -6,9 +6,9 @@
has prop => ( isa => 'Str', is => 'rw' );
has value => ( isa => 'Str', is => 'rw' );
has label => ( isa => 'Str', is => 'rw', default => sub {''});
-has id => ( isa => 'Str', is => 'rw' );
-has class => ( isa => 'Str', is => 'rw' );
-has value => ( isa => 'Str', is => 'rw' );
+has id => ( isa => 'Maybe[Str]', is => 'rw' );
+has class => ( isa => 'Maybe[Str]', is => 'rw' );
+has value => ( isa => 'Maybe[Str]', is => 'rw' );
has type => ( isa => 'Str', is => 'rw', default => 'text');
sub _render_attr {
Added: Prophet/branches/actions/lib/Prophet/Web/FunctionResult.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/actions/lib/Prophet/Web/FunctionResult.pm Sun Dec 14 01:04:08 2008
@@ -0,0 +1,27 @@
+package Prophet::Web::FunctionResult;
+use Moose;
+
+=head1 NAME
+
+=head1 METHODS
+
+=head1 DESCRIPTION
+
+=cut
+
+=head1 METHODS
+
+=cut
+
+has class => ( isa => 'Str', is => 'rw');
+has function_name => ( isa => 'Str', is => 'rw');
+has record_uuid => (isa => 'Str', is => 'rw');
+has success => (isa => 'Bool', is => 'rw');
+has message => (isa => 'Str', is => 'rw');
+
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+
Added: Prophet/branches/actions/lib/Prophet/Web/Result.pm
==============================================================================
--- (empty file)
+++ Prophet/branches/actions/lib/Prophet/Web/Result.pm Sun Dec 14 01:04:08 2008
@@ -0,0 +1,42 @@
+package Prophet::Web::Result;
+use Moose;
+use MooseX::AttributeHelpers;
+
+use Prophet::Web::FunctionResult;
+
+=head1 NAME
+
+Prophet::Web::Result
+
+=head1 METHODS
+
+=head1 DESCRIPTION
+
+=cut
+
+=head1 METHODS
+
+=cut
+
+has success => ( isa => 'Bool', is => 'rw');
+has message => ( isa => 'Str', is => 'rw');
+has functions => (
+ metaclass => 'Collection::Hash',
+ is => 'rw',
+ isa => 'HashRef[Prophet::Web::FunctionResult]',
+ default => sub { {} },
+ provides => {
+ exists => 'exists',
+ keys => 'items',
+ get => 'get',
+ set => 'set',
+ },
+
+);
+
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+
More information about the Bps-public-commit
mailing list