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