Commit | Line | Data |
cfd04b0c |
1 | package Catalyst::ActionContainer; |
2 | |
b2ddf6d7 |
3 | =head1 NAME |
4 | |
5 | Catalyst::ActionContainer - Catalyst Action Container |
6 | |
7 | =head1 SYNOPSIS |
8 | |
9 | See L<Catalyst>. |
10 | |
11 | =head1 DESCRIPTION |
12 | |
13 | This is a container for actions. The dispatcher sets up a tree of these |
14 | to represent the various dispatch points in your application. |
15 | |
16 | =cut |
17 | |
0fc2d522 |
18 | use Class::C3; |
059c085b |
19 | use Moose; |
cfd04b0c |
20 | |
7f602cac |
21 | use overload ( |
22 | |
23 | # Stringify to path part for tree search |
24 | q{""} => sub { shift->part }, |
25 | |
26 | ); |
27 | |
5fb12dbb |
28 | has part => (is => 'rw', required => 1, lazy => 1, default => sub { {} }); |
059c085b |
29 | has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} }); |
a13e21ab |
30 | |
0fc2d522 |
31 | no Moose; |
32 | |
33 | sub new { |
059c085b |
34 | my ($self, $params) = @_; |
35 | $params = { part => $params } unless ref $params; |
0fc2d522 |
36 | $self->next::method($params); |
37 | } |
cfd04b0c |
38 | |
cfd04b0c |
39 | |
b2ddf6d7 |
40 | sub get_action { |
41 | my ( $self, $name ) = @_; |
42 | return $self->actions->{$name} if defined $self->actions->{$name}; |
43 | return; |
44 | } |
cfd04b0c |
45 | |
b2ddf6d7 |
46 | sub add_action { |
47 | my ( $self, $action, $name ) = @_; |
48 | $name ||= $action->name; |
49 | $self->actions->{$name} = $action; |
50 | } |
cfd04b0c |
51 | |
e5ecd5bc |
52 | __PACKAGE__->meta->make_immutable; |
53 | |
b2ddf6d7 |
54 | 1; |
cfd04b0c |
55 | |
b2ddf6d7 |
56 | __END__ |
649fd1fa |
57 | |
cfd04b0c |
58 | =head1 METHODS |
59 | |
d4c74714 |
60 | =head2 new(\%data | $part) |
61 | |
62 | Can be called with { part => $part, actions => \%actions } for full |
63 | construction or with just a part, which will result in an empty actions |
64 | hashref to be populated via add_action later |
65 | |
649fd1fa |
66 | =head2 get_action($name) |
67 | |
68 | Returns an action from this container based on the action name, or undef |
79a3189a |
69 | |
a13e21ab |
70 | =head2 add_action($action, [ $name ]) |
71 | |
72 | Adds an action, optionally providing a name to override $action->name |
73 | |
b5ecfcf0 |
74 | =head2 actions |
79a3189a |
75 | |
649fd1fa |
76 | Accessor to the actions hashref, containing all actions in this container. |
77 | |
b5ecfcf0 |
78 | =head2 part |
cfd04b0c |
79 | |
649fd1fa |
80 | Accessor to the path part this container resolves to. Also what the container |
81 | stringifies to. |
82 | |
059c085b |
83 | =head2 meta |
84 | |
85 | Provided by Moose |
86 | |
cfd04b0c |
87 | =head1 AUTHOR |
88 | |
e5ecd5bc |
89 | Matt S. Trout |
cfd04b0c |
90 | |
91 | =head1 COPYRIGHT |
92 | |
93 | This program is free software, you can redistribute it and/or modify it under |
94 | the same terms as Perl itself. |
95 | |
96 | =cut |
97 | |
98 | 1; |