DispatchTypes' POD refers to Catalyst::Manual::Intro, nominated as the best location...
[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
23=item * L<Catalyst::Manual::Intro> for how they affect website authors
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 ) = @_;
44 return if $path =~ m!/!; # 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
2f381252 61=head1 AUTHORS
2633d7dc 62
2f381252 63Catalyst Contributors, see Catalyst.pm
2633d7dc 64
65=head1 COPYRIGHT
66
67This program is free software, you can redistribute it and/or modify it under
68the same terms as Perl itself.
69
70=cut
71
e5ecd5bc 72__PACKAGE__->meta->make_immutable;
73
b96f127f 741;