diff options
author | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-12-15 21:06:24 +0000 |
---|---|---|
committer | groditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-12-15 21:06:24 +0000 |
commit | aff8f204bc4c7651c9b801a0bee12605b88a706a (patch) | |
tree | e80625ba56510628730b69e5efca1cbf92df4d45 /lib/Reaction/UI/Controller/Role/Action/Object.pm | |
parent | a722f3e3e226a7319f69722de01c06792b3cf2c3 (diff) | |
parent | 931cbc8d6673ec352b369ae2f70f01ff96b4f507 (diff) | |
download | reaction-aff8f204bc4c7651c9b801a0bee12605b88a706a.tar.gz reaction-aff8f204bc4c7651c9b801a0bee12605b88a706a.zip |
r31501@martha (orig r1230): groditi | 2009-09-11 09:36:16 -0400
initial refactor of CRUD controller actions as roles
Diffstat (limited to 'lib/Reaction/UI/Controller/Role/Action/Object.pm')
-rw-r--r-- | lib/Reaction/UI/Controller/Role/Action/Object.pm | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/Reaction/UI/Controller/Role/Action/Object.pm b/lib/Reaction/UI/Controller/Role/Action/Object.pm new file mode 100644 index 0000000..95dbfbd --- /dev/null +++ b/lib/Reaction/UI/Controller/Role/Action/Object.pm @@ -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 |