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