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