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