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