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