perl5.8.8 + cat 5.80's Cat::Test->ctx_request didn't return $c the 2nd
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Test.pm
index 77c4007..9118782 100644 (file)
@@ -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->( @_ );