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