1 package Reaction::UI::Controller::Role::Action::Simple;
3 use Moose::Role -traits => 'MethodAttributes';
5 requires 'push_viewport';
6 requires 'merge_config_hashes';
8 has action_viewport_map => (isa => 'HashRef', is => 'rw', lazy_build => 1);
9 has action_viewport_args => (isa => 'HashRef', is => 'rw', lazy_build => 1);
11 sub _build_action_viewport_map { {} }
13 sub _build_action_viewport_args { {} }
16 my ($self, $c, $vp_args) = @_;
17 my $action_name = $c->stack->[-1]->name;
18 my $vp = $self->action_viewport_map->{$action_name};
19 my $args = $self->merge_config_hashes(
21 $self->action_viewport_args->{$action_name} || {} ,
23 return $self->push_viewport($vp, %$args);
32 Reaction::UI::Controller::Role::Action::Simple
36 Provides a C<setup_viewport> method, which makes it easier to setup and
37 configure a viewport in controller actions.
41 package MyApp::Controller::Foo;
43 use base 'Reaction::Controller';
46 with 'Reaction::UI::Controller::Role::Action::Simple';
49 action_viewport_map => { bar => 'Reaction::UI::Viewport::Object' },
50 action_viewport_args => { location => 'custom-location' },
55 my $obj = $self->get_collection($c)->find( $some_key );
56 $self->setup_viewport($c, { model => $obj });
61 =head2 action_viewport_map
65 =item B<_build_action_viewport_map> - Returns empty hashref by default.
67 =item B<has_action_viewport_map> - Auto generated predicate
69 =item B<clear_action_viewport_map>- Auto generated clearer method
73 Read-write lazy building hashref. The keys should match action names in the
74 Controller and the value should be the ViewPort class that this action should
77 =head2 action_viewport_args
79 Read-write lazy building hashref. Additional ViewPort arguments for the action
80 named as the key in the controller.
84 =item B<_build_action_viewport_args> - Returns empty hashref by default.
86 =item B<has_action_viewport_args> - Auto generated predicate
88 =item B<clear_action_viewport_args>- Auto generated clearer method
94 =head2 setup_viewport $c, \%vp_args
96 Accepts two arguments, context, and a hashref of viewport arguments. It will
97 automatically determine the action name using the catalyst stack and call
98 C<push_viewport> with the ViewPort class name contained in the
99 C<action_viewport_map> with a set of options determined by merging C<$vp_args>
100 and the arguments contained in C<action_viewport_args>, if any.
106 =item L<Reaction::UI::Controller>
108 =item L<Reaction::UI::Controller::Role::Action::Simple>
110 =item L<Reaction::UI::Controller::Role::Action::Object>
112 =item L<Reaction::UI::Controller::Role::Action::List>
114 =item L<Reaction::UI::Controller::Role::Action::View>
116 =item L<Reaction::UI::Controller::Role::Action::Create>
118 =item L<Reaction::UI::Controller::Role::Action::Update>
120 =item L<Reaction::UI::Controller::Role::Action::Delete>
122 =item L<Reaction::UI::Controller::Role::Action::DeleteAll>
128 See L<Reaction::Class> for authors.
132 See L<Reaction::Class> for the license.