From: Matt S Trout Date: Sat, 5 Nov 2005 21:16:30 +0000 (+0000) Subject: - Restored Regex behaviour and added LocalRegex X-Git-Tag: 5.7099_04~1012 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=081def36ee509794aa7b30768c699b16636cee33 - Restored Regex behaviour and added LocalRegex --- diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index c1f1255..cffe66b 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -81,10 +81,17 @@ sub register { # Register sub name as a relative path } - foreach my $r (@register) { - $r =~ s!^/!!; - $self->{paths}{$r} = $action; - } + $self->register_path($c, $_, $action) for @register; +} + +=item $self->register_path($c, $path, $action) + +=cut + +sub register_path { + my ($self, $c, $path, $action) = @_; + $path =~ s!^/!!; + $self->{paths}{$path} = $action; } =back diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index 313a5c3..411cd4c 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -67,22 +67,35 @@ sub register { my ( $self, $c, $action ) = @_; my $attrs = $action->attributes; my @register = map { @{ $_ || [] } } @{$attrs}{ 'Regex', 'Regexp' }; + foreach + my $r ( map { @{ $_ || [] } } @{$attrs}{ 'LocalRegex', 'LocalRegexp' } ) + { + unless ( $r =~ s/^\^// ) { $r = "(?:.*?)$r"; } + push( @register, '^' . $action->namespace . '/' . $r ); + } + foreach my $r (@register) { - unless ( $r =~ /^\^/ ) { # Relative regex - $r = '^' . $action->namespace . '/' . $r; - } - $self->{paths}{$r} = $action; # Register path for superclass - push( - @{ $self->{compiled} }, # and compiled regex for us - { - re => qr#$r#, - action => $action, - path => $r, - } - ); + $self->register_path( $c, $r, $action ); + $self->register_regex( $c, $r, $action ); } } +=item $self->register_regex($c, $re, $action) + +=cut + +sub register_regex { + my ( $self, $c, $re, $action ) = @_; + push( + @{ $self->{compiled} }, # and compiled regex for us + { + re => qr#$re#, + action => $action, + path => $re, + } + ); +} + =back =head1 AUTHOR diff --git a/t/live/lib/TestApp/Controller/Action/Regexp.pm b/t/live/lib/TestApp/Controller/Action/Regexp.pm index 8bc04a7..e454cfd 100644 --- a/t/live/lib/TestApp/Controller/Action/Regexp.pm +++ b/t/live/lib/TestApp/Controller/Action/Regexp.pm @@ -8,7 +8,7 @@ sub one : Action Regex('^action/regexp/(\w+)/(\d+)$') { $c->forward('TestApp::View::Dump::Request'); } -sub two : Action Regexp('(\d+)/(\w+)$') { +sub two : Action LocalRegexp('^(\d+)/(\w+)$') { my ( $self, $c ) = @_; $c->forward('TestApp::View::Dump::Request'); }