Commit | Line | Data |
bcccee4e |
1 | package Catalyst::DispatchType::Index; |
2 | |
0fc2d522 |
3 | use Class::C3; |
3c0186f2 |
4 | use Moose; |
5 | extends 'Catalyst::DispatchType'; |
0fc2d522 |
6 | no Moose; |
e8b9f2a9 |
7 | |
bcccee4e |
8 | =head1 NAME |
9 | |
10 | Catalyst::DispatchType::Index - Index DispatchType |
11 | |
12 | =head1 SYNOPSIS |
13 | |
14 | See L<Catalyst>. |
15 | |
16 | =head1 DESCRIPTION |
17 | |
18 | =head1 METHODS |
19 | |
b5ecfcf0 |
20 | =head2 $self->match( $c, $path ) |
bcccee4e |
21 | |
4ab87e27 |
22 | Check if there's an index action for a given path, and set it up to use it |
b2b90ec2 |
23 | if there is; only matches a full URI - if $c->req->args is already set |
24 | this DispatchType is guaranteed not to match. |
4ab87e27 |
25 | |
bcccee4e |
26 | =cut |
27 | |
28 | sub 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 | |
45 | get a URI part for an action; always returns undef is $captures is set |
46 | since index actions don't have captures |
47 | |
48 | =cut |
49 | |
50 | sub 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 | |
62 | Sebastian Riedel, C<sri@cpan.org> |
63 | |
64 | =head1 COPYRIGHT |
65 | |
66 | This program is free software, you can redistribute it and/or modify it under |
67 | the same terms as Perl itself. |
68 | |
69 | =cut |
70 | |
e5ecd5bc |
71 | __PACKAGE__->meta->make_immutable; |
72 | |
bcccee4e |
73 | 1; |