r31712@martha (orig r1247): groditi | 2009-10-02 17:02:01 -0400
groditi [Mon, 14 Dec 2009 21:03:04 +0000 (21:03 +0000)]
 whoops compile error
 r32396@martha (orig r1251):  wreis | 2009-11-04 14:37:47 -0500
 undo r1236
 r32468@martha (orig r1254):  edenc | 2009-11-16 16:48:46 -0500
  r15979@debian (orig r1252):  edenc | 2009-11-10 21:45:38 -0300
  branching for clone-and-inherit workaround
  r15980@debian (orig r1253):  edenc | 2009-11-10 21:50:34 -0300
  working around Moose glitch via parameterized roles

 r32469@martha (orig r1255):  edenc | 2009-11-16 17:06:25 -0500
 added clone and inherit fix to Field::Mutable::HiddenArray
 r32618@martha (orig r1256):  edenc | 2009-12-04 16:35:06 -0500
 fixed hash deref bug in the base controller

21 files changed:
Changes
Makefile.PL
lib/ComponentUI/Controller/Root.pm
lib/ComponentUI/Controller/TestModel/Bar.pm
lib/ComponentUI/Controller/TestModel/Baz.pm
lib/ComponentUI/Controller/TestModel/Foo.pm
lib/Reaction/UI/Controller.pm
lib/Reaction/UI/Controller/Collection.pm
lib/Reaction/UI/Controller/Collection/CRUD.pm
lib/Reaction/UI/Controller/Collection/CRUD/Search.pm
lib/Reaction/UI/Controller/Role/Action/Create.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/Action/Delete.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/Action/DeleteAll.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/Action/List.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/Action/Object.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/Action/Simple.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/Action/Update.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/Action/View.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/GetCollection.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Role/RedirectTo.pm [new file with mode: 0644]
lib/Reaction/UI/Controller/Root.pm

diff --git a/Changes b/Changes
index e2e42f2..07d89ae 100644 (file)
--- a/Changes
+++ b/Changes
@@ -11,6 +11,12 @@ Revision history for Reaction
           - Add example of explicitly stating action to ComponentUI
         - Don't override custom location in push_viewport
         - Wire layout_args, which was forgotten + example of how to use it
+        - CRUD functionality is now implemented as roles, so it can be used 
+          without needing to use Controller::Collection::CRUD
+        - Deprecate redirect_to and move it to an external role
+        - Controllers no longer 'use Reaction::Class' which was causing 
+          problems with metaclass compatibility. 'use Moose' is now the
+          preferred approach.
 0.002000 - 29 Apr 2008
         - Update CheckUniques role to use around instead of overrides
         - Stop using ACCEPT_CONTEXT, use InstancePerContext instead
index da2cb84..d20d44a 100644 (file)
@@ -33,6 +33,7 @@ requires 'MooseX::Types' => '0.10';
 requires 'MooseX::Types::URI' => '0.02';
 requires 'MooseX::Types::Common' => '0.001000';
 requires 'MooseX::Types::DateTime' => '0.03';
+requires 'MooseX::MethodAttributes' => '0.18';
 requires 'Path::Class::Dir';
 requires 'Path::Class::File';
 requires 'Scalar::Util' => '1.19';
index 9a2017f..bc45f33 100644 (file)
@@ -2,8 +2,9 @@ package ComponentUI::Controller::Root;
 
 use strict;
 use warnings;
-use base 'Reaction::UI::Controller::Root';
-use Reaction::Class;
+
+use Moose;
+BEGIN { extends 'Reaction::UI::Controller::Root'; }
 
 use aliased 'Reaction::UI::ViewPort';
 use aliased 'Reaction::UI::ViewPort::SiteLayout';
index 4701fff..6c1118c 100644 (file)
@@ -1,7 +1,7 @@
 package ComponentUI::Controller::TestModel::Bar;
 
-use base 'Reaction::UI::Controller::Collection::CRUD';
-use Reaction::Class;
+use Moose;
+BEGIN { extends 'Reaction::UI::Controller::Collection::CRUD'; }
 
 __PACKAGE__->config(
   model_name => 'TestModel',
@@ -16,17 +16,22 @@ __PACKAGE__->config(
         layout => 'bar/collection',
         member_class => 'Reaction::UI::ViewPort::Object',
         Member => { layout => 'bar/member' }
-      }
-    }
+      },
+    },
   },
 );
 
-sub get_collection {
-  my ($self, $c) = @_;
-  my $collection = $self->next::method($c);
+around get_collection => sub {
+  my ($orig, $self, $c) = @_;
+  my $collection = $self->$orig($c);
   return $collection->where({}, { prefetch => 'foo' });
-}
+};
+
+1;
+
+__END__;
 
