Commit | Line | Data |
6b239949 |
1 | package Catalyst::DispatchType::Path; |
2 | |
3 | use strict; |
4 | use base qw/Catalyst::DispatchType/; |
5 | |
2633d7dc |
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 ) = @_; |
6b239949 |
26 | |
27 | if ( my $action = $self->{paths}->{$path} ) { |
28 | $c->req->action($path); |
29 | $c->req->match($path); |
30 | $c->action($action); |
2633d7dc |
31 | $c->namespace( $action->prefix ); |
6b239949 |
32 | return 1; |
33 | } |
34 | |
35 | return 0; |
36 | } |
37 | |
2633d7dc |
38 | =item $self->register( $c, $action ) |
39 | |
40 | =cut |
41 | |
42 | sub register { |
6b239949 |
43 | my ( $self, $c, $action ) = @_; |
22f3a8dd |
44 | |
6b239949 |
45 | my $attrs = $action->attributes; |
46 | my @register; |
22f3a8dd |
47 | |
2633d7dc |
48 | foreach my $r ( @{ $attrs->{Path} || [] } ) { |
49 | unless ( $r =~ m!^/! ) { # It's a relative path |
50 | $r = $action->prefix . "/$r"; |
6b239949 |
51 | } |
2633d7dc |
52 | push( @register, $r ); |
6b239949 |
53 | } |
54 | |
2633d7dc |
55 | if ( $attrs->{Global} || $attrs->{Absolute} ) { |
56 | push( @register, $action->name ); # Register sub name against root |
6b239949 |
57 | } |
58 | |
2633d7dc |
59 | if ( $attrs->{Local} || $attrs->{Relative} ) { |
60 | push( @register, join( '/', $action->prefix, $action->name ) ); |
61 | |
62 | # Register sub name as a relative path |
6b239949 |
63 | } |
64 | |
65 | foreach my $r (@register) { |
66 | $r =~ s!^/!!; |
67 | $self->{paths}{$r} = $action; |
68 | } |
69 | } |
70 | |
2633d7dc |
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 | |
6b239949 |
85 | 1; |