File Coverage

blib/lib/Catalyst/DispatchType/Default.pm
Criterion Covered Total %
statement 18 19 94.7
branch 5 6 83.3
condition 2 3 66.6
subroutine 4 4 100.0
pod 1 1 100.0
total 30 33 90.9


line stmt bran cond sub pod time code
1              
2             use Moose;
3 154     154   3672 extends 'Catalyst::DispatchType';
  154         433  
  154         1186  
4              
5             no Moose;
6 154     154   1020915  
  154         451  
  154         846  
7             =head1 NAME
8              
9             Catalyst::DispatchType::Default - Default DispatchType
10              
11             =head1 SYNOPSIS
12              
13             See L<Catalyst::DispatchType>.
14              
15             =head1 DESCRIPTION
16              
17             Dispatch type managing default behaviour. For more information on
18             dispatch types, see:
19              
20             =over 4
21              
22             =item * L<Catalyst::Manual::Intro> for how they affect application authors
23              
24             =item * L<Catalyst::DispatchType> for implementation information.
25              
26             =back
27              
28             =head1 METHODS
29              
30             =head2 $self->match( $c, $path )
31              
32             If path is empty (i.e. all path parts have been converted into args),
33             attempts to find a default for the namespace constructed from the args,
34             or the last inherited default otherwise and will match that.
35              
36             If path is not empty, never matches since Default will only match if all
37             other possibilities have been exhausted.
38              
39             =cut
40              
41             my ( $self, $c, $path ) = @_;
42             return if $path ne ''; # Not at root yet, wait for it ...
43 631     631 1 1714 my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1];
44 631 100       2382  
45 68         432 # Find default on namespace or super
46             if ($result && $result->match($c)) {
47             $c->action($result);
48 68 100 66     612 $c->namespace( $result->namespace );
49 58         1694 $c->req->action('default');
50 58         1607  
51 58         256 # default methods receive the controller name as the first argument
52             unshift @{ $c->req->args }, $path if $path;
53             $c->req->match('');
54 58 50       208 return 1;
  0         0  
55 58         331 }
56 58         317 return 0;
57             }
58 10         53  
59              
60             =head1 AUTHORS
61 2216     2216   4402  
62             Catalyst Contributors, see Catalyst.pm
63              
64             =head1 COPYRIGHT
65              
66             This library is free software. You can redistribute it and/or modify it under
67             the same terms as Perl itself.
68              
69             =cut
70              
71             __PACKAGE__->meta->make_immutable;
72              
73             1;