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