Commit | Line | Data |
bcccee4e |
1 | package Catalyst::DispatchType::Index; |
2 | |
3c0186f2 |
3 | use Moose; |
4 | extends 'Catalyst::DispatchType'; |
1315d253 |
5 | use namespace::clean -except => 'meta'; |
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 | |
1315d253 |
28 | =cut |
29 | |
30 | has _actions => ( |
31 | is => 'rw', isa => 'HashRef', default => sub { +{} } |
32 | ); |
33 | |
bcccee4e |
34 | =head1 METHODS |
35 | |
b5ecfcf0 |
36 | =head2 $self->match( $c, $path ) |
bcccee4e |
37 | |
4ab87e27 |
38 | Check if there's an index action for a given path, and set it up to use it |
b2b90ec2 |
39 | if there is; only matches a full URI - if $c->req->args is already set |
40 | this DispatchType is guaranteed not to match. |
4ab87e27 |
41 | |
bcccee4e |
42 | =cut |
43 | |
44 | sub match { |
45 | my ( $self, $c, $path ) = @_; |
bcccee4e |
46 | return if @{ $c->req->args }; |
a9dc674c |
47 | my $result = $c->get_action( 'index', $path ); |
bcccee4e |
48 | |
1315d253 |
49 | return 0 unless $result && exists $self->_actions->{ $result->reverse }; |
50 | |
4082e678 |
51 | if ($result && $result->match($c)) { |
b5ecfcf0 |
52 | $c->action($result); |
a9dc674c |
53 | $c->namespace( $result->namespace ); |
bcccee4e |
54 | $c->req->action('index'); |
55 | $c->req->match( $c->req->path ); |
56 | return 1; |
57 | } |
58 | return 0; |
59 | } |
60 | |
1315d253 |
61 | =head2 $self->register( $c, $action ) |
62 | |
63 | Register an action with this DispatchType. |
64 | |
65 | =cut |
66 | |
67 | sub register { |
68 | my ( $self, $c, $action ) = @_; |
69 | |
76cd735d |
70 | $self->_actions->{ $action->reverse } = $action if $action->name eq 'index'; |
1315d253 |
71 | |
72 | return 1; |
73 | } |
74 | |
ea0e58d9 |
75 | =head2 $self->uri_for_action( $action, $captures ) |
76 | |
77 | get a URI part for an action; always returns undef is $captures is set |
78 | since index actions don't have captures |
79 | |
80 | =cut |
81 | |
82 | sub uri_for_action { |
83 | my ( $self, $action, $captures ) = @_; |
84 | |
85 | return undef if @$captures; |
86 | |
76cd735d |
87 | return undef unless exists $self->_actions->{ $action->reverse }; |
ea0e58d9 |
88 | |
89 | return "/".$action->namespace; |
90 | } |
91 | |
c4586fd0 |
92 | sub _is_low_precedence { 1 } |
93 | |
2f381252 |
94 | =head1 AUTHORS |
bcccee4e |
95 | |
2f381252 |
96 | Catalyst Contributors, see Catalyst.pm |
bcccee4e |
97 | |
98 | =head1 COPYRIGHT |
99 | |
536bee89 |
100 | This library is free software. You can redistribute it and/or modify it under |
bcccee4e |
101 | the same terms as Perl itself. |
102 | |
103 | =cut |
104 | |
e5ecd5bc |
105 | __PACKAGE__->meta->make_immutable; |
106 | |
bcccee4e |
107 | 1; |