Commit | Line | Data |
cfd04b0c |
1 | package Catalyst::ActionContainer; |
2 | |
3 | use strict; |
4 | use base qw/Class::Accessor::Fast/; |
5 | |
b2ddf6d7 |
6 | =head1 NAME |
7 | |
8 | Catalyst::ActionContainer - Catalyst Action Container |
9 | |
10 | =head1 SYNOPSIS |
11 | |
12 | See L<Catalyst>. |
13 | |
14 | =head1 DESCRIPTION |
15 | |
16 | This is a container for actions. The dispatcher sets up a tree of these |
17 | to represent the various dispatch points in your application. |
18 | |
19 | =cut |
20 | |
cfd04b0c |
21 | __PACKAGE__->mk_accessors(qw/part actions/); |
22 | |
23 | use overload ( |
24 | |
25 | # Stringify to path part for tree search |
26 | q{""} => sub { shift->{part} }, |
27 | |
28 | ); |
29 | |
a13e21ab |
30 | sub new { |
31 | my ( $class, $fields ) = @_; |
32 | |
33 | $fields = { part => $fields, actions => {} } unless ref $fields; |
34 | |
35 | $class->SUPER::new($fields); |
36 | } |
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 | |
b2ddf6d7 |
52 | 1; |
cfd04b0c |
53 | |
b2ddf6d7 |
54 | __END__ |
649fd1fa |
55 | |
cfd04b0c |
56 | =head1 METHODS |
57 | |
d4c74714 |
58 | =head2 new(\%data | $part) |
59 | |
60 | Can be called with { part => $part, actions => \%actions } for full |
61 | construction or with just a part, which will result in an empty actions |
62 | hashref to be populated via add_action later |
63 | |
649fd1fa |
64 | =head2 get_action($name) |
65 | |
66 | Returns an action from this container based on the action name, or undef |
79a3189a |
67 | |
a13e21ab |
68 | =head2 add_action($action, [ $name ]) |
69 | |
70 | Adds an action, optionally providing a name to override $action->name |
71 | |
b5ecfcf0 |
72 | =head2 actions |
79a3189a |
73 | |
649fd1fa |
74 | Accessor to the actions hashref, containing all actions in this container. |
75 | |
b5ecfcf0 |
76 | =head2 part |
cfd04b0c |
77 | |
649fd1fa |
78 | Accessor to the path part this container resolves to. Also what the container |
79 | stringifies to. |
80 | |
cfd04b0c |
81 | =head1 AUTHOR |
82 | |
b2ddf6d7 |
83 | Matt S. Trout |
cfd04b0c |
84 | |
85 | =head1 COPYRIGHT |
86 | |
87 | This program is free software, you can redistribute it and/or modify it under |
88 | the same terms as Perl itself. |
89 | |
90 | =cut |
91 | |
92 | 1; |