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