- Shifted Path dispatch into a DispatchType and nuked old set_action stuff
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Path.pm
CommitLineData
6b239949 1package Catalyst::DispatchType::Path;
2
3use strict;
4use base qw/Catalyst::DispatchType/;
5
6sub 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
20sub register_action {
21 my ( $self, $c, $action ) = @_;
22 my $attrs = $action->attributes;
23 my @register;
24 foreach my $r (@{$attrs->{Path} || []}) {
25 unless ($r =~ m!^/!) {
26 $r = $action->prefix."/$r";
27 }
28 push(@register, $r);
29 }
30
31 if ($attrs->{Global} || $attrs->{Absolute}) {
32 push(@register, $action->name);
33 }
34
35 if ($attrs->{Local} || $attrs->{Relative}) {
36 push(@register, join('/', $action->prefix, $action->name));
37 }
38
39 foreach my $r (@register) {
40 $r =~ s!^/!!;
41 $self->{paths}{$r} = $action;
42 }
43}
44
451;