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