- Fixes for rt.cpan #17322 and #17331
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Default.pm
1 package Catalyst::DispatchType::Default;
2
3 use strict;
4 use base qw/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 =cut
21
22 sub match {
23     my ( $self, $c, $path ) = @_;
24     return if $path =~ m!/!;    # Not at root yet, wait for it ...
25     my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1];
26
27     # Find default on namespace or super
28     if ($result) {
29         $c->action($result);
30         $c->namespace( $result->namespace );
31         $c->req->action('default');
32
33         # default methods receive the controller name as the first argument
34         unshift @{ $c->req->args }, $path if $path;
35         $c->req->match('');
36         return 1;
37     }
38     return 0;
39 }
40
41 =head1 AUTHOR
42
43 Matt S Trout
44 Sebastian Riedel, C<sri@cpan.org>
45
46 =head1 COPYRIGHT
47
48 This program is free software, you can redistribute it and/or modify it under
49 the same terms as Perl itself.
50
51 =cut
52
53 1;