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