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