f3cb7e06669bc8f79130bb50fa31d3b25b344e7c
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ActionContainer.pm
1 package Catalyst::ActionContainer;
2
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
18 use Moose;
19
20 has part => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
21 has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
22
23 around new => sub {
24   my ($orig, $self, $params) = @_;
25   $orig->($self, (ref($params) ? $params :  { part => $params } ));
26 };
27
28 no Moose;
29
30 sub get_action {
31     my ( $self, $name ) = @_;
32     return $self->actions->{$name} if defined $self->actions->{$name};
33     return;
34 }
35
36 sub add_action {
37     my ( $self, $action, $name ) = @_;
38     $name ||= $action->name;
39     $self->actions->{$name} = $action;
40 }
41
42 __PACKAGE__->meta->make_immutable;
43
44 1;
45
46 __END__
47
48 =head1 METHODS
49
50 =head2 new(\%data | $part)
51
52 Can be called with { part => $part, actions => \%actions } for full
53 construction or with just a part, which will result in an empty actions
54 hashref to be populated via add_action later
55
56 =head2 get_action($name)
57
58 Returns an action from this container based on the action name, or undef
59
60 =head2 add_action($action, [ $name ])
61
62 Adds an action, optionally providing a name to override $action->name
63
64 =head2 actions
65
66 Accessor to the actions hashref, containing all actions in this container.
67
68 =head2 part
69
70 Accessor to the path part this container resolves to. Also what the container
71 stringifies to.
72
73 =head2 meta
74
75 Provided by Moose
76
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;