- Shifted Path dispatch into a DispatchType and nuked old set_action stuff
[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);
b96f127f 10
11 foreach my $compiled (@{$self->{compiled}||[]}) {
12 if ( my @snippets = ( $path =~ $compiled->{re} ) ) {
13 $c->req->action($compiled->{path});
14 $c->req->match($path);
15 $c->req->snippets(\@snippets);
16 $c->action($compiled->{action});
17 $c->namespace($compiled->{action}->prefix);
18 return 1;
19 }
20 }
21
22 return 0;
23}
24
25sub register_action {
26 my ( $self, $c, $action ) = @_;
27 my $attrs = $action->attributes;
28 my @register = map { @{$_ || []} } @{$attrs}{'Regex', 'Regexp'};
29 foreach my $r (@register) {
30 $self->{paths}{$r} = $action;
31 push(@{$self->{compiled}},
32 {
33 re => qr#$r#,
34 action => $action,
35 path => $r,
36 } );
37 }
38}
39
401;