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