File Coverage

blib/lib/Catalyst/ActionContainer.pm
Criterion Covered Total %
statement 16 16 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 2 2 100.0
total 27 29 93.1


line stmt bran cond sub pod time code
1              
2             =head1 NAME
3              
4             Catalyst::ActionContainer - Catalyst Action Container
5              
6             =head1 SYNOPSIS
7              
8             See L<Catalyst>.
9              
10             =head1 DESCRIPTION
11              
12             This is a container for actions. The dispatcher sets up a tree of these
13             to represent the various dispatch points in your application.
14              
15             =cut
16              
17             use Moose;
18 153     153   4840 with 'MooseX::Emulate::Class::Accessor::Fast';
  153         440  
  153         1177  
19              
20             has part => (is => 'rw', required => 1);
21             has actions => (is => 'rw', required => 1, lazy => 1, default => sub { {} });
22              
23             around BUILDARGS => sub {
24             my ($next, $self, @args) = @_;
25             unshift @args, 'part' if scalar @args == 1 && !ref $args[0];
26             return $self->$next(@args);
27             };
28              
29             no Moose;
30 153     153   883783  
  153         430  
  153         950  
31             use overload (
32             # Stringify to path part for tree search
33             q{""} => sub { shift->part },
34 33     33   873 );
35 153     153   33236  
  153         372  
  153         1553  
36             my ( $self, $name ) = @_;
37             return $self->actions->{$name} if defined $self->actions->{$name};
38 6163     6163 1 9990 return;
39 6163 100       142692 }
40 4634         13117  
41             my ( $self, $action, $name ) = @_;
42             $name ||= $action->name;
43             $self->actions->{$name} = $action;
44 69160     69160 1 112768 }
45 69160   33     1555347  
46 69160         1600107 __PACKAGE__->meta->make_immutable;
47              
48             1;
49              
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 AUTHORS
81              
82             Catalyst Contributors, see Catalyst.pm
83              
84             =head1 COPYRIGHT
85              
86             This library 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;