blob: 95dbfbdc3af35b1999e61f4005dc0fd2a9d12207 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
|