Simplify dispatcher guts to use hashes
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ActionContainer.pm
CommitLineData
cfd04b0c 1package Catalyst::ActionContainer;
2
3use strict;
4use base qw/Class::Accessor::Fast/;
5
6__PACKAGE__->mk_accessors(qw/part actions/);
7
8use overload (
9
10 # Stringify to path part for tree search
11 q{""} => sub { shift->{part} },
12
13);
14
a13e21ab 15sub new {
16 my ( $class, $fields ) = @_;
17
18 $fields = { part => $fields, actions => {} } unless ref $fields;
19
20 $class->SUPER::new($fields);
21}
22
cfd04b0c 23=head1 NAME
24
aa6283e4 25Catalyst::ActionContainer - Catalyst Action Container
cfd04b0c 26
27=head1 SYNOPSIS
28
29See L<Catalyst>.
30
31=head1 DESCRIPTION
32
649fd1fa 33This is a container for actions. The dispatcher sets up a tree of these
34to represent the various dispatch points in your application.
35
cfd04b0c 36=head1 METHODS
37
649fd1fa 38=head2 get_action($name)
39
40Returns an action from this container based on the action name, or undef
79a3189a 41
42=cut
43
44sub get_action {
bcd1002b 45 my ( $self, $name ) = @_;
79a3189a 46 return $self->actions->{$name} if defined $self->actions->{$name};
47 return;
48}
cfd04b0c 49
a13e21ab 50=head2 add_action($action, [ $name ])
51
52Adds an action, optionally providing a name to override $action->name
53
54=cut
55
56sub add_action {
57 my ( $self, $action, $name ) = @_;
58 my $name ||= $action->name;
59 $self->actions->{$name} = $action;
60}
61
b5ecfcf0 62=head2 actions
79a3189a 63
649fd1fa 64Accessor to the actions hashref, containing all actions in this container.
65
b5ecfcf0 66=head2 part
cfd04b0c 67
649fd1fa 68Accessor to the path part this container resolves to. Also what the container
69stringifies to.
70
cfd04b0c 71=head1 AUTHOR
72
73Matt S. Trout
74
75=head1 COPYRIGHT
76
77This program is free software, you can redistribute it and/or modify it under
78the same terms as Perl itself.
79
80=cut
81
821;