Commit | Line | Data |
b96f127f |
1 | package Catalyst::DispatchType::Default; |
2 | |
3c0186f2 |
3 | use Moose; |
4 | extends 'Catalyst::DispatchType'; |
b96f127f |
5 | |
e8b9f2a9 |
6 | |
7 | #use strict; |
8 | #use base qw/Catalyst::DispatchType/; |
9 | |
2633d7dc |
10 | =head1 NAME |
11 | |
12 | Catalyst::DispatchType::Default - Default DispatchType |
13 | |
14 | =head1 SYNOPSIS |
15 | |
16 | See L<Catalyst>. |
17 | |
18 | =head1 DESCRIPTION |
19 | |
20 | =head1 METHODS |
21 | |
b5ecfcf0 |
22 | =head2 $self->match( $c, $path ) |
2633d7dc |
23 | |
b2b90ec2 |
24 | If path is empty (i.e. all path parts have been converted into args), |
25 | attempts to find a default for the namespace constructed from the args, |
26 | or the last inherited default otherwise and will match that. |
27 | |
28 | If path is not empty, never matches since Default will only match if all |
29 | other possibilities have been exhausted. |
4ab87e27 |
30 | |
2633d7dc |
31 | =cut |
32 | |
33 | sub match { |
78d760bb |
34 | my ( $self, $c, $path ) = @_; |
35 | return if $path =~ m!/!; # Not at root yet, wait for it ... |
6112c0f9 |
36 | my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1]; |
78d760bb |
37 | |
38 | # Find default on namespace or super |
4082e678 |
39 | if ($result && $result->match($c)) { |
6112c0f9 |
40 | $c->action($result); |
a9dc674c |
41 | $c->namespace( $result->namespace ); |
b96f127f |
42 | $c->req->action('default'); |
6112c0f9 |
43 | |
7cfcfd27 |
44 | # default methods receive the controller name as the first argument |
6112c0f9 |
45 | unshift @{ $c->req->args }, $path if $path; |
b96f127f |
46 | $c->req->match(''); |
22f3a8dd |
47 | return 1; |
b96f127f |
48 | } |
22f3a8dd |
49 | return 0; |
b96f127f |
50 | } |
51 | |
2633d7dc |
52 | =head1 AUTHOR |
53 | |
54 | Matt S Trout |
55 | Sebastian Riedel, C<sri@cpan.org> |
56 | |
57 | =head1 COPYRIGHT |
58 | |
59 | This program is free software, you can redistribute it and/or modify it under |
60 | the same terms as Perl itself. |
61 | |
62 | =cut |
63 | |
6680c772 |
64 | no Moose; |
e5ecd5bc |
65 | __PACKAGE__->meta->make_immutable; |
66 | |
b96f127f |
67 | 1; |