fixup for Chained and CaptureArgs
Matt S Trout [Thu, 14 Sep 2006 22:29:04 +0000 (22:29 +0000)]
Changes
lib/Catalyst/DispatchType/Chained.pm
t/lib/TestApp/Controller/Action/Chained.pm
t/live_component_controller_action_chained.t

diff --git a/Changes b/Changes
index ab05edf..82fbefa 100644 (file)
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@ This file documents the revision history for Perl extension Catalyst.
         - unescape captures to match args
         - fix for relative Chained under namespace '' (root)
         - fix for hashrefs in action attributes from config
+        - fix for Chained to require correct number of CaptureArgs
 
 5.7001   2006-07-19 23:46:54
         - fix for component loading
index 10342b9..d55d22d 100644 (file)
@@ -141,6 +141,10 @@ sub recurse_match {
         my @try_actions = @{$children->{$try_part}};
         TRY_ACTION: foreach my $action (@try_actions) {
             if (my $capture_attr = $action->attributes->{CaptureArgs}) {
+
+                # Short-circuit if not enough remaining parts
+                next TRY_ACTION unless @parts >= $capture_attr->[0];
+
                 my @captures;
                 my @parts = @parts; # localise
 
index dba0d5d..e89b8e0 100644 (file)
@@ -151,6 +151,13 @@ sub empty_chain_d : Chained('empty_chain_c') PathPart('')              CaptureAr
 sub empty_chain_e : Chained('empty_chain_d') PathPart('')              CaptureArgs(0) { }
 sub empty_chain_f : Chained('empty_chain_e') PathPart('')              Args(1)        { }
 
+sub mult_nopp_base  : Chained('/') PathPart('chained/mult_nopp') CaptureArgs(0) { }
+sub mult_nopp_all   : Chained('mult_nopp_base') PathPart('') Args(0) { }
+sub mult_nopp_new   : Chained('mult_nopp_base') PathPart('new') Args(0) { }
+sub mult_nopp_id    : Chained('mult_nopp_base') PathPart('') CaptureArgs(1) { }
+sub mult_nopp_idall : Chained('mult_nopp_id') PathPart('') Args(0) { }
+sub mult_nopp_idnew : Chained('mult_nopp_id') PathPart('new') Args(0) { }
+
 sub end :Private {
   my ($self, $c) = @_;
   return if $c->stash->{no_end};
index 0ed19c7..e903391 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
 
-use Test::More tests => 103*$iters;
+use Test::More tests => 106*$iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -727,4 +727,25 @@ sub run_tests {
         }
         else { pass( "Error on absolute path part arguments already tested" ) }
     }
+
+    #
+    #   Complex path with multiple empty pathparts
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Chained->begin
+          TestApp::Controller::Action::Chained->mult_nopp_base
+          TestApp::Controller::Action::Chained->mult_nopp_all
+          TestApp::Controller::Action::Chained->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/chained/mult_nopp'),
+            "Complex path with multiple empty pathparts" );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '; ', 'Content OK' );
+    }
+
 }