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