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