- Shifted Path dispatch into a DispatchType and nuked old set_action stuff
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Regex.pm
1 package Catalyst::DispatchType::Regex;
2
3 use strict;
4 use base qw/Catalyst::DispatchType::Path/;
5
6 sub prepare_action {
7     my ($self, $c, $path) = @_;
8
9     return if $self->SUPER::prepare_action($c, $path);
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
25 sub 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
40 1;