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 153     153   2882 extends 'Catalyst::DispatchType';
  153         376  
  153         958  
4              
5             no Moose;
6 153     153   828827  
  153         489  
  153         722  
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 1432 my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1];
44 631 100       1986  
45 68         296 # Find default on namespace or super
46             if ($result && $result->match($c)) {
47             $c->action($result);
48 68 100 66     572 $c->namespace( $result->namespace );
49 58         1335 $c->req->action('default');
50 58         1366  
51 58         286 # 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       155 return 1;
  0         0  
55 58         155 }
56 58         241 return 0;
57             }
58 10         40  
59              
60             =head1 AUTHORS
61 2216     2216   3920  
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;