- Added a bunch of comments to new dispatcher code
[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 sub prepare_action {
7     my ($self, $c, $path) = @_;
8
9     if ( my $action = $self->{paths}->{$path} ) {
10         $c->req->action($path);
11         $c->req->match($path);
12         $c->action($action);
13         $c->namespace($action->prefix);
14         return 1;
15     }
16
17     return 0;
18 }
19
20 sub register_action {
21     my ( $self, $c, $action ) = @_;
22
23     my $attrs = $action->attributes;
24     my @register;
25
26     foreach my $r (@{$attrs->{Path} || []}) {
27         unless ($r =~ m!^/!) {    # It's a relative path
28             $r = $action->prefix."/$r";
29         }
30         push(@register, $r);
31     }
32
33     if ($attrs->{Global} || $attrs->{Absolute}) {
34         push(@register, $action->name); # Register sub name against root
35     }
36
37     if ($attrs->{Local} || $attrs->{Relative}) {
38         push(@register, join('/', $action->prefix, $action->name));
39             # Register sub name as a relative path
40     }
41
42     foreach my $r (@register) {
43         $r =~ s!^/!!;
44         $self->{paths}{$r} = $action;
45     }
46 }
47
48 1;