[Catalyst-commits] r11772 - in Catalyst-Runtime/5.80/branches/refactoring_dispatcher: lib/Catalyst lib/Catalyst/DispatchType t/aggregate t/lib/Catalyst/Plugin/Test t/lib/TestApp/Controller/Action

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Thu Nov 5 04:20:38 GMT 2009


Author: jnapiorkowski
Date: 2009-11-05 04:20:36 +0000 (Thu, 05 Nov 2009)
New Revision: 11772

Added:
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_chain_matchargs.t
   Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_path_matchargs.t
   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
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/t/lib/Catalyst/Plugin/Test/Headers.pm
Log:
first seeemingly working version of MatchArgs for Path and Chained.

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-05 02:10:25 UTC (rev 11771)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/Action.pm	2009-11-05 04:20:36 UTC (rev 11772)
@@ -79,6 +79,7 @@
 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
@@ -90,10 +91,13 @@
     my ($self, $c, $match_args) = @_;
     my @incoming_args = @{ $c->req->args };
     my $splitter = qr/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/;
-    my @parsed_match_args = map {qr/$_/} split($splitter, $match_args);
+    my @parsed_match_args = split($splitter, $match_args);
     foreach my $arg (@incoming_args) {
         my $match_arg = shift(@parsed_match_args);
-        if($arg =~ $match_arg) {
+        $match_arg =~s/^"//;
+        $match_arg =~s/"$//;        
+        $match_arg = qr[$match_arg];
+        if($arg =~ m/^$match_arg$/x) {
             next;
         } else {
             return 0;

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-05 02:10:25 UTC (rev 11771)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/lib/Catalyst/DispatchType/Path.pm	2009-11-05 04:20:36 UTC (rev 11772)
@@ -79,8 +79,7 @@
     my @actions = @{ $self->_paths->{$path} || [] };
 
     foreach my $action ( @actions ) {
-        next unless $action->match($c);
-        next unless $action->match_captures($c);
+        next unless ($action->match($c) && $action->match_captures($c));
         $c->req->action($path);
         $c->req->match($path);
         $c->action($action);

Added: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_chain_matchargs.t
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_chain_matchargs.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_chain_matchargs.t	2009-11-05 04:20:36 UTC (rev 11772)
@@ -0,0 +1,83 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+our $iters;
+
+BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
+
+use Test::More tests => 16*$iters;
+use Catalyst::Test 'TestApp';
+
+if ( $ENV{CAT_BENCHMARK} ) {
+    require Benchmark;
+    Benchmark::timethis( $iters, \&run_tests );
+}
+else {
+    for ( 1 .. $iters ) {
+        run_tests();
+    }
+}
+
+sub run_tests {
+    {
+        ok(
+            my $response =
+              request('http://localhost/action/chainedmatchargs/1/end/2'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action-Private'),
+            'action/chainedmatchargs/endpoint1',
+            'Test Action'
+        );
+    }
+    {
+        ok(
+            my $response =
+              request('http://localhost/action/chainedmatchargs/1/end/22'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action-Private'),
+            'action/chainedmatchargs/endpoint2',
+            'Test Action'
+        );
+    }
+    {
+        ok(
+            my $response =
+              request('http://localhost/action/chainedmatchargs/1/end/2/33'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action-Private'),
+            'action/chainedmatchargs/endpoint3',
+            'Test Action'
+        );
+    }
+    {
+        ok(
+            my $response =
+              request('http://localhost/action/chainedmatchargs/1/end/22/3'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action-Private'),
+            'action/chainedmatchargs/endpoint4',
+            'Test Action'
+        );
+    }
+}

Added: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_path_matchargs.t
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_path_matchargs.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/aggregate/live_component_controller_action_path_matchargs.t	2009-11-05 04:20:36 UTC (rev 11772)
@@ -0,0 +1,99 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+our $iters;
+
+BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
+
+use Test::More tests => 18*$iters;
+use Catalyst::Test 'TestApp';
+
+if ( $ENV{CAT_BENCHMARK} ) {
+    require Benchmark;
+    Benchmark::timethis( $iters, \&run_tests );
+}
+else {
+    for ( 1 .. $iters ) {
+        run_tests();
+    }
+}
+
+sub run_tests {
+    {
+        ok(
+            my $response =
+              request('http://localhost/action/pathmatchargs/one/1'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action-Private'),
+            'action/pathmatchargs/one',
+            'Test Action'
+        );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::PathMatchArgs',
+            'Test Class'
+        );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
+    {
+        ok(
+            my $response =
+              request('http://localhost/action/pathmatchargs/one/11'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action-Private'),
+            'action/pathmatchargs/two',
+            'Test Action'
+        );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::PathMatchArgs',
+            'Test Class'
+        );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
+    {
+        ok(
+            my $response =
+              request('http://localhost/action/pathmatchargs/one/111'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action-Private'),
+            'action/pathmatchargs/three',
+            'Test Action'
+        );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::PathMatchArgs',
+            'Test Class'
+        );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
+}

Modified: Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/Catalyst/Plugin/Test/Headers.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/Catalyst/Plugin/Test/Headers.pm	2009-11-05 02:10:25 UTC (rev 11771)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/Catalyst/Plugin/Test/Headers.pm	2009-11-05 04:20:36 UTC (rev 11772)
@@ -29,6 +29,7 @@
     my $c = shift;
     $c->next::method(@_);
     $c->res->header( 'X-Catalyst-Action' => $c->req->action );
+    $c->res->header( 'X-Catalyst-Action-Private' => $c->action );
 }
 
 1;

Added: 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	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/ChainedMatchArgs.pm	2009-11-05 04:20:36 UTC (rev 11772)
@@ -0,0 +1,57 @@
+package TestApp::Controller::Action::ChainedMatchArgs;
+
+use strict;
+use warnings;
+
+use HTML::Entities;
+
+use base qw/Catalyst::Controller/;
+
+sub begin :Private { }
+
+
+sub foo
+    :PathPrefix
+    :CaptureArgs(1)
+    :Chained('/') {
+        my ( $self, $c, @args ) = @_;
+        die "missing argument" unless @args;
+        die "more than 1 argument" if @args > 1;
+}
+
+sub endpoint1
+    :PathPart('end') 
+    :Chained('foo')
+    :MatchArgs('\d')
+    :Args(1) {
+    	my ($self, $c, @args) = @_;
+        $c->forward('TestApp::View::Dump::Request');    
+    }
+
+sub endpoint2
+    :PathPart('end') 
+    :Chained('foo')
+    :MatchArgs('\d\d')
+    :Args(1) {
+    	my ($self, $c, @args) = @_;
+        $c->forward('TestApp::View::Dump::Request');    
+    }
+
+sub endpoint3
+    :PathPart('end') 
+    :Chained('foo')
+    :MatchArgs('\d,"\d\d"')
+    :Args(2) {
+    	my ($self, $c, @args) = @_;
+        $c->forward('TestApp::View::Dump::Request');    
+    }
+
+sub endpoint4
+    :PathPart('end') 
+    :Chained('foo')
+    :MatchArgs('\d\d,\d')
+    :Args(2) {
+    	my ($self, $c, @args) = @_;
+        $c->forward('TestApp::View::Dump::Request');    
+    }
+1;

Added: 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	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/refactoring_dispatcher/t/lib/TestApp/Controller/Action/PathMatchArgs.pm	2009-11-05 04:20:36 UTC (rev 11772)
@@ -0,0 +1,29 @@
+package TestApp::Controller::Action::PathMatchArgs;
+
+use strict;
+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' },   
+    },
+);
+
+sub one : Action {
+    my ( $self, $c, $arg ) = @_;
+    $c->forward('TestApp::View::Dump::Request');
+}
+
+sub two : Action {
+    my ( $self, $c, @args ) = @_;
+    $c->forward('TestApp::View::Dump::Request');
+}
+
+sub three : Action {
+    my ( $self, $c, @args ) = @_;
+    $c->forward('TestApp::View::Dump::Request');
+}
+
+1;




More information about the Catalyst-commits mailing list