[Catalyst] proper flow control with $c->foward, in search of greater grok

Tommy Butler ace at tommybutler.me
Mon Jan 4 21:26:40 GMT 2010


Tomas Doran wrote:
> 
>> # FORWARDING TO AN ACTION IN SOME OTHER NAMESPACE
>> # THAT MIGHT NOT BE ACCESSIBLE AS A URL
>> my $dbix_query = $c->forward(
>>    'Reports::Custom::TodaysPerformance',
>>    'todays_performance_detailed',
>>    [ { # Snip
>>    } ]
>> );
>>
> 
> Erm, that's forwarding to a component name and a method name, and I
> don't think ^^ will work, as it's not a component which will be returned
> by $c->component.

I don't understand what you mean by "component", but I'll be looking
that up here momentarily.  For the record, it _does_ work, and it's part
of a completely functional application running on several servers as I type.

Part of that example I found at a website and by trial and error was
able to arrive at the working final product.

>> # FORWARDING TO A VIEW?
>> # not sure if you can pass arguements here, nor am I sure why I'm
>> # required to fully qualify the namespace starting at 'MyApp' and
>> # why I am not required to do so in the example immediately above
>> # this one.
>> $c->forward('MyApp::View::MP3');
> 
> This is forwarding to a class name without a method name, and so the
> method name defaults to 'process'
> 
> You don't fully qualify the namespace - you just say
> ->forward('View::XXXX');

Again, this seems strange to me as well, seeing as the example I gave
for forwarding to a view comes nearly verbatim from working code.  But
despite that, what you say makes perfect sense; the view (or class -ahem
, sorry) to which I'm forwarding does contain a single method named
"process".  I found that example from a CPAN module's source code.  As
you can see, I really have been digging around for a while.  I've found
things that work, but have no idea *why*.  More than anything else I've
found things that *don't* work ;-)

> The other thing is that you've missed the most important and useful
> thing you can forward to - an action directly.
> 
> $c->forward($c->controller('Foo')->action_for('bar'), [@args]);

oOOooo I like that!  $c->controller->... AWESOME!

Thank you for your response Tomas.

-- 
Tommy Butler





More information about the Catalyst mailing list