From: Matt S Trout Date: Sun, 12 Mar 2006 00:39:49 +0000 (+0000) Subject: Looping and recursion tests plus a fix X-Git-Tag: 5.7099_04~673 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=1627551a60fe1e220d390a565f793dea27cd36a6 Looping and recursion tests plus a fix --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index e093ddb..203f1c4 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -971,19 +971,22 @@ sub execute { $class = $c->component($class) || $class; $c->state(0); + if ($c->depth >= $RECURSION) { + my $action = "$code"; + $action = "/$action" unless $action =~ /\-\>/; + my $error = qq/Deep recursion detected calling "$action"/; + $c->log->error($error); + $c->error($error); + $c->state(0); + return $c->state; + } + + if ( $c->debug ) { my $action = "$code"; $action = "/$action" unless $action =~ /\-\>/; $c->counter->{"$code"}++; - if ( $c->counter->{"$code"} > $RECURSION ) { - my $error = qq/Deep recursion detected in "$action"/; - $c->log->error($error); - $c->error($error); - $c->state(0); - return $c->state; - } - # determine if the call was the result of a forward # this is done by walking up the call stack and looking for a calling # sub of Catalyst::forward before the eval diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index 00cde9a..cdb9d6e 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -55,11 +55,24 @@ sub execute { return $c->SUPER::execute(@_); } -sub class_forward_test_method { +sub class_forward_test_method :Private { my ( $self, $c ) = @_; $c->response->headers->header( 'X-Class-Forward-Test-Method' => 1 ); } +sub loop_test : Local { + my ( $self, $c ) = @_; + + for( 1..1001 ) { + $c->forward( 'class_forward_test_method' ); + } +} + +sub recursion_test : Local { + my ( $self, $c ) = @_; + $c->forward( 'recursion_test' ); +} + { no warnings 'redefine'; sub Catalyst::Log::error { } diff --git a/t/live_loop.t b/t/live_loop.t new file mode 100644 index 0000000..23f2ad2 --- /dev/null +++ b/t/live_loop.t @@ -0,0 +1,14 @@ +#!perl + +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/lib"; + +use Test::More tests => 3; +use Catalyst::Test 'TestApp'; + +ok( my $response = request('http://localhost/loop_test'), 'Request' ); +ok( $response->is_success, 'Response Successful 2xx' ); +ok( $response->header('X-Class-Forward-Test-Method'), 'Loop OK' ); diff --git a/t/live_recursion.t b/t/live_recursion.t new file mode 100644 index 0000000..fa8ced1 --- /dev/null +++ b/t/live_recursion.t @@ -0,0 +1,14 @@ +#!perl + +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/lib"; + +use Test::More tests => 3; +use Catalyst::Test 'TestApp'; + +ok( my $response = request('http://localhost/recursion_test'), 'Request' ); +ok( !$response->is_success, 'Response Not Successful' ); +is( $response->header('X-Catalyst-Error'), 'Deep recursion detected calling "/recursion_test"', 'Deep Recursion Detected' );