[Catalyst] Clash of the plugins: SubRequest vs Static::Simple

Andy Grundman andy at hybridized.org
Wed Oct 5 04:19:36 CEST 2005


Andy Grundman wrote:
> Johan Lindström wrote:
> 
>> At 00:29 2005-10-05, Andy Grundman wrote:
>>
>>> I'll try to duplicate this and write a failing test for 
>>> Static::Simple.  Just looking at the code, I can't see anything 
>>> wrong, though.
>>
>>
>>
>> Attached is a simple Cat project that demonstrates the behaviour 
>> (note: Windows newlines).
>>
>> perl script\smurf_test.pl /bar/baz
>> [just outputs text]
>> ...
>> in Bar::baz
>>
>> perl script\smurf_test.pl /bar/foo
>> [calls /bar/baz as a subrequest and outputs some text with the result]
>> ...
>> in Bar::foo with subreq: (in Bar::baz)
>>
>> If you edit Smurf.pm and add the Static::Simple, you get this instead:
>> in Bar::foo with subreq: ()
>>
>> And if you'll trace after the breakpoint you'll see how 
>> Smurf::dispatch() is never called.
> 
> 
> Thanks.  I worked up a test that duplicates the issue which I just 
> committed.  Unfortunately, it appears to be an issue with NEXT.  When 
> subrequest calls $c->dispatch, NEXT has already seen the dispatch method 
> and therefore refuses to call it a second time.
> 
> Tried this in sub_request():
> 
> {
>     local $NEXT::SEEN = {};
>     $c->dispatch();
> }
> 
> but with no luck.  There is probably a solution here with localizing the 
> proper NEXT data structure.
> 
> I also changed my calls to NEXT::ACTUAL so it will die if it can't call 
> the dispatch method, rather than appearing to work and just returning 
> nothing.

Aha!  Thanks to mst, try this patch to SubRequest.pm and let me know if 
it works in your app.

-Andy
-------------- next part --------------
Index: SubRequest.pm
===================================================================
--- SubRequest.pm	(revision 1234)
+++ SubRequest.pm	(working copy)
@@ -52,7 +52,12 @@
     $c->prepare_action();
     $c->log->debug("Subrequest to $path , action is ".  $c->req->action )
         if $c->debug;
-    $c->dispatch();
+    
+    # hack NEXT so we can call all the dispatch methods
+    {
+        local $NEXT::NEXT{$c,'dispatch'};
+        $c->dispatch();
+    }
     my $output  = $c->res->output;
     $c->req->{params}=$old_req{params};
     $c->req->arguments($old_req{args});


More information about the Catalyst mailing list