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