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