mro compat stuff
[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 MRO::Compat;
19 use mro 'c3';
20 use Moose;
21
22 has part => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
23 has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
24
25 no Moose;
26
27 sub new {
28   my ($self, $params) = @_;
29   $params = { part => $params } unless ref $params;
30   $self->next::method($params);
31 }
32
33
34 sub get_action {
35     my ( $self, $name ) = @_;
36     return $self->actions->{$name} if defined $self->actions->{$name};
37     return;
38 }
39
40 sub add_action {
41     my ( $self, $action, $name ) = @_;
42     $name ||= $action->name;
43     $self->actions->{$name} = $action;
44 }
45
46 __PACKAGE__->meta->make_immutable;
47
48 1;
49
50 __END__
51
52 =head1 METHODS
53
54 =head2 new(\%data | $part)
55
56 Can be called with { part => $part, actions => \%actions } for full
57 construction or with just a part, which will result in an empty actions
58 hashref to be populated via add_action later
59
60 =head2 get_action($name)
61
62 Returns an action from this container based on the action name, or undef
63
64 =head2 add_action($action, [ $name ])
65
66 Adds an action, optionally providing a name to override $action->name
67
68 =head2 actions
69
70 Accessor to the actions hashref, containing all actions in this container.
71
72 =head2 part
73
74 Accessor to the path part this container resolves to. Also what the container
75 stringifies to.
76
77 =head2 meta
78
79 Provided by Moose
80
81 =head1 AUTHOR
82
83 Matt S. Trout
84
85 =head1 COPYRIGHT
86
87 This program is free software, you can redistribute it and/or modify it under
88 the same terms as Perl itself.
89
90 =cut
91
92 1;