refactored to leave synopsis to the top, and move the rest of the pod to the
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ActionContainer.pm
1 package Catalyst::ActionContainer;
2
3 use strict;
4 use base qw/Class::Accessor::Fast/;
5
6 =head1 NAME
7
8 Catalyst::ActionContainer - Catalyst Action Container
9
10 =head1 SYNOPSIS
11
12 See L<Catalyst>.
13
14 =head1 DESCRIPTION
15
16 This is a container for actions. The dispatcher sets up a tree of these
17 to represent the various dispatch points in your application.
18
19 =cut
20
21 __PACKAGE__->mk_accessors(qw/part actions/);
22
23 use overload (
24
25     # Stringify to path part for tree search
26     q{""} => sub { shift->{part} },
27
28 );
29
30 sub new {
31     my ( $class, $fields ) = @_;
32
33     $fields = { part => $fields, actions => {} } unless ref $fields;
34
35     $class->SUPER::new($fields);
36 }
37
38
39
40 sub get_action {
41     my ( $self, $name ) = @_;
42     return $self->actions->{$name} if defined $self->actions->{$name};
43     return;
44 }
45
46 sub add_action {
47     my ( $self, $action, $name ) = @_;
48     $name ||= $action->name;
49     $self->actions->{$name} = $action;
50 }
51
52 1;
53
54 __END__
55
56 =head1 METHODS
57
58 =head2 new(\%data | $part)
59
60 Can be called with { part => $part, actions => \%actions } for full
61 construction or with just a part, which will result in an empty actions
62 hashref to be populated via add_action later
63
64 =head2 get_action($name)
65
66 Returns an action from this container based on the action name, or undef
67
68 =head2 add_action($action, [ $name ])
69
70 Adds an action, optionally providing a name to override $action->name
71
72 =head2 actions
73
74 Accessor to the actions hashref, containing all actions in this container.
75
76 =head2 part
77
78 Accessor to the path part this container resolves to. Also what the container
79 stringifies to.
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;