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