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