From: Matt S Trout Date: Thu, 22 Jun 2006 14:53:49 +0000 (+0000) Subject: Chained: test and err handling for absolute path parts; test for recursive chains X-Git-Tag: 5.7099_04~476 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=8a6a6581d48a3c1c4d5f631cdb7cbda336c0e5e2 Chained: test and err handling for absolute path parts; test for recursive chains r10154@cain (orig r4432): phaylon | 2006-06-21 19:29:36 +0000 --- diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index b236aa4..1d7783b 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -202,6 +202,12 @@ sub register { ); } + if ($part =~ m(^/)) { + Catalyst::Exception->throw( + "Absolute parameters to PathPart not allowed registering ${action}" + ); + } + $action->attributes->{PartPath} = [ $part ]; unshift(@{ $children->{$part} ||= [] }, $action); diff --git a/t/lib/TestAppChainedAbsolutePathPart.pm b/t/lib/TestAppChainedAbsolutePathPart.pm new file mode 100644 index 0000000..6ffd047 --- /dev/null +++ b/t/lib/TestAppChainedAbsolutePathPart.pm @@ -0,0 +1,20 @@ +package TestAppChainedAbsolutePathPart; + +use strict; +use Catalyst qw/ + Test::Errors + Test::Headers +/; +use Catalyst::Utils; + +our $VERSION = '0.01'; + +TestAppChainedAbsolutePathPart + ->config( + name => 'TestAppChainedAbsolutePathPart', + root => '/some/dir' + ); + +TestAppChainedAbsolutePathPart->setup; + +1; diff --git a/t/lib/TestAppChainedAbsolutePathPart/Controller/Foo.pm b/t/lib/TestAppChainedAbsolutePathPart/Controller/Foo.pm new file mode 100644 index 0000000..bbf222d --- /dev/null +++ b/t/lib/TestAppChainedAbsolutePathPart/Controller/Foo.pm @@ -0,0 +1,10 @@ +package TestAppChainedAbsolutePathPart::Controller::Foo; + +use strict; +use warnings; + +use base qw/Catalyst::Controller/; + +sub foo : Chained PathPart('/foo/bar') Args(1) { } + +1; diff --git a/t/lib/TestAppChainedRecursive.pm b/t/lib/TestAppChainedRecursive.pm new file mode 100644 index 0000000..7d28cab --- /dev/null +++ b/t/lib/TestAppChainedRecursive.pm @@ -0,0 +1,19 @@ +package TestAppChainedRecursive; + +use strict; +use Catalyst qw/ + Test::Errors + Test::Headers +/; +use Catalyst::Utils; + +our $VERSION = '0.01'; + +TestAppChainedRecursive->config( + name => 'TestAppChainedRecursive', + root => '/some/dir' +); + +TestAppChainedRecursive->setup; + +1; diff --git a/t/lib/TestAppChainedRecursive/Controller/Foo.pm b/t/lib/TestAppChainedRecursive/Controller/Foo.pm new file mode 100644 index 0000000..36358d2 --- /dev/null +++ b/t/lib/TestAppChainedRecursive/Controller/Foo.pm @@ -0,0 +1,11 @@ +package TestAppChainedRecursive::Controller::Foo; + +use strict; +use warnings; + +use base qw/Catalyst::Controller/; + +sub foo : Chained('bar') CaptureArgs(1) { } +sub bar : Chained('foo') CaptureArgs(1) { } + +1; diff --git a/t/live_component_controller_action_chained.t b/t/live_component_controller_action_chained.t index b9367a2..ee50214 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 => 99*$iters; +use Test::More tests => 101*$iters; use Catalyst::Test 'TestApp'; if ( $ENV{CAT_BENCHMARK} ) { @@ -19,11 +19,12 @@ if ( $ENV{CAT_BENCHMARK} ) { } else { for ( 1 .. $iters ) { - run_tests(); + run_tests($_); } } sub run_tests { + my ($run_number) = @_; # # This is a simple test where the parent and child actions are @@ -688,4 +689,26 @@ sub run_tests { $expected, 'Executed actions' ); is( $response->content, '1; 2', 'Content OK' ); } + + # + # Test interception of recursive chains. This test was added because at + # one point during the :Chained development, Catalyst used to hang on + # recursive chains. + # + { + eval { require 'TestAppChainedRecursive.pm' }; + pass( "Interception of recursive chains" ); + } + + # + # Test failure of absolute path part arguments. + # + { + eval { require 'TestAppChainedAbsolutePathPart.pm' }; + if ($run_number == 1) { + like( $@, qr(foo/foo), + "Usage of absolute path part argument emits error" ); + } + else { pass( "Error on absolute path part arguments already tested" ) } + } }