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