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