From: Jos Boumans Date: Thu, 7 May 2009 15:14:16 +0000 (+0000) Subject: perl5.8.8 + cat 5.80's Cat::Test->ctx_request didn't return $c the 2nd X-Git-Tag: 5.80004~37 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=ba151d0d0be3d3553d866bd0f2277bfdee17d446;hp=c66a708f501cf8e38c67d60aa833eeda369a4233 perl5.8.8 + cat 5.80's Cat::Test->ctx_request didn't return $c the 2nd time it was invoked. Without tracking the bug down all the way, it was clearly related to the Moose'ification of Cat::Test and a scoping issue with a 'my'd variable. Since the same code works fine in 5.10, a bug in either Moose or perl 5.8 is suspected. Khisanth++ for the elegant patch. --- diff --git a/lib/Catalyst/Test.pm b/lib/Catalyst/Test.pm index 77c4007..9118782 100644 --- a/lib/Catalyst/Test.pm +++ b/lib/Catalyst/Test.pm @@ -38,19 +38,24 @@ my $build_exports = sub { Catalyst::Exception->throw("$me only works with local requests, not remote") if $ENV{CATALYST_SERVER}; + ### check explicitly for the class here, or the Cat->meta call will blow + ### up in our face + Catalyst::Exception->throw("Must specify a test app: use Catalyst::Test 'TestApp'") unless $class; + ### place holder for $c after the request finishes; reset every time ### requests are done. my $c; ### hook into 'dispatch' -- the function gets called after all plugins ### have done their work, and it's an easy place to capture $c. - no warnings 'redefine'; - my $dispatch = Catalyst->can('dispatch'); - local *Catalyst::dispatch = sub { - $c = shift; - $dispatch->( $c, @_ ); - }; + my $meta = Catalyst->meta; + $meta->make_mutable; + $meta->add_after_method_modifier( "dispatch", sub { + $c = shift; + }); + $meta->make_immutable; + ### do the request; C::T::request will know about the class name, and ### we've already stopped it from doing remote requests above. my $res = $request->( @_ ); diff --git a/t/unit_load_catalyst_test.t b/t/unit_load_catalyst_test.t index a3a3b37..07cc38c 100644 --- a/t/unit_load_catalyst_test.t +++ b/t/unit_load_catalyst_test.t @@ -5,7 +5,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 56; +use Test::More tests => 59; use FindBin qw/$Bin/; use lib "$Bin/lib"; use Catalyst::Utils; @@ -92,6 +92,18 @@ use_ok( $Class ); } } } +### perl5.8.8 + cat 5.80's Cat::Test->ctx_request didn't return $c the 2nd +### time it was invoked. Without tracking the bug down all the way, it was +### clearly related to the Moose'ification of Cat::Test and a scoping issue +### with a 'my'd variable. Since the same code works fine in 5.10, a bug in +### either Moose or perl 5.8 is suspected. +{ ok( 1, "Testing consistency of ctx_request()" ); + for( 1..2 ) { + my($res, $c) = ctx_request( $Url ); + ok( $c, " Call $_: Context object returned" ); + } +} + # FIXME - These vhosts in tests tests should be somewhere else... sub customize { Catalyst::Test::_customize_request(@_) }