610e0a4c7f36ace1bf84e2712f6a0103e31e11c8
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Index.pm
1 package Catalyst::DispatchType::Index;
2
3 use Moose;
4 extends 'Catalyst::DispatchType';
5 no Moose;
6
7 =head1 NAME
8
9 Catalyst::DispatchType::Index - Index DispatchType
10
11 =head1 SYNOPSIS
12
13 See L<Catalyst>.
14
15 =head1 DESCRIPTION
16
17 =head1 METHODS
18
19 =head2 $self->match( $c, $path )
20
21 Check if there's an index action for a given path, and set it up to use it
22 if there is; only matches a full URI - if $c->req->args is already set
23 this DispatchType is guaranteed not to match.
24
25 =cut
26
27 sub match {
28     my ( $self, $c, $path ) = @_;
29     return if @{ $c->req->args };
30     my $result = $c->get_action( 'index', $path );
31
32     if ($result && $result->match($c)) {
33         $c->action($result);
34         $c->namespace( $result->namespace );
35         $c->req->action('index');
36         $c->req->match( $c->req->path );
37         return 1;
38     }
39     return 0;
40 }
41
42 =head2 $self->uri_for_action( $action, $captures )
43
44 get a URI part for an action; always returns undef is $captures is set
45 since index actions don't have captures
46
47 =cut
48
49 sub uri_for_action {
50     my ( $self, $action, $captures ) = @_;
51
52     return undef if @$captures;
53
54     return undef unless $action->name eq 'index';
55
56     return "/".$action->namespace;
57 }
58
59 =head1 AUTHORS
60
61 Catalyst Contributors, see Catalyst.pm
62
63 =head1 COPYRIGHT
64
65 This program is free software, you can redistribute it and/or modify it under
66 the same terms as Perl itself.
67
68 =cut
69
70 __PACKAGE__->meta->make_immutable;
71
72 1;