File Coverage

blib/lib/Catalyst/DispatchType/Default.pm
Criterion Covered Total %
statement 18 18 100.0
branch 5 6 83.3
condition 2 3 66.7
subroutine 3 3 100.0
pod 1 1 100.0
total 29 31 93.5


line stmt bran cond sub pod time code
1             package Catalyst::DispatchType::Default;
2              
3 48     48   805 use strict;
  48         1719  
  48         761  
4 48     48   752 use base qw/Catalyst::DispatchType/;
  48         524  
  48         979  
5              
6             =head1 NAME
7            
8             Catalyst::DispatchType::Default - Default DispatchType
9            
10             =head1 SYNOPSIS
11            
12             See L<Catalyst>.
13            
14             =head1 DESCRIPTION
15            
16             =head1 METHODS
17            
18             =head2 $self->match( $c, $path )
19            
20             If path is empty (i.e. all path parts have been converted into args),
21             attempts to find a default for the namespace constructed from the args,
22             or the last inherited default otherwise and will match that.
23            
24             If path is not empty, never matches since Default will only match if all
25             other possibilities have been exhausted.
26            
27             =cut
28              
29             sub match {
30 553     553 1 6444     my ( $self, $c, $path ) = @_;
31 553 100       12371     return if $path =~ m!/!; # Not at root yet, wait for it ...
32 65         3894     my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1];
33              
34             # Find default on namespace or super
35 65 100 66     907     if ($result && $result->match($c)) {
36 41         1772         $c->action($result);
37 41         1674         $c->namespace( $result->namespace );
38 41         586         $c->req->action('default');
39              
40             # default methods receive the controller name as the first argument
41 41 50       486         unshift @{ $c->req->args }, $path if $path;
  41         650  
42 41         545         $c->req->match('');
43 41         674         return 1;
44                 }
45 24         329     return 0;
46             }
47              
48             =head1 AUTHOR
49            
50             Matt S Trout
51             Sebastian Riedel, C<sri@cpan.org>
52            
53             =head1 COPYRIGHT
54            
55             This program is free software, you can redistribute it and/or modify it under
56             the same terms as Perl itself.
57            
58             =cut
59              
60             1;
61