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/Delete.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/Delete.pm')
-rw-r--r-- | lib/Reaction/UI/Controller/Role/Action/Delete.pm | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/lib/Reaction/UI/Controller/Role/Action/Delete.pm b/lib/Reaction/UI/Controller/Role/Action/Delete.pm new file mode 100644 index 0000000..4dc1985 --- /dev/null +++ b/lib/Reaction/UI/Controller/Role/Action/Delete.pm @@ -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 |