Fixed default action in appclass
[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 ) = @_;
22f3a8dd 22
6b239949 23 my $attrs = $action->attributes;
24 my @register;
22f3a8dd 25
6b239949 26 foreach my $r (@{$attrs->{Path} || []}) {
22f3a8dd 27 unless ($r =~ m!^/!) { # It's a relative path
6b239949 28 $r = $action->prefix."/$r";
29 }
30 push(@register, $r);
31 }
32
33 if ($attrs->{Global} || $attrs->{Absolute}) {
22f3a8dd 34 push(@register, $action->name); # Register sub name against root
6b239949 35 }
36
37 if ($attrs->{Local} || $attrs->{Relative}) {
38 push(@register, join('/', $action->prefix, $action->name));
22f3a8dd 39 # Register sub name as a relative path
6b239949 40 }
41
42 foreach my $r (@register) {
43 $r =~ s!^/!!;
44 $self->{paths}{$r} = $action;
45 }
46}
47
481;