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