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 | |
26dc649a |
13 | See L<Catalyst::DispatchType>. |
bcccee4e |
14 | |
15 | =head1 DESCRIPTION |
16 | |
26dc649a |
17 | Dispatch type managing behaviour for index pages. For more information on |
18 | dispatch types, see: |
19 | |
20 | =over 4 |
21 | |
b9b89145 |
22 | =item * L<Catalyst::Manual::Intro> for how they affect application authors |
26dc649a |
23 | |
24 | =item * L<Catalyst::DispatchType> for implementation information. |
25 | |
26 | =back |
27 | |
bcccee4e |
28 | =head1 METHODS |
29 | |
b5ecfcf0 |
30 | =head2 $self->match( $c, $path ) |
bcccee4e |
31 | |
4ab87e27 |
32 | Check if there's an index action for a given path, and set it up to use it |
b2b90ec2 |
33 | if there is; only matches a full URI - if $c->req->args is already set |
34 | this DispatchType is guaranteed not to match. |
4ab87e27 |
35 | |
bcccee4e |
36 | =cut |
37 | |
38 | sub match { |
39 | my ( $self, $c, $path ) = @_; |
bcccee4e |
40 | return if @{ $c->req->args }; |
a9dc674c |
41 | my $result = $c->get_action( 'index', $path ); |
bcccee4e |
42 | |
4082e678 |
43 | if ($result && $result->match($c)) { |
b5ecfcf0 |
44 | $c->action($result); |
a9dc674c |
45 | $c->namespace( $result->namespace ); |
bcccee4e |
46 | $c->req->action('index'); |
47 | $c->req->match( $c->req->path ); |
48 | return 1; |
49 | } |
50 | return 0; |
51 | } |
52 | |
ea0e58d9 |
53 | =head2 $self->uri_for_action( $action, $captures ) |
54 | |
55 | get a URI part for an action; always returns undef is $captures is set |
56 | since index actions don't have captures |
57 | |
58 | =cut |
59 | |
60 | sub uri_for_action { |
61 | my ( $self, $action, $captures ) = @_; |
62 | |
63 | return undef if @$captures; |
64 | |
65 | return undef unless $action->name eq 'index'; |
66 | |
67 | return "/".$action->namespace; |
68 | } |
69 | |
2f381252 |
70 | =head1 AUTHORS |
bcccee4e |
71 | |
2f381252 |
72 | Catalyst Contributors, see Catalyst.pm |
bcccee4e |
73 | |
74 | =head1 COPYRIGHT |
75 | |
536bee89 |
76 | This library is free software. You can redistribute it and/or modify it under |
bcccee4e |
77 | the same terms as Perl itself. |
78 | |
79 | =cut |
80 | |
e5ecd5bc |
81 | __PACKAGE__->meta->make_immutable; |
82 | |
bcccee4e |
83 | 1; |