Added index action and fixed get_action
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Index.pm
1 package Catalyst::DispatchType::Index;
2
3 use strict;
4 use base qw/Catalyst::DispatchType/;
5
6 =head1 NAME
7
8 Catalyst::DispatchType::Index - Index DispatchType
9
10 =head1 SYNOPSIS
11
12 See L<Catalyst>.
13
14 =head1 DESCRIPTION
15
16 =head1 METHODS
17
18 =over 4
19
20 =item $self->match( $c, $path )
21
22 =cut
23
24 sub match {
25     my ( $self, $c, $path ) = @_;
26     return if $path =~ m!/!;
27     return if @{ $c->req->args };
28     my $result = @{ $c->get_action( 'index', $c->req->path ) || [] }[-1];
29
30     # Find default on namespace or super
31     if ($result) {
32         $c->action( $result->[0] );
33         $c->namespace( $c->req->path );
34         $c->req->action('index');
35         $c->req->match( $c->req->path );
36         return 1;
37     }
38     return 0;
39 }
40
41 =back
42
43 =head1 AUTHOR
44
45 Sebastian Riedel, C<sri@cpan.org>
46
47 =head1 COPYRIGHT
48
49 This program is free software, you can redistribute it and/or modify it under
50 the same terms as Perl itself.
51
52 =cut
53
54 1;