fix root default thingie jayk gave me, sanitize Paths at registration time better
[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::DispatchType>.
15
16 =head1 DESCRIPTION
17
18 Dispatch type managing default behaviour.  For more information on
19 dispatch types, see:
20
21 =over 4
22
23 =item * L<Catalyst::Manual::Intro> for how they affect application authors
24
25 =item * L<Catalyst::DispatchType> for implementation information.
26
27 =back
28
29 =head1 METHODS
30
31 =head2 $self->match( $c, $path )
32
33 If path is empty (i.e. all path parts have been converted into args),
34 attempts to find a default for the namespace constructed from the args,
35 or the last inherited default otherwise and will match that.
36
37 If path is not empty, never matches since Default will only match if all
38 other possibilities have been exhausted.
39
40 =cut
41
42 sub match {
43     my ( $self, $c, $path ) = @_;
44     return if $path ne '';    # Not at root yet, wait for it ...
45     my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1];
46
47     # Find default on namespace or super
48     if ($result && $result->match($c)) {
49         $c->action($result);
50         $c->namespace( $result->namespace );
51         $c->req->action('default');
52
53         # default methods receive the controller name as the first argument
54         unshift @{ $c->req->args }, $path if $path;
55         $c->req->match('');
56         return 1;
57     }
58     return 0;
59 }
60
61 =head1 AUTHORS
62
63 Catalyst Contributors, see Catalyst.pm
64
65 =head1 COPYRIGHT
66
67 This library is free software. You can redistribute it and/or modify it under
68 the same terms as Perl itself.
69
70 =cut
71
72 __PACKAGE__->meta->make_immutable;
73
74 1;