rename test test
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ActionContainer.pm
1 package Catalyst::ActionContainer;
2
3 =head1 NAME
4
5 Catalyst::ActionContainer - Catalyst Action Container
6
7 =head1 SYNOPSIS
8
9 See L<Catalyst>.
10
11 =head1 DESCRIPTION
12
13 This is a container for actions. The dispatcher sets up a tree of these
14 to represent the various dispatch points in your application.
15
16 =cut
17
18 use Moose;
19
20 has part => (is => 'rw', required => 1);
21 has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
22
23 around new => sub {
24   my ($orig, $self, $params) = @_;
25   $orig->($self, (ref($params) ? $params :  { part => $params } ));
26 };
27
28 no Moose;
29
30 use overload (
31     # Stringify to path part for tree search
32     q{""} => sub { shift->part },
33 );
34
35 sub get_action {
36     my ( $self, $name ) = @_;
37     return $self->actions->{$name} if defined $self->actions->{$name};
38     return;
39 }
40
41 sub add_action {
42     my ( $self, $action, $name ) = @_;
43     $name ||= $action->name;
44     $self->actions->{$name} = $action;
45 }
46
47 __PACKAGE__->meta->make_immutable;
48
49 1;
50
51 __END__
52
53 =head1 METHODS
54
55 =head2 new(\%data | $part)
56
57 Can be called with { part => $part, actions => \%actions } for full
58 construction or with just a part, which will result in an empty actions
59 hashref to be populated via add_action later
60
61 =head2 get_action($name)
62
63 Returns an action from this container based on the action name, or undef
64
65 =head2 add_action($action, [ $name ])
66
67 Adds an action, optionally providing a name to override $action->name
68
69 =head2 actions
70
71 Accessor to the actions hashref, containing all actions in this container.
72
73 =head2 part
74
75 Accessor to the path part this container resolves to. Also what the container
76 stringifies to.
77
78 =head2 meta
79
80 Provided by Moose
81
82 =head1 AUTHORS
83
84 Catalyst Contributors, see Catalyst.pm
85
86 =head1 COPYRIGHT
87
88 This program is free software, you can redistribute it and/or modify it under
89 the same terms as Perl itself.
90
91 =cut
92
93 1;