[Catalyst-commits] r11859 - in Catalyst-Runtime/5.80/branches/refactoring_dispatcher: lib/Catalyst lib/Catalyst/DispatchType t/lib/TestApp/Action t/lib/TestApp/Controller/Action

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Tue Nov 17 02:42:23 GMT 2009


Author: jnapiorkowski
Date: 2009-11-17 02:42:23 +0000 (Tue, 17 Nov 2009)
New Revision: 11859

Added:
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchArgsRegexp.pm
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchCapturesRegexp.pm
Modified:
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Action.pm
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Path.pm
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Regex.pm
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/ChainedMatchArgs.pm
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/PathMatchArgs.pm
Log:
changed around the match_captures so that the actions are just in test for now and reverted path dispatcher to original

Modified: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Action.pm	2009-11-16 22:29:19 UTC (rev 11858)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Action.pm	2009-11-17 02:42:23 UTC (rev 11859)
@@ -77,32 +77,6 @@
 }
 
 sub match_captures {
-    my ($self, $c) = @_;
-    if(my $match_args = $self->attributes->{MatchArgs}) {
-    	$match_args = join(',', @$match_args); ## incase you have multiple
-        return $self->_compare_args_to_signature($c, $match_args)
-    } else {
-        return 1; ## if no MatchArgs, assume all is well
-    }
-}
-
-## MatchArgs("/d/d","/w/d",...)
-sub _compare_args_to_signature {
-    my ($self, $c, $match_args) = @_;
-    my @incoming_args = @{ $c->req->args };
-    my $splitter = qr/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/;
-    my @parsed_match_args = split($splitter, $match_args);
-    foreach my $arg (@incoming_args) {
-        my $match_arg = shift(@parsed_match_args);
-        $match_arg =~s/^"//;
-        $match_arg =~s/"$//;        
-        $match_arg = qr[$match_arg];
-        if($arg =~ m/^$match_arg$/x) {
-            next;
-        } else {
-            return 0;
-        }
-    }
     return 1;
 }
 

