r31712@martha (orig r1247): groditi | 2009-10-02 17:02:01 -0400
[catagits/Reaction.git] / lib / Reaction / UI / Controller / Role / Action / List.pm
1 package Reaction::UI::Controller::Role::Action::List;
2
3 use Moose::Role -traits => 'MethodAttributes';
4 use Reaction::UI::ViewPort::Collection;
5
6 requires qw/get_collection setup_viewport/;
7
8 sub list :Action :Args(0) {
9   my ($self, $c) = @_;
10   my $collection = $c->stash->{collection} || $self->get_collection($c);
11   $self->setup_viewport($c, { collection => $collection });
12 }
13
14 around _build_action_viewport_map => sub {
15   my $orig = shift;
16   my $map = shift->$orig( @_ );
17   $map->{list} = 'Reaction::UI::ViewPort::Collection';
18   return $map;
19 };
20
21 1;
22
23 __END__;
24
25 =head1 NAME
26
27 Reaction::UI::Controller::Role::Action::List - List action
28
29 =head1 DESCRIPTION
30
31 Provides a C<list> action, which sets up an L<Collection Viewport|Reaction::UI::Viewport::Collection>
32 using the collection contained in the C<collection> slot of the stash, if
33 present, or using the object returned by the method C<get_collection>.
34
35 =head1 SYNOPSYS
36
37     package MyApp::Controller::Foo;
38
39     use base 'Reaction::Controller';
40     use Reaction::Class;
41
42     with(
43       'Reaction::UI::Controller::Role::GetCollection',
44       'Reaction::UI::Controller::Role::Action::Simple',
45       'Reaction::UI::Controller::Role::Action::List'
46     );
47
48
49     __PACKAGE__->config( action => {
50       list => { Chained => 'base' },
51     } );
52
53     sub base :Chained('/base') :CaptureArgs(0) {
54       ...
55     }
56
57 =head1 ROLES CONSUMED
58
59 This role also consumes the following roles:
60
61 =over4
62
63 =item L<Reaction::UI::Controller::Role::Action::Simple>
64
65 =back
66
67 =head1 REQUIRED METHODS
68
69 The following methods must be provided by the consuming class:
70
71 =over4
72
73 =item C<get_collection>
74
75 =back
76
77 =head1 ACTIONS
78
79 =head2 list
80
81 Chain endpoint with no args, sets up the viewport with the appropriate action.
82
83 =head1 METHODS
84
85 =head2 _build_action_viewport_map
86
87 Extends to set the C<list> key in the map to L<Reaction::UI::ViewPort::Action>
88
89 =head1 SEE ALSO
90
91 =over4
92
93 =item L<Reaction::UI::Controller>
94
95 =item L<Reaction::UI::Controller::Role::GetCollection>
96
97 =item L<Reaction::UI::Controller::Role::Action::Simple>
98
99 =item L<Reaction::UI::Controller::Role::Action::View>
100
101 =item L<Reaction::UI::Controller::Role::Action::Object>
102
103 =item L<Reaction::UI::Controller::Role::Action::Create>
104
105 =item L<Reaction::UI::Controller::Role::Action::Update>
106
107 =item L<Reaction::UI::Controller::Role::Action::Delete>
108
109 =item L<Reaction::UI::Controller::Role::Action::DeleteAll>
110
111 =back
112
113 =head1 AUTHORS
114
115 See L<Reaction::Class> for authors.
116
117 =head1 LICENSE
118
119 See L<Reaction::Class> for the license.
120
121 =cut