Fixed default action in appclass
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Regex.pm
CommitLineData
b96f127f 1package Catalyst::DispatchType::Regex;
2
3use strict;
6b239949 4use base qw/Catalyst::DispatchType::Path/;
b96f127f 5
6sub prepare_action {
7 my ($self, $c, $path) = @_;
8
6b239949 9 return if $self->SUPER::prepare_action($c, $path);
22f3a8dd 10 # Check path against plain text first
b96f127f 11
12 foreach my $compiled (@{$self->{compiled}||[]}) {
13 if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
14 $c->req->action($compiled->{path});
15 $c->req->match($path);
16 $c->req->snippets(\@snippets);
17 $c->action($compiled->{action});
18 $c->namespace($compiled->{action}->prefix);
19 return 1;
20 }
21 }
22
23 return 0;
24}
25
26sub register_action {
27 my ( $self, $c, $action ) = @_;
28 my $attrs = $action->attributes;
29 my @register = map { @{$_ || []} } @{$attrs}{'Regex', 'Regexp'};
30 foreach my $r (@register) {
22f3a8dd 31 $self->{paths}{$r} = $action; # Register path for superclass
32 push(@{$self->{compiled}}, # and compiled regex for us
b96f127f 33 {
34 re => qr#$r#,
35 action => $action,
36 path => $r,
37 } );
38 }
39}
40
411;