DispatchType stripped of CAF, SUPER and substituted instances of $self->{*} with...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Index.pm
CommitLineData
bcccee4e 1package Catalyst::DispatchType::Index;
2
3c0186f2 3use Moose;
4extends 'Catalyst::DispatchType';
bcccee4e 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
b2b90ec2 21if there is; only matches a full URI - if $c->req->args is already set
22this DispatchType is guaranteed not to match.
4ab87e27 23
bcccee4e 24=cut
25
26sub match {
27 my ( $self, $c, $path ) = @_;
bcccee4e 28 return if @{ $c->req->args };
a9dc674c 29 my $result = $c->get_action( 'index', $path );
bcccee4e 30
4082e678 31 if ($result && $result->match($c)) {
b5ecfcf0 32 $c->action($result);
a9dc674c 33 $c->namespace( $result->namespace );
bcccee4e 34 $c->req->action('index');
35 $c->req->match( $c->req->path );
36 return 1;
37 }
38 return 0;
39}
40
ea0e58d9 41=head2 $self->uri_for_action( $action, $captures )
42
43get a URI part for an action; always returns undef is $captures is set
44since index actions don't have captures
45
46=cut
47
48sub uri_for_action {
49 my ( $self, $action, $captures ) = @_;
50
51 return undef if @$captures;
52
53 return undef unless $action->name eq 'index';
54
55 return "/".$action->namespace;
56}
57
bcccee4e 58=head1 AUTHOR
59
60Sebastian Riedel, C<sri@cpan.org>
61
62=head1 COPYRIGHT
63
64This program is free software, you can redistribute it and/or modify it under
65the same terms as Perl itself.
66
67=cut
68
691;