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

Tomas Doran bobtfish at bobtfish.net
Mon Jan 4 20:57:09 GMT 2010


On 4 Jan 2010, at 19:48, Tommy Butler wrote:
> # FORWARDING WITH URL SYNTAX
> $c->forward('/groceries/vegetables/carrots');
>

No, there is no such thing as forwarding to a URL.

You forward to a 'private path'. This may, or may not correspond to a  
dispatchable URI.

> # FORWARDING WITH ARGUMENTS
> $c->forward('yet_another_action', [ 1, 2, 'buckle my shoe' ]);
>
> # 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.

> # 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');

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]);

Cheers
t0m




More information about the Catalyst mailing list