Cleaned all new classes
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Path.pm
1 package Catalyst::DispatchType::Path;
2
3 use strict;
4 use base qw/Catalyst::DispatchType/;
5
6 =head1 NAME
7
8 Catalyst::DispatchType::Path - Path DispatchType
9
10 =head1 SYNOPSIS
11
12 See L<Catalyst>.
13
14 =head1 DESCRIPTION
15
16 =head1 METHODS
17
18 =over 4
19
20 =item $self->match( $c, $path )
21
22 =cut
23
24 sub match {
25     my ( $self, $c, $path ) = @_;
26
27     if ( my $action = $self->{paths}->{$path} ) {
28         $c->req->action($path);
29         $c->req->match($path);
30         $c->action($action);
31         $c->namespace( $action->prefix );
32         return 1;
33     }
34
35     return 0;
36 }
37
38 =item $self->register( $c, $action )
39
40 =cut
41
42 sub register {
43     my ( $self, $c, $action ) = @_;
44
45     my $attrs = $action->attributes;
46     my @register;
47
48     foreach my $r ( @{ $attrs->{Path} || [] } ) {
49         unless ( $r =~ m!^/! ) {    # It's a relative path
50             $r = $action->prefix . "/$r";
51         }
52         push( @register, $r );
53     }
54
55     if ( $attrs->{Global} || $attrs->{Absolute} ) {
56         push( @register, $action->name );    # Register sub name against root
57     }
58
59     if ( $attrs->{Local} || $attrs->{Relative} ) {
60         push( @register, join( '/', $action->prefix, $action->name ) );
61
62         # Register sub name as a relative path
63     }
64
65     foreach my $r (@register) {
66         $r =~ s!^/!!;
67         $self->{paths}{$r} = $action;
68     }
69 }
70
71 =back
72
73 =head1 AUTHOR
74
75 Matt S Trout
76 Sebastian Riedel, C<sri@cpan.org>
77
78 =head1 COPYRIGHT
79
80 This program is free software, you can redistribute it and/or modify it under
81 the same terms as Perl itself.
82
83 =cut
84
85 1;