Create branch register_actions.
[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 AUTHORS
51
52 Catalyst Contributors, see Catalyst.pm
53
54 =head1 COPYRIGHT
55
56 This program is free software, you can redistribute it and/or modify it under
57 the same terms as Perl itself.
58
59 =cut
60
61 __PACKAGE__->meta->make_immutable;
62
63 1;