Refreshing branch
[catagits/Catalyst-Runtime.git] / trunk / lib / Catalyst / DispatchType / Index.pm
CommitLineData
ceae39c5 1package Catalyst::DispatchType::Index;
2
3use Moose;
4extends 'Catalyst::DispatchType';
5use namespace::clean -except => 'meta';
6
7=head1 NAME
8
9Catalyst::DispatchType::Index - Index DispatchType
10
11=head1 SYNOPSIS
12
13See L<Catalyst::DispatchType>.
14
15=head1 DESCRIPTION
16
17Dispatch type managing behaviour for index pages. For more information on
18dispatch types, see:
19
20=over 4
21
22=item * L<Catalyst::Manual::Intro> for how they affect application authors
23
24=item * L<Catalyst::DispatchType> for implementation information.
25
26=back
27
28=cut
29
30has _actions => (
31 is => 'rw', isa => 'HashRef', default => sub { +{} }
32);
33
34=head1 METHODS
35
36=head2 $self->match( $c, $path )
37
38Check if there's an index action for a given path, and set it up to use it
39if there is; only matches a full URI - if $c->req->args is already set
40this DispatchType is guaranteed not to match.
41
42=cut
43
44sub match {
45 my ( $self, $c, $path ) = @_;
46 return if @{ $c->req->args };
47 my $result = $c->get_action( 'index', $path );
48
49 return 0 unless $result && exists $self->_actions->{ $result->reverse };
50
51 if ($result && $result->match($c)) {
52 $c->action($result);
53 $c->namespace( $result->namespace );
54 $c->req->action('index');
55 $c->req->match( $c->req->path );
56 return 1;
57 }
58 return 0;
59}
60
61=head2 $self->register( $c, $action )
62
63Register an action with this DispatchType.
64
65=cut
66
67sub register {
68 my ( $self, $c, $action ) = @_;
69
70 $self->_actions->{ $action->reverse } = $action;
71
72 return 1;
73}
74
75=head2 $self->uri_for_action( $action, $captures )
76
77get a URI part for an action; always returns undef is $captures is set
78since index actions don't have captures
79
80=cut
81
82sub uri_for_action {
83 my ( $self, $action, $captures ) = @_;
84
85 return undef if @$captures;
86
87 return undef unless $action->name eq 'index';
88
89 return "/".$action->namespace;
90}
91
92sub _is_low_precedence { 1 }
93
94=head1 AUTHORS
95
96Catalyst Contributors, see Catalyst.pm
97
98=head1 COPYRIGHT
99
100This library is free software. You can redistribute it and/or modify it under
101the same terms as Perl itself.
102
103=cut
104
105__PACKAGE__->meta->make_immutable;
106
1071;