From: Matt S Trout Date: Thu, 14 Sep 2006 22:29:04 +0000 (+0000) Subject: fixup for Chained and CaptureArgs X-Git-Tag: 5.7099_04~350 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=f505df49a4707ce6962d8a9ebcf5280430a801cf fixup for Chained and CaptureArgs --- diff --git a/Changes b/Changes index ab05edf..82fbefa 100644 --- 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 diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 10342b9..d55d22d 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -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 diff --git a/t/lib/TestApp/Controller/Action/Chained.pm b/t/lib/TestApp/Controller/Action/Chained.pm index dba0d5d..e89b8e0 100644 --- a/t/lib/TestApp/Controller/Action/Chained.pm +++ b/t/lib/TestApp/Controller/Action/Chained.pm @@ -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}; diff --git a/t/live_component_controller_action_chained.t b/t/live_component_controller_action_chained.t index 0ed19c7..e903391 100644 --- a/t/live_component_controller_action_chained.t +++ b/t/live_component_controller_action_chained.t @@ -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' ); + } + }