Chained: test and err handling for absolute path parts; test for recursive chains
Matt S Trout [Thu, 22 Jun 2006 14:53:49 +0000 (14:53 +0000)]
r10154@cain (orig r4432):  phaylon | 2006-06-21 19:29:36 +0000

lib/Catalyst/DispatchType/Chained.pm
t/lib/TestAppChainedAbsolutePathPart.pm [new file with mode: 0644]
t/lib/TestAppChainedAbsolutePathPart/Controller/Foo.pm [new file with mode: 0644]
t/lib/TestAppChainedRecursive.pm [new file with mode: 0644]
t/lib/TestAppChainedRecursive/Controller/Foo.pm [new file with mode: 0644]
t/live_component_controller_action_chained.t

index b236aa4..1d7783b 100644 (file)
@@ -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 (file)
index 0000000..6ffd047
--- /dev/null
@@ -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 (file)
index 0000000..bbf222d
--- /dev/null
@@ -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 (file)
index 0000000..7d28cab
--- /dev/null
@@ -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 (file)
index 0000000..36358d2
--- /dev/null
@@ -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;
index b9367a2..ee50214 100644 (file)
@@ -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" ) }
+    }
 }