File Coverage

blib/lib/Catalyst/ActionContainer.pm
Criterion Covered Total %
statement 18 19 94.7
branch 4 4 100.0
condition 1 3 33.3
subroutine 6 7 85.7
pod 3 3 100.0
total 32 36 88.9


line stmt bran cond sub pod time code
1             package Catalyst::ActionContainer;
2              
3 48     48   701 use strict;
  48         2331  
  48         2498  
4 48     48   1072 use base qw/Class::Accessor::Fast/;
  48         596  
  48         1900  
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 0     0   0     q{""} => sub { shift->{part} },
27              
28 48     48   958 );
  48         463  
  48         1073  
29              
30             sub new {
31 2642     2642 1 51621     my ( $class, $fields ) = @_;
32              
33 2642 100       71565     $fields = { part => $fields, actions => {} } unless ref $fields;
34              
35 2642         78298     $class->SUPER::new($fields);
36             }
37              
38              
39              
40             sub get_action {
41 6202     6202 1 75736     my ( $self, $name ) = @_;
42 6202 100       114973     return $self->actions->{$name} if defined $self->actions->{$name};
43 4256         131150     return;
44             }
45              
46             sub add_action {
47 25048     25048 1 323176     my ( $self, $action, $name ) = @_;
48 25048   33     445277     $name ||= $action->name;
49 25048         444110     $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;
93