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