+#put this aside for now
 sub create :Chained('base') {
   my $self = shift;
   my ($c) = @_;
index 6c88792..f5ff875 100644 (file)
@@ -1,7 +1,8 @@
 package ComponentUI::Controller::TestModel::Baz;
 
-use base 'Reaction::UI::Controller::Collection::CRUD';
-use Reaction::Class;
+use Moose;
+BEGIN { extends 'Reaction::UI::Controller::Collection::CRUD'; }
+
 use ComponentUI::UI::ViewPort::Baz::ListView::Member;
 
 __PACKAGE__->config(
index d636c6c..50dccde 100644 (file)
@@ -1,7 +1,7 @@
 package ComponentUI::Controller::TestModel::Foo;
 
-use base 'Reaction::UI::Controller::Collection::CRUD';
-use Reaction::Class;
+use Moose;
+BEGIN { extends 'Reaction::UI::Controller::Collection::CRUD'; }
 
 use aliased 'Reaction::UI::ViewPort::SearchableListViewContainer';
 use aliased 'ComponentUI::TestModel::Foo::SearchSpec';
@@ -56,16 +56,22 @@ for my $action (qw/view create update/){
 override _build_action_viewport_map => sub {
   my $map = super();
   $map->{list} = SearchableListViewContainer;
-  $map;
+  return $map;
 };
 
-sub _build_action_viewport_args {
-  my $self = shift;
-  my $args = $self->next::method(@_);
-  $args->{list}{action_prototypes}{delete_all}{label} = 'Delete All Records';
+override _build_action_viewport_args => sub {
+  my $args = super();
   $args->{list}{spec_class} = SearchSpec;
   $args->{list}{action_class} = Update;
   return $args;
+};
+
+sub object : Chained('base') PathPart('id') CaptureArgs(1) {
+  my ($self, $c, $object) = @_;
+  $self->next::method($c, $object);
+  # just as failing use case
 }
 
 1;
+
+__END__;
index f428941..0ff1c2c 100644 (file)
@@ -1,13 +1,16 @@
 package Reaction::UI::Controller;
 
-use base qw(Catalyst::Controller); # Reaction::Object);
-
-use Reaction::Class;
+use Moose;
 use Scalar::Util 'weaken';
 use namespace::clean -except => [ qw(meta) ];
 
+BEGIN { extends 'Catalyst::Controller'; }
+
 has context => (is => 'ro', isa => 'Object', weak_ref => 1);
-with 'Catalyst::Component::InstancePerContext';
+with(
+  'Catalyst::Component::InstancePerContext',
+  'Reaction::UI::Controller::Role::RedirectTo'
+);
 
 sub build_per_context_instance {
   my ($self, $c, @args) = @_;
@@ -54,31 +57,6 @@ sub pop_viewports_to {
   return $self->context->stash->{focus_stack}->pop_viewports_to($vp);
 }
 
-sub redirect_to {
-  my ($self, $c, $to, $cap, $args, $attrs) = @_;
-
-  #the confess calls could be changed later to $c->log ?
-  my $action;
-  my $reftype = ref($to);
-  if( $reftype eq '' ){
-    $action = $self->action_for($to);
-    confess("Failed to locate action ${to} in " . blessed($self)) unless $action;
-  } elsif($reftype eq 'ARRAY' && @$to == 2){ #is that overkill / too strict?
-    $action = $c->controller($to->[0])->action_for($to->[1]);
-    confess("Failed to locate action $to->[1] in $to->[0]" ) unless $action;
-  } elsif( blessed $to && $to->isa('Catalyst::Action') ){
-    $action = $to;
-  } else{
-    confess("Failed to locate action from ${to}");
-  }
-
-  $cap ||= $c->req->captures;
-  $args ||= $c->req->args;
-  $attrs ||= {};
-  my $uri = $c->uri_for($action, $cap, @$args, $attrs);
-  $c->res->redirect($uri);
-}
-
 sub make_context_closure {
   my($self, $closure) = @_;
   my $ctx = $self->context;
@@ -115,13 +93,17 @@ Reaction::UI::Controller - Reaction Base Controller Class
 
 =head1 DESCRIPTION
 
-Base Reaction Controller class. Inherits from:
+Base Reaction Controller class, subclass of L<Catalyst::Controller>.
+
+=head1 ROLES CONSUMED
 
 =over 4
 
-=item L<Catalyst::Controller>
-=item L<Catalyst::Component::ACCEPT_CONTEXT>
-=item L<Reaction::Object>
+=item L<Catalyst::Component::InstancePerContext>
+
+=item L<Reaction::UI::Controller::Role::RedirectTo>
+
+Please not that this functionality is now deprecated.
 
 =back
 
index 7597d0f..dd93a10 100644 (file)
@@ -1,18 +1,25 @@
 package Reaction::UI::Controller::Collection;
 
-use strict;
-use warnings;
-use base 'Reaction::UI::Controller';
-use Reaction::Class;
+use Moose;
+BEGIN { extends 'Reaction::UI::Controller'; }
 
 use aliased 'Reaction::UI::ViewPort::Collection::Grid';
-use aliased 'Reaction::UI::ViewPort::Object';
 
-has model_name => (isa => 'Str', is => 'rw', required => 1);
-has collection_name => (isa => 'Str', is => 'rw', required => 1);
+__PACKAGE__->config(
+  action => {
+    list => { Chained => 'base', PathPart => '' },
+    object => { Chained => 'base', PathPart => 'id' },
+    view => { Chained => 'object', },
+  },
+);
 
-has action_viewport_map => (isa => 'HashRef', is => 'rw', lazy_build => 1);
-has action_viewport_args => (isa => 'HashRef', is => 'rw', lazy_build => 1);
+with(
+  'Reaction::UI::Controller::Role::GetCollection',
+  'Reaction::UI::Controller::Role::Action::Simple',
+  'Reaction::UI::Controller::Role::Action::Object',
+  'Reaction::UI::Controller::Role::Action::View',
+  'Reaction::UI::Controller::Role::Action::List'
+);
 
 has default_member_actions => (
   isa => 'ArrayRef',
@@ -30,34 +37,34 @@ sub _build_default_member_actions { ['view'] }
 
 sub _build_default_collection_actions { [] }
 
-sub _build_action_viewport_map {
-  my $self = shift;
-  my %map;
-  $map{list} = Grid;
-  $map{view} = Object; #if grep {$_ eq 'view'} @{$self->default_member_actions};
-  return \%map;
-}
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{list} = Grid;
+  return $map;
+};
 
-sub _build_action_viewport_args {
+around _build_action_viewport_args => sub {
+  my $orig = shift;
   my $self = shift;
   my $args = { list => { Member => {} } };
 
-  my $m_protos = $args->{list}{Member}{action_prototypes} = {};
-  for my $action_name( @{ $self->default_member_actions }){
-    my $label = join(' ', map { ucfirst } split(/_/, $action_name));
-    my $proto = $self->_build_member_action_prototype($label, $action_name);
-    $m_protos->{$action_name} = $proto;
-  }
+   my $m_protos = $args->{list}{Member}{action_prototypes} = {};
+   for my $action_name( @{ $self->default_member_actions }){
+     my $label = join(' ', map { ucfirst } split(/_/, $action_name));
+     my $proto = $self->_build_member_action_prototype($label, $action_name);
+     $m_protos->{$action_name} = $proto;
+   }
 
-  my $c_protos = $args->{list}{action_prototypes} = {};
-  for my $action_name( @{ $self->default_collection_actions }){
-    my $label = join(' ', map { ucfirst } split(/_/, $action_name));
-    my $proto = $self->_build_collection_action_prototype($label, $action_name);
-    $c_protos->{$action_name} = $proto;
-  }
+   my $c_protos = $args->{list}{action_prototypes} = {};
+   for my $action_name( @{ $self->default_collection_actions }){
+     my $label = join(' ', map { ucfirst } split(/_/, $action_name));
+     my $proto = $self->_build_collection_action_prototype($label, $action_name);
+     $c_protos->{$action_name} = $proto;
+   }
 
   return $args;
-}
+};
 
 sub _build_member_action_prototype {
   my ($self, $label, $action_name) = @_;
@@ -81,56 +88,21 @@ sub _build_collection_action_prototype {
   };
 }
 
-#XXX candidate for futre optimization, should cache reader?
-sub get_collection {
-  my ($self, $c) = @_;
-  my $model = $c->model( $self->model_name );
-  confess "Failed to find Catalyst model named: " . $self->model_name
-    unless $model;
-  my $collection = $self->collection_name;
-  if( my $meth = $model->can( $collection ) ){
-    return $model->$meth;
-  } elsif ( my $meta = $model->can('meta') ){
-    if ( my $attr = $model->$meta->find_attribute_by_name($collection) ) {
-      my $reader = $attr->get_read_method;
-      return $model->$reader;
-    }
-  }
-  confess "Failed to find collection $collection";
-}
 
-sub base :Action :CaptureArgs(0) {
+sub base :CaptureArgs(0) {
   my ($self, $c) = @_;
 }
 
-sub object :Chained('base') :PathPart('id') :CaptureArgs(1) {
-  my ($self, $c, $key) = @_;
-  my $object = $self->get_collection($c)->find($key);
-  $c->detach("/error_404") unless $object;
-  $c->stash(object => $object);
-}
-
-sub list :Chained('base') :PathPart('') :Args(0) {
-  my ($self, $c) = @_;
-  my $collection = $c->stash->{collection} || $self->get_collection($c);
-  $self->basic_page($c, { collection => $collection });
-}
-
-sub view :Chained('object') :Args(0) {
-  my ($self, $c) = @_;
-  $self->basic_page($c, { model => $c->stash->{object} });
-}
+##DEPRECATED ACTION
 
 sub basic_page {
-  my ($self, $c, $vp_args) = @_;
-  my $action_name = $c->stack->[-1]->name;
-  my $vp = $self->action_viewport_map->{$action_name},
-  my $args = $self->merge_config_hashes
-    (
-     $vp_args || {},
-     $self->action_viewport_args->{$action_name} || {} ,
-    );
-  return $self->push_viewport($vp, %$args);
+  my( $self, $c, @args) = @_;
+  if( $c->debug ){
+    my ($package,undef,$line,$sub_name,@rest) = caller(1);
+    my $message = "The method 'basic_page', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated. Please use 'setup_viewport' instead.";
+    $c->log->debug( $message );
+  }
+  $self->setup_viewport( $c, @args );
 }
 
 1;
@@ -146,48 +118,25 @@ Reaction::UI::Controller
 Controller class used to make displaying collections easier.
 Inherits from L<Reaction::UI::Controller>.
 
-=head1 ATTRIBUTES
-
-=head2 model_name
+=head1 ROLES CONSUMED
 
-The name of the model this controller will use as it's data source. Should be a
-name that can be passed to C<$C-E<gt>model>
+This role also consumes the following roles:
 
-=head2 collection_name
+=over4
 
-The name of the collection whithin the model that this Controller will be
-utilizing.
+=item L<Reaction::UI::Controller::Role::Action::GetCollection>
 
-=head2 action_viewport_map
+=item L<Reaction::UI::Controller::Role::Action::Simple>
 
-=over 4
+=item L<Reaction::UI::Controller::Role::Action::Object>
 
-=item B<_build_action_viewport_map> - Provided builder method, see METHODS
+=item L<Reaction::UI::Controller::Role::Action::List>
 
-=item B<has_action_viewport_map> - Auto generated predicate
-
-=item B<clear_action_viewport_map>- Auto generated clearer method
+=item L<Reaction::UI::Controller::Role::Action::View>
 
 =back
 
-Read-write lazy building hashref. The keys should match action names in the
-Controller and the value should be the ViewPort class that this action should
-use. See method C<basic_page> for more info.
-
-=head2 action_viewport_args
-
-Read-write lazy building hashref. Additional ViewPort arguments for the action
-named as the key in the controller.  See method C<basic_page> for more info.
-
-=over 4
-
-=item B<_build_action_viewport_args> - Provided builder method, see METHODS
-
-=item B<has_action_viewport_args> - Auto generated predicate
-
-=item B<clear_action_viewport_args>- Auto generated clearer method
-
-=back
+=head1 ATTRIBUTES
 
 =head2 default_member_actions
 
@@ -225,16 +174,9 @@ is only empty.
 
 =head1 METHODS
 
-=head2 get_collection $c
-
-Returns an instance of the collection this controller uses.
-
 =head2 _build_action_viewport_map
 
-Provided builder for C<action_viewport_map>. Returns a hash containing:
-
-    list => 'Reaction::UI::ViewPort::Collection::Grid',
-    view => 'Reaction::UI::ViewPort::Object',
+Set C<list> to L<Reaction::UI::ViewPort::Collection::Grid>
 
 =head2 _build_action_viewport_args
 
@@ -269,11 +211,7 @@ based on the action, current captures.
 
 =head2 basic_page $c, \%vp_args
 
-Accepts two arguments, context, and a hashref of viewport arguments. It will
-automatically determine the action name using the catalyst stack and call
-C<push_viewport> with the ViewPort class name contained in the
-C<action_viewport_map> with a set of options determined by merging C<$vp_args>
-and the arguments contained in C<action_viewport_args>, if any.
+Deprecated alias to C<setup_viewport>.
 
 =head1 ACTIONS
 
@@ -283,27 +221,15 @@ Chain link, no-op.
 
 =head2 list
 
-Chain link, chained to C<base>. C<list> fetches the collection for the model
-and calls C<basic_page> with a single argument, C<collection>.
-
-The default ViewPort for this action is C<Reaction::UI::ViewPort::ListView> and
-can be changed by altering the C<action_viewport_map> attribute hash.
+Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::List>
 
 =head2 object
 
-Chain link, chained to C<base>, captures one argument, 'id'. Attempts to find
-a single object by searching for a member of the current collection which has a
-Primary Key or Unique constraint matching that argument. If the object is found
-it is stored in the stash under the C<object> key.
+Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::Object>
 
 =head2 view
 
-Chain link, chained to C<object>. Calls C<basic page> with one argument,
-C<model>, which contains an instance of the object fetched by the C<object>
-action link.
-
-The default ViewPort for this action is C<Reaction::UI::ViewPort::Object> and
-can be changed by altering the C<action_viewport_map> attribute hash.
+Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::View>
 
 =head1 SEE ALSO
 
index 11a29f9..fc7585e 100644 (file)
@@ -1,26 +1,32 @@
 package Reaction::UI::Controller::Collection::CRUD;
 
-use strict;
-use warnings;
-use base 'Reaction::UI::Controller::Collection';
-use Reaction::Class;
+use Moose;
+BEGIN { extends 'Reaction::UI::Controller::Collection'; }
 
-use aliased 'Reaction::UI::ViewPort::Action';
 use aliased 'Reaction::UI::ViewPort::ListView';
 
-sub _build_action_viewport_map {
-  my $self = shift;
-  my $map = $self->next::method(@_);
-  $map->{list} = ListView if exists $map->{list};
-
-  #my %allowed = map { $_ => undef }
-  #  ( @{$self->default_member_actions}, @{$self->default_collection_actions} );
-  my @local_actions = qw/create update delete delete_all/;
-  #$map->{$_} = Action for grep { exists $allowed{$_} } @local_actions;
-
-  $map->{$_} = Action for @local_actions;
+__PACKAGE__->config(
+  action => {
+    create => { Chained => 'base', },
+    delete_all => { Chained => 'base', },
+    update => { Chained => 'object', },
+    delete => { Chained => 'object', },
+  },
+);
+
+with(
+  'Reaction::UI::Controller::Role::Action::Create',
+  'Reaction::UI::Controller::Role::Action::Update',
+  'Reaction::UI::Controller::Role::Action::Delete',
+  'Reaction::UI::Controller::Role::Action::DeleteAll',
+);
+
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{list} = ListView;
   return $map;
-}
+};
 
 sub _build_default_member_actions {
   [ @{shift->next::method(@_)}, qw/update delete/ ];
@@ -30,37 +36,14 @@ sub _build_default_collection_actions {
   [ @{shift->next::method(@_)}, qw/create delete_all/ ];
 }
 
-sub get_model_action {
-  my ($self, $c, $name, $target) = @_;
-  return $target->action_for($name, ctx => $c);
-}
-sub create :Chained('base') :PathPart('create') :Args(0) {
-  my ($self, $c) = @_;
-  my $apply = sub { $self->after_create_callback( @_) };
-  my $close = sub { $self->on_create_close_callback( @_) };
-  my $vp_args = {
-    target => ($c->stash->{collection} || $self->get_collection($c)),
-    on_apply_callback => $self->make_context_closure($apply),
-    on_close_callback => $self->make_context_closure($close),
-  };
-  $self->basic_model_action( $c, $vp_args);
-}
-
-sub delete_all :Chained('base') :PathPart('delete_all') :Args(0) {
-  my ($self, $c) = @_;
-  my $close = sub { $self->on_delete_all_close_callback( @_) };
-  $self->basic_model_action( $c, {
-    target => ($c->stash->{collection} || $self->get_collection($c)),
-    on_close_callback => $self->make_context_closure($close),
-  });
-}
+##DEFAULT CALLBACKS
 
 sub on_delete_all_close_callback {
   my($self, $c) = @_;
   $self->redirect_to($c, 'list');
 }
 
-sub after_create_callback {
+sub on_create_apply_callback {
   my ($self, $c, $vp, $result) = @_;
   return $self->redirect_to
     ( $c, 'update', [ @{$c->req->captures}, $result->id ] );
@@ -71,15 +54,6 @@ sub on_create_close_callback {
   $self->redirect_to( $c, 'list' );
 }
 
-sub update :Chained('object') :Args(0) {
-  my ($self, $c) = @_;
-  my $close = sub { $self->on_update_close_callback( @_) };
-  my $vp_args = {
-    on_close_callback => $self->make_context_closure($close),
-  };
-  $self->basic_model_action( $c, $vp_args);
-}
-
 sub on_update_close_callback {
   my($self, $c) = @_;
   #this needs a better solution. currently thinking about it
@@ -88,15 +62,6 @@ sub on_update_close_callback {
   $self->redirect_to($c, 'list', \@cap);
 }
 
-sub delete :Chained('object') :Args(0) {
-  my ($self, $c) = @_;
-  my $close = sub { $self->on_delete_close_callback( @_) };
-  my $vp_args = {
-    on_close_callback => $self->make_context_closure($close),
-  };
-  $self->basic_model_action( $c, $vp_args);
-}
-
 sub on_delete_close_callback {
   my($self, $c) = @_;
   #this needs a better solution. currently thinking about it
@@ -105,8 +70,25 @@ sub on_delete_close_callback {
   $self->redirect_to($c, 'list', \@cap);
 }
 
+#### DEPRECATED METHODS
+
+sub get_model_action {
+  my ($self, $c, $name, $target) = @_;
+  if( $c->debug ){
+    my ($package,undef,$line,$sub_name,@rest) = caller(1);
+    my $message = "The method 'get_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
+    $c->log->debug( $message );
+  }
+  return $target->action_for($name, ctx => $c);
+}
+
 sub basic_model_action {
   my ($self, $c, $vp_args) = @_;
+  if( $c->debug ){
+    my ($package,undef,$line,$sub_name,@rest) = caller(1);
+    my $message = "The method 'basic_model_action', called from sub '${sub_name}' in package ${package} at line ${line} is deprecated.";
+    $c->log->debug( $message );
+  }
   my $stash = $c->stash;
   my $target = delete $vp_args->{target};
   $target ||= ($stash->{object} || $stash->{collection} || $self->get_collection($c));
@@ -134,31 +116,45 @@ easily create complex and highly flexible CRUD functionality for your
 InterfaceModel models by providing a simple way to render and process your
 custom InterfaceModel Actions and customize built-ins.
 
+=head1 ROLES CONSUMED
+
+This role also consumes the following roles:
+
+=over4
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
 =head1 METHODS
 
 =head2 get_model_action $c, $action_name, $target_im
 
-Get an instance of the C<$action_name> 
+DEPRECATED. Get an instance of the C<$action_name> 
 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> for model C<$target>
 This action is suitable for passing to an 
 C<Action|Reaction::UI::ViewPort::Action> viewport
 
-=head2 after_create_callback $c, $vp, $result
-
-When a <create> action is applied, move the user to the new object's,
-C<update> page.
-
 =head2 basic_model_action $c, \%vp_args
 
-Extension to C<basic_page> which automatically instantiates an 
+DEPRECTAED extension to C<basic_page> which automatically instantiates an 
 L<InterfaceModel::Action|Reaction::InterfaceModel::Action> with the right
 data target using C<get_model_action>
 
+=head2 after_create_callback $c, $vp, $result
+
+When a <create> action is applied, move the user to the new object's,
+C<update> page.
+
 =head2 _build_action_viewport_map
 
-Map C<create>, C<update>, C<delete> and C<delete_all> to use the
-L<Action|Reaction::UI::ViewPort::Action> viewport by default and have C<list>
-use L<ListView|Reaction::UI::ViewPort::ListView> by default.
+Map C<list> to L<ListView|Reaction::UI::ViewPort::ListView>.
 
 =head2 _build_default_member_actions
 
@@ -172,34 +168,19 @@ Add C<create> and C<delete_all> to the list of default actions.
 
 =head2 create
 
-Chaned to C<base>. Create a new member of the collection represented by 
-this controller. By default it attaches the C<after_create_callback> to
-DWIM after apply operations.
-
-See L<Create|Reaction::InterfaceModel::Action::DBIC::ResultSet::Create>
- for more info.
+Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::Create>
 
 =head2 delete_all
 
-Chained to B<base>, delete all the members of the B<collection>. In most cases
-this is very much like a C<TRUNCATE> operation.
-
-See L<DeleteAll|Reaction::InterfaceModel::Action::DBIC::ResultSet::DeleteAll>
- for more info.
+Chained to C<base>. See L<Reaction::UI::Controller::Role::Action::DeleteAll>
 
 =head2 update
 
-Chained to C<object>, update a single object.
-
-See L<Update|Reaction::InterfaceModel::Action::DBIC::Result::Update>
- for more info.
+Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Update>
 
 =head2 delete
 
-Chained to C<object>, delete a single object.
-
-See L<Delete|Reaction::InterfaceModel::Action::DBIC::Result::Delete>
- for more info.
+Chained to C<object>. See L<Reaction::UI::Controller::Role::Action::Delete>
 
 =head1 SEE ALSO
 
index e9d467d..7d4560f 100644 (file)
@@ -1,6 +1,7 @@
 package Reaction::UI::Controller::Collection::CRUD::Search;
-use parent 'Reaction::UI::Controller::Collection::CRUD';
-use Reaction::Class;
+
+use Moose;
+BEGIN { extends 'Reaction::UI::Controller::Collection::CRUD'; }
 
 use aliased 'Reaction::UI::ViewPort::SearchableListViewContainer';
 
diff --git a/lib/Reaction/UI/Controller/Role/Action/Create.pm b/lib/Reaction/UI/Controller/Role/Action/Create.pm
new file mode 100644 (file)
index 0000000..f227ef8
--- /dev/null
@@ -0,0 +1,145 @@
+package Reaction::UI::Controller::Role::Action::Create;
+
+use Moose::Role -traits => 'MethodAttributes';
+use Reaction::UI::ViewPort::Action;
+
+requires qw/get_collection make_context_closure setup_viewport/;
+
+sub create :Action :Args(0) {
+  my ($self, $c) = @_;
+  my $target = $c->stash->{collection} || $self->get_collection($c);
+  my %vp_args = ( model => $target->action_for('Create') );
+
+  if( $self->can('on_create_apply_callback') ){
+    my $apply = sub { $self->on_create_apply_callback( @_) };
+    $vp_args{on_apply_callback} = $self->make_context_closure( $apply );
+  }
+  if( $self->can('on_create_close_callback') ){
+    my $close = sub { $self->on_create_close_callback( @_) };
+    $vp_args{on_close_callback} = $self->make_context_closure( $close );
+  }
+
+  $self->setup_viewport( $c, \%vp_args );
+}
+
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{create} = 'Reaction::UI::ViewPort::Action';
+  return $map;
+};
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::Create - Create action
+
+=head1 DESCRIPTION
+
+Provides a C<create> action, which sets up an L<Action Viewport|Reaction::UI::Viewport::Action>
+by calling C<action_for> on either the object located in the C<collection> slot
+of the C<stash> or on the object returned by the method C<get_collection>.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with(
+      'Reaction::UI::Controller::Role::GetCollection',
+      'Reaction::UI::Controller::Role::Action::Simple',
+      'Reaction::UI::Controller::Role::Action::Create'
+    );
+
+    __PACKAGE__->config( action => {
+      create => { Chained => 'base' },
+    } );
+
+    sub base :Chained('/base') :CaptureArgs(0) {
+      ...
+    }
+
+    sub on_create_apply_callback{ #optional callback
+      my($self, $c, $vp, $result) = @_;
+      ...
+    }
+
+    sub on_create_close_callback{ #optional callback
+      my($self, $c, $vp) = @_;
+      ...
+    }
+
+=head1 ROLES CONSUMED
+
+This role also consumes the following roles:
+
+=over4
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=back
+
+=head1 REQUIRED METHODS
+
+The following methods must be provided by the consuming class:
+
+=over4
+
+=item C<get_collection>
+
+=item C<make_context_closure>
+
+=back
+
+=head1 ACTIONS
+
+=head2 create
+
+Chain endpoint with no args, sets up the viewport with the appropriate action.
+If the methods C<on_create_apply_callback> and C<on_create_close_callback> are
+present in the consuming class, they will be used as callbacks in the viewport.
+
+=head1 METHODS
+
+=head2 _build_action_viewport_map
+
+Extends to set the C<create> key in the map to L<Reaction::UI::ViewPort::Action>
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::GetCollection>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/Action/Delete.pm b/lib/Reaction/UI/Controller/Role/Action/Delete.pm
new file mode 100644 (file)
index 0000000..4dc1985
--- /dev/null
@@ -0,0 +1,145 @@
+package Reaction::UI::Controller::Role::Action::Delete;
+
+use Moose::Role -traits => 'MethodAttributes';
+use Reaction::UI::ViewPort::Action;
+
+requires qw/make_context_closure setup_viewport/;
+
+sub delete :Action :Args(0) {
+  my ($self, $c) = @_;
+  my $target = $c->stash->{object};
+  my %vp_args = ( model => $target->action_for('Delete') );
+
+  if( $self->can('on_delete_apply_callback') ){
+    my $apply = sub { $self->on_delete_apply_callback( @_) };
+    $vp_args{on_apply_callback} = $self->make_context_closure( $apply );
+  }
+  if( $self->can('on_delete_close_callback') ){
+    my $close = sub { $self->on_delete_close_callback( @_) };
+    $vp_args{on_close_callback} = $self->make_context_closure( $close );
+  }
+
+  $self->setup_viewport( $c, \%vp_args );
+}
+
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{delete} = 'Reaction::UI::ViewPort::Action';
+  return $map;
+};
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::Delete - Delete action
+
+=head1 DESCRIPTION
+
+Provides a C<delete> action, which sets up an L<Action Viewport|Reaction::UI::Viewport::Action>
+by calling C<action_for> on the object located in the C<object> slot of the
+C<stash>.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with(
+      'Reaction::UI::Controller::Role::GetCollection',
+      'Reaction::UI::Controller::Role::Action::Simple',
+      'Reaction::UI::Controller::Role::Action::Object',
+      'Reaction::UI::Controller::Role::Action::Delete'
+    );
+
+    __PACKAGE__->config( action => {
+      object => { Chained => 'base' },
+      delete => { Chained => 'object' },
+    } );
+
+    sub base :Chained('/base') :CaptureArgs(0) {
+      ...
+    }
+
+    sub on_delete_apply_callback{ #optional callback
+      my($self, $c, $vp, $result) = @_;
+      ...
+    }
+
+    sub on_delete_close_callback{ #optional callback
+      my($self, $c, $vp) = @_;
+      ...
+    }
+
+=head1 ROLES CONSUMED
+
+This role also consumes the following roles:
+
+=over4
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=back
+
+=head1 REQUIRED METHODS
+
+The following methods must be provided by the consuming class:
+
+=over4
+
+=item C<make_context_closure>
+
+=back
+
+=head1 ACTIONS
+
+=head2 delete
+
+Chain endpoint with no args, sets up the viewport with the appropriate action.
+If the methods C<on_delete_apply_callback> and C<on_delete_close_callback> are
+present in the consuming class, they will be used as callbacks in the viewport.
+
+=head1 METHODS
+
+=head2 _build_action_viewport_map
+
+Extends to set the C<delete> key in the map to L<Reaction::UI::ViewPort::Action>
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::GetCollection>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/Action/DeleteAll.pm b/lib/Reaction/UI/Controller/Role/Action/DeleteAll.pm
new file mode 100644 (file)
index 0000000..797a835
--- /dev/null
@@ -0,0 +1,145 @@
+package Reaction::UI::Controller::Role::Action::DeleteAll;
+
+use Moose::Role -traits => 'MethodAttributes';
+use Reaction::UI::ViewPort::Action;
+
+requires qw/get_collection make_context_closure setup_viewport/;
+
+sub delete_all :Action :Args(0) {
+  my ($self, $c) = @_;
+  my $target = $c->stash->{collection} || $self->get_collection($c);
+  my %vp_args = ( model => $target->action_for('DeleteAll') );
+
+  if( $self->can('on_delete_all_apply_callback') ){
+    my $apply = sub { $self->on_delete_all_apply_callback( @_) };
+    $vp_args{on_apply_callback} = $self->make_context_closure( $apply );
+  }
+  if( $self->can('on_delete_all_close_callback') ){
+    my $close = sub { $self->on_delete_all_close_callback( @_) };
+    $vp_args{on_close_callback} = $self->make_context_closure( $close );
+  }
+
+  $self->setup_viewport( $c, \%vp_args );
+}
+
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{delete_all} = 'Reaction::UI::ViewPort::Action';
+  return $map;
+};
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::DeleteAll - Delete All action
+
+=head1 DESCRIPTION
+
+Provides a C<delete_all> action, which sets up an L<Action Viewport|Reaction::UI::Viewport::Action>
+by calling C<action_for> on either the object located in the C<collection> slot
+of the C<stash> or on the object returned by the method C<get_collection>.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with(
+      'Reaction::UI::Controller::Role::GetCollection',
+      'Reaction::UI::Controller::Role::Action::Simple',
+      'Reaction::UI::Controller::Role::Action::DeleteAll'
+    );
+
+    __PACKAGE__->config( action => {
+      delete_all => { Chained => 'base' },
+    } );
+
+    sub base :Chained('/base') :CaptureArgs(0) {
+      ...
+    }
+
+    sub on_delete_all_apply_callback{ #optional callback
+      my($self, $c, $vp, $result) = @_;
+      ...
+    }
+
+    sub on_delete_all_close_callback{ #optional callback
+      my($self, $c, $vp) = @_;
+      ...
+    }
+
+=head1 ROLES CONSUMED
+
+This role also consumes the following roles:
+
+=over4
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=back
+
+=head1 REQUIRED METHODS
+
+The following methods must be provided by the consuming class:
+
+=over4
+
+=item C<get_collection>
+
+=item C<make_context_closure>
+
+=back
+
+=head1 ACTIONS
+
+=head2 delete_all
+
+Chain endpoint with no args, sets up the viewport with the appropriate action.
+If the methods C<on_delete_all_apply_callback> and C<on_delete_all_close_callback> are
+present in the consuming class, they will be used as callbacks in the viewport.
+
+=head1 METHODS
+
+=head2 _build_action_viewport_map
+
+Extends to set the C<delete_all> key in the map to L<Reaction::UI::ViewPort::Action>
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::GetCollection>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/Action/List.pm b/lib/Reaction/UI/Controller/Role/Action/List.pm
new file mode 100644 (file)
index 0000000..be15fd8
--- /dev/null
@@ -0,0 +1,121 @@
+package Reaction::UI::Controller::Role::Action::List;
+
+use Moose::Role -traits => 'MethodAttributes';
+use Reaction::UI::ViewPort::Collection;
+
+requires qw/get_collection setup_viewport/;
+
+sub list :Action :Args(0) {
+  my ($self, $c) = @_;
+  my $collection = $c->stash->{collection} || $self->get_collection($c);
+  $self->setup_viewport($c, { collection => $collection });
+}
+
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{list} = 'Reaction::UI::ViewPort::Collection';
+  return $map;
+};
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::List - List action
+
+=head1 DESCRIPTION
+
+Provides a C<list> action, which sets up an L<Collection Viewport|Reaction::UI::Viewport::Collection>
+using the collection contained in the C<collection> slot of the stash, if
+present, or using the object returned by the method C<get_collection>.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with(
+      'Reaction::UI::Controller::Role::GetCollection',
+      'Reaction::UI::Controller::Role::Action::Simple',
+      'Reaction::UI::Controller::Role::Action::List'
+    );
+
+
+    __PACKAGE__->config( action => {
+      list => { Chained => 'base' },
+    } );
+
+    sub base :Chained('/base') :CaptureArgs(0) {
+      ...
+    }
+
+=head1 ROLES CONSUMED
+
+This role also consumes the following roles:
+
+=over4
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=back
+
+=head1 REQUIRED METHODS
+
+The following methods must be provided by the consuming class:
+
+=over4
+
+=item C<get_collection>
+
+=back
+
+=head1 ACTIONS
+
+=head2 list
+
+Chain endpoint with no args, sets up the viewport with the appropriate action.
+
+=head1 METHODS
+
+=head2 _build_action_viewport_map
+
+Extends to set the C<list> key in the map to L<Reaction::UI::ViewPort::Action>
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::GetCollection>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/Action/Object.pm b/lib/Reaction/UI/Controller/Role/Action/Object.pm
new file mode 100644 (file)
index 0000000..95dbfbd
--- /dev/null
@@ -0,0 +1,108 @@
+package Reaction::UI::Controller::Role::Action::Object;
+
+use Moose::Role -traits => 'MethodAttributes';
+
+requires 'get_collection';
+
+sub object :Action :CaptureArgs(1) {
+  my ($self, $c, $key) = @_;
+  if( my $object = $self->get_collection($c)->find($key) ){
+    $c->stash(object => $object);
+    return $object;
+  }
+  $c->res->status(404);
+  return;
+}
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::Object
+
+=head1 DESCRIPTION
+
+Provides an C<object> action, which attempts to find an item in a collection
+and store it in the stash.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with(
+      'Reaction::UI::Controller::Role::GetCollection',
+      'Reaction::UI::Controller::Role::Action::Simple',
+      'Reaction::UI::Controller::Role::Action::Object',
+    );
+
+    __PACKAGE__->config( action => {
+      object => { Chained => 'base', PathPart => 'id' },
+      foo_action => { Chained => 'object' },
+    } );
+
+    sub base :Chained('/base') :CaptureArgs(0) {
+      ...
+    }
+
+    sub foo_action :Args(0){
+      my($self, $c) = @_;
+      $c->stash->{object}; #object is here....
+    }
+
+=head1 REQUIRED METHODS
+
+The following methods must be provided by the consuming class:
+
+=over4
+
+=item C<get_collection>
+
+=back
+
+=head1 ACTIONS
+
+=head2 object
+
+Chain link, captures one argument. Attempts to find a single object by passing
+the captured argument to the C<find> method of the collection returned by
+C<get_collection>. If the object is found it is stored in the stash under the
+C<object> key.
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::GetCollection>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/Action/Simple.pm b/lib/Reaction/UI/Controller/Role/Action/Simple.pm
new file mode 100644 (file)
index 0000000..351d124
--- /dev/null
@@ -0,0 +1,134 @@
+package Reaction::UI::Controller::Role::Action::Simple;
+
+use Moose::Role -traits => 'MethodAttributes';
+
+requires 'push_viewport';
+requires 'merge_config_hashes';
+
+has action_viewport_map => (isa => 'HashRef', is => 'rw', lazy_build => 1);
+has action_viewport_args => (isa => 'HashRef', is => 'rw', lazy_build => 1);
+
+sub _build_action_viewport_map { {} }
+
+sub _build_action_viewport_args { {} }
+
+sub setup_viewport {
+  my ($self, $c, $vp_args) = @_;
+  my $action_name = $c->stack->[-1]->name;
+  my $vp = $self->action_viewport_map->{$action_name};
+  my $args = $self->merge_config_hashes(
+    $vp_args || {},
+    $self->action_viewport_args->{$action_name} || {} ,
+  );
+  return $self->push_viewport($vp, %$args);
+}
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::Simple
+
+=head1 DESCRIPTION
+
+Provides a C<setup_viewport> method, which makes it easier to setup and
+configure a viewport in controller actions.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with 'Reaction::UI::Controller::Role::Action::Simple';
+
+    __PACKAGE__->config(
+      action_viewport_map => { bar => 'Reaction::UI::Viewport::Object' },
+      action_viewport_args => { location => 'custom-location' },
+    );
+
+    sub bar :Local {
+      my($self, $c) = @_;
+      my $obj = $self->get_collection($c)->find( $some_key );
+      $self->setup_viewport($c, { model => $obj });
+    }
+
+=head1 ATTRIBUTES
+
+=head2 action_viewport_map
+
+=over 4
+
+=item B<_build_action_viewport_map> - Returns empty hashref by default.
+
+=item B<has_action_viewport_map> - Auto generated predicate
+
+=item B<clear_action_viewport_map>- Auto generated clearer method
+
+=back
+
+Read-write lazy building hashref. The keys should match action names in the
+Controller and the value should be the ViewPort class that this action should
+use.
+
+=head2 action_viewport_args
+
+Read-write lazy building hashref. Additional ViewPort arguments for the action
+named as the key in the controller.
+
+=over 4
+
+=item B<_build_action_viewport_args> - Returns empty hashref by default.
+
+=item B<has_action_viewport_args> - Auto generated predicate
+
+=item B<clear_action_viewport_args>- Auto generated clearer method
+
+=back
+
+=head1 METHODS
+
+=head2 setup_viewport $c, \%vp_args
+
+Accepts two arguments, context, and a hashref of viewport arguments. It will
+automatically determine the action name using the catalyst stack and call
+C<push_viewport> with the ViewPort class name contained in the
+C<action_viewport_map> with a set of options determined by merging C<$vp_args>
+and the arguments contained in C<action_viewport_args>, if any.
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/Action/Update.pm b/lib/Reaction/UI/Controller/Role/Action/Update.pm
new file mode 100644 (file)
index 0000000..6788e9c
--- /dev/null
@@ -0,0 +1,145 @@
+package Reaction::UI::Controller::Role::Action::Update;
+
+use Moose::Role -traits => 'MethodAttributes';
+use Reaction::UI::ViewPort::Action;
+
+requires qw/make_context_closure setup_viewport/;
+
+sub update :Action :Args(0) {
+  my ($self, $c) = @_;
+  my $target = $c->stash->{object};
+  my %vp_args = ( model => $target->action_for('Update') );
+
+  if( $self->can('on_update_apply_callback') ){
+    my $apply = sub { $self->on_update_apply_callback( @_) };
+    $vp_args{on_apply_callback} = $self->make_context_closure( $apply );
+  }
+  if( $self->can('on_update_close_callback') ){
+    my $close = sub { $self->on_update_close_callback( @_) };
+    $vp_args{on_close_callback} = $self->make_context_closure( $close );
+  }
+
+  $self->setup_viewport( $c, \%vp_args );
+}
+
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{update} = 'Reaction::UI::ViewPort::Action';
+  return $map;
+};
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::Update - Update action
+
+=head1 DESCRIPTION
+
+Provides a C<update> action, which sets up an L<Action Viewport|Reaction::UI::Viewport::Action>
+by calling C<action_for> on the object located in the C<object> slot of the
+C<stash>.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with(
+      'Reaction::UI::Controller::Role::GetCollection',
+      'Reaction::UI::Controller::Role::Action::Simple',
+      'Reaction::UI::Controller::Role::Action::Object',
+      'Reaction::UI::Controller::Role::Action::Update'
+    );
+
+    __PACKAGE__->config( action => {
+      object => { Chained => 'base' },
+      update => { Chained => 'object' },
+    } );
+
+    sub base :Chained('/base') :CaptureArgs(0) {
+      ...
+    }
+
+    sub on_update_apply_callback{ #optional callback
+      my($self, $c, $vp, $result) = @_;
+      ...
+    }
+
+    sub on_update_close_callback{ #optional callback
+      my($self, $c, $vp) = @_;
+      ...
+    }
+
+=head1 ROLES CONSUMED
+
+This role also consumes the following roles:
+
+=over4
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=back
+
+=head1 REQUIRED METHODS
+
+The following methods must be provided by the consuming class:
+
+=over4
+
+=item C<make_context_closure>
+
+=back
+
+=head1 ACTIONS
+
+=head2 update
+
+Chain endpoint with no args, sets up the viewport with the appropriate action.
+If the methods C<on_update_apply_callback> and C<on_update_close_callback> are
+present in the consuming class, they will be used as callbacks in the viewport.
+
+=head1 METHODS
+
+=head2 _build_action_viewport_map
+
+Extends to set the C<delete> key in the map to L<Reaction::UI::ViewPort::Action>
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::GetCollection>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/Action/View.pm b/lib/Reaction/UI/Controller/Role/Action/View.pm
new file mode 100644 (file)
index 0000000..ce7bb8f
--- /dev/null
@@ -0,0 +1,111 @@
+package Reaction::UI::Controller::Role::Action::View;
+
+use Moose::Role -traits => 'MethodAttributes';
+use Reaction::UI::ViewPort::Object;
+
+requires 'setup_viewport';
+
+sub view :Action :Args(0) {
+  my ($self, $c) = @_;
+  $self->setup_viewport($c, { model => $c->stash->{object} });
+}
+
+around _build_action_viewport_map => sub {
+  my $orig = shift;
+  my $map = shift->$orig( @_ );
+  $map->{view} = 'Reaction::UI::ViewPort::Object';
+  return $map;
+};
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::Action::View - View action
+
+=head1 DESCRIPTION
+
+Provides a C<view> action, which sets up an L<Object Viewport|Reaction::UI::Viewport::Object>
+using the object located in the C<object> slot of the C<stash>.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with(
+      'Reaction::UI::Controller::Role::GetCollection',
+      'Reaction::UI::Controller::Role::Action::Simple',
+      'Reaction::UI::Controller::Role::Action::Object',
+      'Reaction::UI::Controller::Role::Action::View'
+    );
+
+    __PACKAGE__->config( action => {
+      object => { Chained => 'base' },
+      view => { Chained => 'object' },
+    } );
+
+    sub base :Chained('/base') :CaptureArgs(0) {
+      ...
+    }
+
+
+=head1 ROLES CONSUMED
+
+This role also consumes the following roles:
+
+=over4
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=back
+
+=head1 ACTIONS
+
+=head2 view
+
+Chain endpoint with no args, sets up the viewport with the appropriate viewport.
+
+=head1 METHODS
+
+=head2 _build_action_viewport_map
+
+Extends to set the C<view> key in the map to L<Reaction::UI::ViewPort::Object>
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::GetCollection>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/GetCollection.pm b/lib/Reaction/UI/Controller/Role/GetCollection.pm
new file mode 100644 (file)
index 0000000..8f40ce2
--- /dev/null
@@ -0,0 +1,104 @@
+package Reaction::UI::Controller::Role::GetCollection;
+
+use Moose::Role -traits => 'MethodAttributes';
+
+has model_name => (isa => 'Str', is => 'rw', required => 1);
+has collection_name => (isa => 'Str', is => 'rw', required => 1);
+
+sub get_collection {
+  my ($self, $c) = @_;
+  my $model = $c->model( $self->model_name );
+  confess "Failed to find Catalyst model named: " . $self->model_name
+    unless $model;
+  my $collection = $self->collection_name;
+  if( my $meth = $model->can( $collection ) ){
+    return $model->$meth;
+  } elsif ( my $meta = $model->can('meta') ){
+    if ( my $attr = $model->$meta->find_attribute_by_name($collection) ) {
+      my $reader = $attr->get_read_method;
+      return $model->$reader;
+    }
+  }
+  confess "Failed to find collection $collection";
+}
+
+1;
+
+__END__;
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::GetCollection
+
+=head1 DESCRIPTION
+
+Provides a C<get_collection> method, which fetches an C<Collection> object
+from a specified model.
+
+=head1 SYNOPSYS
+
+    package MyApp::Controller::Foo;
+
+    use base 'Reaction::Controller';
+    use Reaction::Class;
+
+    with 'Reaction::UI::Controller::Role::GetCollection';
+
+    __PACKAGE__->config( model_name => 'MyAppIM', collection_name => 'foos' );
+
+    sub bar :Local {
+      my($self, $c) = @_;
+      my $obj = $self->get_collection($c)->find( $some_key );
+    }
+
+=head1 ATTRIBUTES
+
+=head2 model_name
+
+The name of the model this controller will use as it's data source. Should be a
+name that can be passed to C<$C-E<gt>model>
+
+=head2 collection_name
+
+The name of the collection whithin the model that this Controller will be
+utilizing.
+
+=head1 METHODS
+
+=head2 get_collection $c
+
+Returns an instance of the collection this controller uses.
+
+=head1 SEE ALSO
+
+=over4
+
+=item L<Reaction::UI::Controller>
+
+=item L<Reaction::UI::Controller::Role::Action::Simple>
+
+=item L<Reaction::UI::Controller::Role::Action::Object>
+
+=item L<Reaction::UI::Controller::Role::Action::List>
+
+=item L<Reaction::UI::Controller::Role::Action::View>
+
+=item L<Reaction::UI::Controller::Role::Action::Create>
+
+=item L<Reaction::UI::Controller::Role::Action::Update>
+
+=item L<Reaction::UI::Controller::Role::Action::Delete>
+
+=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
+
+=back
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
diff --git a/lib/Reaction/UI/Controller/Role/RedirectTo.pm b/lib/Reaction/UI/Controller/Role/RedirectTo.pm
new file mode 100644 (file)
index 0000000..7d35b10
--- /dev/null
@@ -0,0 +1,78 @@
+package Reaction::UI::Controller::Role::RedirectTo;
+
+use Moose::Role;
+
+sub redirect_to {
+  my ($self, $c, $to, $cap, $args, $attrs) = @_;
+
+  $c->log->debug(
+    "Using redirect_to is now deprecated and may be removed in the future."
+  );
+
+  #the confess calls could be changed later to $c->log ?
+  my $action;
+  my $reftype = ref($to);
+  if( $reftype eq '' ){
+    $action = $self->action_for($to);
+    confess("Failed to locate action ${to} in " . blessed($self)) unless $action;
+  } elsif($reftype eq 'ARRAY' && @$to == 2){ #is that overkill / too strict?
+    $action = $c->controller($to->[0])->action_for($to->[1]);
+    confess("Failed to locate action $to->[1] in $to->[0]" ) unless $action;
+  } elsif( blessed $to && $to->isa('Catalyst::Action') ){
+    $action = $to;
+  } else{
+    confess("Failed to locate action from ${to}");
+  }
+
+  $cap ||= $c->req->captures;
+  $args ||= $c->req->args;
+  $attrs ||= {};
+  my $uri = $c->uri_for($action, $cap, @$args, $attrs);
+  $c->res->redirect($uri);
+}
+
+1;
+
+__END__;
+
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::RedirectTo
+
+=head1 DESCRIPTION
+
+Provides a C<redirect_to> method, which aims to be a more convenient way to
+create internal redirects vs C<Catalyst::uri_for> and C<Catalyst::Response::redirect>
+
+=head1 DEPRECATION NOTICE
+
+This method was separated out of L<Catalyst::Controller> to facilitate deprecation.
+The behavior of this method is, by design, flawed and you should aim to replace
+any instances of it in your codebase;
+
+=head1 METHODS
+
+=head2 redirect_to $c, 'action_name', \@captures, \@args, \%query_parms
+
+=head2 redirect_to $c, $action_object, \@captures, \@args, \%query_parms
+
+=head2 redirect_to $c, [ Controller_name => 'action_name' ], \@captures, \@args, \%query_parms
+
+Will create a uri from the arguments given and redirect to it without detaching.
+If captures and arguments are not explicitly given, the ones from the current
+request will be used. If query-parameters are not given, none will be used.
+
+The first argument after C<$c> cab be one of three, the name of an action present
+in the controller returned by C<$c-E<gt>controller>, an action object, or an
+array reference contraining 2 items, a controller name and an action name.
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
index eb0e3b5..f27ffcf 100644 (file)
@@ -1,9 +1,10 @@
 package Reaction::UI::Controller::Root;
 
-use base qw/Reaction::UI::Controller/;
-use Reaction::Class;
+use Moose;
 use Reaction::UI::Window;
 
+BEGIN { extends 'Reaction::UI::Controller'; }
+
 __PACKAGE__->config(
   view_name => 'XHTML',
   content_type => 'text/html',