Changelog and sed s/website authors/application authors/
[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::DispatchType>.
14
15 =head1 DESCRIPTION
16
17 Dispatch type managing behaviour for index pages.  For more information on
18 dispatch types, see:
19
20 =over 4
21
22 =item * L<Catalyst::Manual::Intro> for how they affect application authors
23
24 =item * L<Catalyst::DispatchType> for implementation information.
25
26 =back
27
28 =head1 METHODS
29
30 =head2 $self->match( $c, $path )
31
32 Check if there's an index action for a given path, and set it up to use it
33 if there is; only matches a full URI - if $c->req->args is already set
34 this DispatchType is guaranteed not to match.
35
36 =cut
37
38 sub match {
39     my ( $self, $c, $path ) = @_;
40     return if @{ $c->req->args };
41     my $result = $c->get_action( 'index', $path );
42
43     if ($result && $result->match($c)) {
44         $c->action($result);
45         $c->namespace( $result->namespace );
46         $c->req->action('index');
47         $c->req->match( $c->req->path );
48         return 1;
49     }
50     return 0;
51 }
52
53 =head2 $self->uri_for_action( $action, $captures )
54
55 get a URI part for an action; always returns undef is $captures is set
56 since index actions don't have captures
57
58 =cut
59
60 sub uri_for_action {
61     my ( $self, $action, $captures ) = @_;
62
63     return undef if @$captures;
64
65     return undef unless $action->name eq 'index';
66
67     return "/".$action->namespace;
68 }
69
70 =head1 AUTHORS
71
72 Catalyst Contributors, see Catalyst.pm
73
74 =head1 COPYRIGHT
75
76 This program is free software, you can redistribute it and/or modify it under
77 the same terms as Perl itself.
78
79 =cut
80
81 __PACKAGE__->meta->make_immutable;
82
83 1;