first part of fix for attributes and roles mess. metclass coompat bug still lurks
[catagits/Reaction.git] / lib / Reaction / UI / Controller / Role / Action / Simple.pm
CommitLineData
931cbc8d 1package Reaction::UI::Controller::Role::Action::Simple;
2
3use Moose::Role -traits => 'MethodAttributes';
4
5requires 'push_viewport';
6requires 'merge_config_hashes';
7
8has action_viewport_map => (isa => 'HashRef', is => 'rw', lazy_build => 1);
9has action_viewport_args => (isa => 'HashRef', is => 'rw', lazy_build => 1);
10
11sub _build_action_viewport_map { {} }
12
13sub _build_action_viewport_args { {} }
14
15sub setup_viewport {
16 my ($self, $c, $vp_args) = @_;
17 my $action_name = $c->stack->[-1]->name;
90bcd4d7 18 my $vp = $self->action_viewport_map->{$action_name};
931cbc8d 19 my $args = $self->merge_config_hashes(
20 $vp_args || {},
21 $self->action_viewport_args->{$action_name} || {} ,
22 );
23 return $self->push_viewport($vp, %$args);
24}
25
261;
27
28__END__;
29
30=head1 NAME
31
32Reaction::UI::Controller::Role::Action::Simple
33
34=head1 DESCRIPTION
35
36Provides a C<setup_viewport> method, which makes it easier to setup and
37configure a viewport in controller actions.
38
39=head1 SYNOPSYS
40
41 package MyApp::Controller::Foo;
42
43 use base 'Reaction::Controller';
44 use Reaction::Class;
45
46 with 'Reaction::UI::Controller::Role::Action::Simple';
47
48 __PACKAGE__->config(
49 action_viewport_map => { bar => 'Reaction::UI::Viewport::Object' },
50 action_viewport_args => { location => 'custom-location' },
51 );
52
53 sub bar :Local {
54 my($self, $c) = @_;
55 my $obj = $self->get_collection($c)->find( $some_key );
56 $self->setup_viewport($c, { model => $obj });
57 }
58
59=head1 ATTRIBUTES
60
61=head2 action_viewport_map
62
63=over 4
64
65=item B<_build_action_viewport_map> - Returns empty hashref by default.
66
67=item B<has_action_viewport_map> - Auto generated predicate
68
69=item B<clear_action_viewport_map>- Auto generated clearer method
70
71=back
72
73Read-write lazy building hashref. The keys should match action names in the
74Controller and the value should be the ViewPort class that this action should
75use.
76
77=head2 action_viewport_args
78
79Read-write lazy building hashref. Additional ViewPort arguments for the action
80named as the key in the controller.
81
82=over 4
83
84=item B<_build_action_viewport_args> - Returns empty hashref by default.
85
86=item B<has_action_viewport_args> - Auto generated predicate
87
88=item B<clear_action_viewport_args>- Auto generated clearer method
89
90=back
91
92=head1 METHODS
93
94=head2 setup_viewport $c, \%vp_args
95
96Accepts two arguments, context, and a hashref of viewport arguments. It will
97automatically determine the action name using the catalyst stack and call
98C<push_viewport> with the ViewPort class name contained in the
99C<action_viewport_map> with a set of options determined by merging C<$vp_args>
100and the arguments contained in C<action_viewport_args>, if any.
101
102=head1 SEE ALSO
103
104=over4
105
106=item L<Reaction::UI::Controller>
107
108=item L<Reaction::UI::Controller::Role::Action::Simple>
109
110=item L<Reaction::UI::Controller::Role::Action::Object>
111
112=item L<Reaction::UI::Controller::Role::Action::List>
113
114=item L<Reaction::UI::Controller::Role::Action::View>
115
116=item L<Reaction::UI::Controller::Role::Action::Create>
117
118=item L<Reaction::UI::Controller::Role::Action::Update>
119
120=item L<Reaction::UI::Controller::Role::Action::Delete>
121
122=item L<Reaction::UI::Controller::Role::Action::DeleteAll>
123
124=back
125
126=head1 AUTHORS
127
128See L<Reaction::Class> for authors.
129
130=head1 LICENSE
131
132See L<Reaction::Class> for the license.
133
134=cut