Commit | Line | Data |
b96f127f |
1 | package Catalyst::DispatchType::Default; |
2 | |
3 | use strict; |
4 | use base qw/Catalyst::DispatchType/; |
5 | |
2633d7dc |
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 | |
b5ecfcf0 |
18 | =head2 $self->match( $c, $path ) |
2633d7dc |
19 | |
b2b90ec2 |
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. |
4ab87e27 |
26 | |
2633d7dc |
27 | =cut |
28 | |
29 | sub match { |
78d760bb |
30 | my ( $self, $c, $path ) = @_; |
31 | return if $path =~ m!/!; # Not at root yet, wait for it ... |
6112c0f9 |
32 | my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1]; |
78d760bb |
33 | |
34 | # Find default on namespace or super |
4082e678 |
35 | if ($result && $result->match($c)) { |
6112c0f9 |
36 | $c->action($result); |
a9dc674c |
37 | $c->namespace( $result->namespace ); |
b96f127f |
38 | $c->req->action('default'); |
6112c0f9 |
39 | |
7cfcfd27 |
40 | # default methods receive the controller name as the first argument |
6112c0f9 |
41 | unshift @{ $c->req->args }, $path if $path; |
b96f127f |
42 | $c->req->match(''); |
22f3a8dd |
43 | return 1; |
b96f127f |
44 | } |
22f3a8dd |
45 | return 0; |
b96f127f |
46 | } |
47 | |
2633d7dc |
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 | |
b96f127f |
60 | 1; |