rename test test
[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
059c085b 18use Moose;
cfd04b0c 19
b8ea7be4 20has part => (is => 'rw', required => 1);
059c085b 21has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
a13e21ab 22
4090e3bb 23around new => sub {
24 my ($orig, $self, $params) = @_;
25 $orig->($self, (ref($params) ? $params : { part => $params } ));
26};
cfd04b0c 27
4090e3bb 28no Moose;
cfd04b0c 29
9b73c5e7 30use overload (
31 # Stringify to path part for tree search
32 q{""} => sub { shift->part },
33);
34
b2ddf6d7 35sub get_action {
36 my ( $self, $name ) = @_;
37 return $self->actions->{$name} if defined $self->actions->{$name};
38 return;
39}
cfd04b0c 40
b2ddf6d7 41sub add_action {
42 my ( $self, $action, $name ) = @_;
43 $name ||= $action->name;
44 $self->actions->{$name} = $action;
45}
cfd04b0c 46
e5ecd5bc 47__PACKAGE__->meta->make_immutable;
48
b2ddf6d7 491;
cfd04b0c 50
b2ddf6d7 51__END__
649fd1fa 52
cfd04b0c 53=head1 METHODS
54
d4c74714 55=head2 new(\%data | $part)
56
57Can be called with { part => $part, actions => \%actions } for full
58construction or with just a part, which will result in an empty actions
59hashref to be populated via add_action later
60
649fd1fa 61=head2 get_action($name)
62
63Returns an action from this container based on the action name, or undef
79a3189a 64
a13e21ab 65=head2 add_action($action, [ $name ])
66
67Adds an action, optionally providing a name to override $action->name
68
b5ecfcf0 69=head2 actions
79a3189a 70
649fd1fa 71Accessor to the actions hashref, containing all actions in this container.
72
b5ecfcf0 73=head2 part
cfd04b0c 74
649fd1fa 75Accessor to the path part this container resolves to. Also what the container
76stringifies to.
77
059c085b 78=head2 meta
79
80Provided by Moose
81
2f381252 82=head1 AUTHORS
cfd04b0c 83
2f381252 84Catalyst Contributors, see Catalyst.pm
cfd04b0c 85
86=head1 COPYRIGHT
87
88This program is free software, you can redistribute it and/or modify it under
89the same terms as Perl itself.
90
91=cut
92
931;