add C::DispatchType::_is_low_precedence
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Default.pm
CommitLineData
b96f127f 1package Catalyst::DispatchType::Default;
2
3c0186f2 3use Moose;
4extends 'Catalyst::DispatchType';
b96f127f 5
0fc2d522 6no Moose;
e8b9f2a9 7
2633d7dc 8=head1 NAME
9
10Catalyst::DispatchType::Default - Default DispatchType
11
12=head1 SYNOPSIS
13
26dc649a 14See L<Catalyst::DispatchType>.
2633d7dc 15
16=head1 DESCRIPTION
17
26dc649a 18Dispatch type managing default behaviour. For more information on
19dispatch 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 33If path is empty (i.e. all path parts have been converted into args),
34attempts to find a default for the namespace constructed from the args,
35or the last inherited default otherwise and will match that.
36
37If path is not empty, never matches since Default will only match if all
38other possibilities have been exhausted.
4ab87e27 39
2633d7dc 40=cut
41
42sub 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 61sub _is_low_precedence { 1 }
62
2f381252 63=head1 AUTHORS
2633d7dc 64
2f381252 65Catalyst Contributors, see Catalyst.pm
2633d7dc 66
67=head1 COPYRIGHT
68
536bee89 69This library is free software. You can redistribute it and/or modify it under
2633d7dc 70the same terms as Perl itself.
71
72=cut
73
e5ecd5bc 74__PACKAGE__->meta->make_immutable;
75
b96f127f 761;