File Coverage

blib/lib/Catalyst/DispatchType/Index.pm
Criterion Covered Total %
statement 21 21 100.0
branch 8 8 100.0
condition 2 3 66.7
subroutine 4 4 100.0
pod 2 2 100.0
total 37 38 97.4


line stmt bran cond sub pod time code
1             package Catalyst::DispatchType::Index;
2              
3 48     48   3229 use strict;
  48         528  
  48         1809  
4 48     48   855 use base qw/Catalyst::DispatchType/;
  48         507  
  48         730  
5              
6             =head1 NAME
7            
8             Catalyst::DispatchType::Index - Index 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             Check if there's an index action for a given path, and set it up to use it
21             if there is; only matches a full URI - if $c->req->args is already set
22             this DispatchType is guaranteed not to match.
23            
24             =cut
25              
26             sub match {
27 1317     1317 1 23207     my ( $self, $c, $path ) = @_;
28 1317 100       16149     return if @{ $c->req->args };
  1317         20806  
29 817         24287     my $result = $c->get_action( 'index', $path );
30              
31 817 100 66     29629     if ($result && $result->match($c)) {
32 20         704         $c->action($result);
33 20         586         $c->namespace( $result->namespace );
34 20         474         $c->req->action('index');
35 20         229         $c->req->match( $c->req->path );
36 20         3313         return 1;
37                 }
38 797         24781     return 0;
39             }
40              
41             =head2 $self->uri_for_action( $action, $captures )
42            
43             get a URI part for an action; always returns undef is $captures is set
44             since index actions don't have captures
45            
46             =cut
47              
48             sub uri_for_action {
49 29     29 1 274     my ( $self, $action, $captures ) = @_;
50              
51 29 100       554     return undef if @$captures;
52              
53 9 100       125     return undef unless $action->name eq 'index';
54              
55 1         15     return "/".$action->namespace;
56             }
57              
58             =head1 AUTHOR
59            
60             Sebastian Riedel, C<sri@cpan.org>
61            
62             =head1 COPYRIGHT
63            
64             This program is free software, you can redistribute it and/or modify it under
65             the same terms as Perl itself.
66            
67             =cut
68              
69             1;
70