- Restored Regex behaviour and added LocalRegex
Matt S Trout [Sat, 5 Nov 2005 21:16:30 +0000 (21:16 +0000)]
lib/Catalyst/DispatchType/Path.pm
lib/Catalyst/DispatchType/Regex.pm
t/live/lib/TestApp/Controller/Action/Regexp.pm

index c1f1255..cffe66b 100644 (file)
@@ -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
index 313a5c3..411cd4c 100644 (file)
@@ -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
index 8bc04a7..e454cfd 100644 (file)
@@ -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');
 }