Modified: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Path.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Path.pm	2009-11-16 22:29:19 UTC (rev 11858)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Path.pm	2009-11-17 02:42:23 UTC (rev 11859)
@@ -79,7 +79,7 @@
     my @actions = @{ $self->_paths->{$path} || [] };
 
     foreach my $action ( @actions ) {
-        next unless ($action->match($c) && $action->match_captures($c));
+        next unless ($action->match($c));
         $c->req->action($path);
         $c->req->match($path);
         $c->action($action);

Modified: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Regex.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Regex.pm	2009-11-16 22:29:19 UTC (rev 11858)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Regex.pm	2009-11-17 02:42:23 UTC (rev 11859)
@@ -79,7 +79,8 @@
 
     foreach my $compiled ( @{ $self->_compiled } ) {
         if ( my @captures = ( $path =~ $compiled->{re} ) ) {
-            next unless $compiled->{action}->match($c);
+            my $action = $compiled->{action};
+            next unless ($action->match($c) && $action->match_captures($c));
             $c->req->action( $compiled->{path} );
             $c->req->match($path);
             $c->req->captures( \@captures );

Added: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchArgsRegexp.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchArgsRegexp.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchArgsRegexp.pm	2009-11-17 02:42:23 UTC (rev 11859)
@@ -0,0 +1,42 @@
+package TestApp::Action::MatchArgsRegexp;
+
+use strict;
+use warnings;
+
+use base qw/Catalyst::Action/;
+
+sub match {
+	my $self = shift;
+	if($self->next::method(@_)) {
+		my $c = shift;
+		if(my $match_args = $self->attributes->{MatchArgsRegexp}) {
+			$match_args = join(',', @$match_args);
+			return $self->compare_args_to_signature($c, $match_args);
+		} else {
+			return 1;
+		}
+	}
+}
+
+## MatchArgsRegexp("/d/d","/w/d",...)
+sub compare_args_to_signature {
+    my ($self, $c, $match_args) = @_;
+    my @incoming_args = @{ $c->req->args };
+    my $splitter = qr/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/;
+    my @parsed_match_args = split($splitter, $match_args);
+    foreach my $arg (@incoming_args) {
+        my $match_arg = shift(@parsed_match_args);
+        $match_arg =~s/^"//;
+        $match_arg =~s/"$//;        
+        $match_arg = qr[$match_arg];
+        if($arg =~ m/^$match_arg$/x) {
+            next;
+        } else {
+            return 0;
+        }
+    }
+    return 1;
+}
+
+1;
+

Added: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchCapturesRegexp.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchCapturesRegexp.pm	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Action/MatchCapturesRegexp.pm	2009-11-17 02:42:23 UTC (rev 11859)
@@ -0,0 +1,41 @@
+package TestApp::Action::MatchCapturesRegexp;
+
+use strict;
+use warnings;
+
+use base qw/Catalyst::Action/;
+
+sub match_captures {
+	my $self = shift;
+	if($self->next::method(@_)) {
+		my $c = shift;
+		if(my $match_captures = $self->attributes->{MatchCapturesRegexp}) {
+			$match_captures = join(',', @$match_captures);
+			return $self->compare_captures_to_signature($c, $match_captures)
+		} else {
+			return 1;
+		}
+	}
+}
+
+sub compare_captures_to_signature {
+    my ($self, $c, $match_captures) = @_;
+    my @incoming_args = @{ $c->req->args };
+    my $splitter = qr/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/;
+    my @parsed_match_captures = split($splitter, $match_captures);
+    foreach my $arg (@incoming_args) {
+        my $match_capture = shift(@parsed_match_captures);
+        $match_capture =~s/^"//;
+        $match_capture =~s/"$//;        
+        $match_capture = qr[$match_capture];
+        if($arg =~ m/^$match_capture$/x) {
+            next;
+        } else {
+            return 0;
+        }
+    }
+    return 1;
+}
+
+1;
+

Modified: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/ChainedMatchArgs.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/ChainedMatchArgs.pm	2009-11-16 22:29:19 UTC (rev 11858)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/ChainedMatchArgs.pm	2009-11-17 02:42:23 UTC (rev 11859)
@@ -20,36 +20,40 @@
 }
 
 sub endpoint1
+	:ActionClass('+TestApp::Action::MatchCapturesRegexp')
     :PathPart('end') 
     :Chained('foo')
-    :MatchArgs('\d')
+    :MatchCapturesRegexp('\d')
     :Args(1) {
     	my ($self, $c, @args) = @_;
         $c->forward('TestApp::View::Dump::Request');    
     }
 
 sub endpoint2
+	:ActionClass('+TestApp::Action::MatchCapturesRegexp')
     :PathPart('end') 
     :Chained('foo')
-    :MatchArgs('\d\d')
+    :MatchCapturesRegexp('\d\d')
     :Args(1) {
     	my ($self, $c, @args) = @_;
         $c->forward('TestApp::View::Dump::Request');    
     }
 
 sub endpoint3
+	:ActionClass('+TestApp::Action::MatchCapturesRegexp')
     :PathPart('end') 
     :Chained('foo')
-    :MatchArgs('\d,"\d\d"')
+    :MatchCapturesRegexp('\d,"\d\d"')
     :Args(2) {
     	my ($self, $c, @args) = @_;
         $c->forward('TestApp::View::Dump::Request');    
     }
 
 sub endpoint4
+	:ActionClass('+TestApp::Action::MatchCapturesRegexp')
     :PathPart('end') 
     :Chained('foo')
-    :MatchArgs('\d\d,\d')
+    :MatchCapturesRegexp('\d\d,\d')
     :Args(2) {
     	my ($self, $c, @args) = @_;
         $c->forward('TestApp::View::Dump::Request');    

Modified: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/PathMatchArgs.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/PathMatchArgs.pm	2009-11-16 22:29:19 UTC (rev 11858)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/PathMatchArgs.pm	2009-11-17 02:42:23 UTC (rev 11859)
@@ -1,14 +1,31 @@
 package TestApp::Controller::Action::PathMatchArgs;
 
 use strict;
+use warnings;
+
 use base 'TestApp::Controller::Action';
 
 __PACKAGE__->config(
     actions => {
-      'one' => { 'Path' => 'one', 'Args' => '1', 'MatchArgs' => '\d' },
-      'two' => { 'Path' => 'one', 'Args' => '1', 'MatchArgs' => '\d\d' },
-      'three' => { 'Path' => 'one', 'Args' => '1', 'MatchArgs' => '\d\d\d' },   
-    },
+		'one' => {
+			'Path' => 'one', 
+			'Args' => '1', 
+			'ActionClass' => '+TestApp::Action::MatchArgsRegexp',
+			'MatchArgsRegexp' => '\d',
+		},
+		'two' => {
+			'Path' => 'one', 
+			'Args' => '1', 
+			'ActionClass' => '+TestApp::Action::MatchArgsRegexp',
+			'MatchArgsRegexp' => '\d\d',
+		},
+		'three' => {
+			'Path' => 'one', 
+			'Args' => '1', 
+			'ActionClass' => '+TestApp::Action::MatchArgsRegexp',
+			'MatchArgsRegexp' => '\d\d\d',
+		},   
+	},
 );
 
 sub one : Action {




More information about the Catalyst-commits mailing list