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 | |
26dc649a |
14 | See L<Catalyst::DispatchType>. |
2633d7dc |
15 | |
16 | =head1 DESCRIPTION |
17 | |
26dc649a |
18 | Dispatch type managing default behaviour. For more information on |
19 | dispatch types, see: |
20 | |
21 | =over 4 |
22 | |
b9b89145 |
23 | =item * L<Catalyst::Manual::Intro> for how they affect application authors |
26dc649a |
24 | |
25 | =item * L<Catalyst::DispatchType> for implementation information. |
26 | |
27 | =back |
28 | |
2633d7dc |
29 | =head1 METHODS |
30 | |
b5ecfcf0 |
31 | =head2 $self->match( $c, $path ) |
2633d7dc |
32 | |
b2b90ec2 |
33 | If path is empty (i.e. all path parts have been converted into args), |
34 | attempts to find a default for the namespace constructed from the args, |
35 | or the last inherited default otherwise and will match that. |
36 | |
37 | If path is not empty, never matches since Default will only match if all |
38 | other possibilities have been exhausted. |
4ab87e27 |
39 | |
2633d7dc |
40 | =cut |
41 | |
42 | sub match { |
78d760bb |
43 | my ( $self, $c, $path ) = @_; |
5299fff8 |
44 | return if $path ne ''; # Not at root yet, wait for it ... |
6112c0f9 |
45 | my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1]; |
78d760bb |
46 | |
47 | # Find default on namespace or super |
4082e678 |
48 | if ($result && $result->match($c)) { |
6112c0f9 |
49 | $c->action($result); |
a9dc674c |
50 | $c->namespace( $result->namespace ); |
b96f127f |
51 | $c->req->action('default'); |
6112c0f9 |
52 | |
7cfcfd27 |
53 | # default methods receive the controller name as the first argument |
6112c0f9 |
54 | unshift @{ $c->req->args }, $path if $path; |
b96f127f |
55 | $c->req->match(''); |
22f3a8dd |
56 | return 1; |
b96f127f |
57 | } |
22f3a8dd |
58 | return 0; |
b96f127f |
59 | } |
60 | |
c4586fd0 |
61 | sub _is_low_precedence { 1 } |
62 | |
2f381252 |
63 | =head1 AUTHORS |
2633d7dc |
64 | |
2f381252 |
65 | Catalyst Contributors, see Catalyst.pm |
2633d7dc |
66 | |
67 | =head1 COPYRIGHT |
68 | |
536bee89 |
69 | This library is free software. You can redistribute it and/or modify it under |
2633d7dc |
70 | the same terms as Perl itself. |
71 | |
72 | =cut |
73 | |
e5ecd5bc |
74 | __PACKAGE__->meta->make_immutable; |
75 | |
b96f127f |
76 | 1; |