[Catalyst] Forwarding to chained Path fails

John Napiorkowski jjn1056 at yahoo.com
Mon Oct 16 14:58:16 CEST 2006


-- John Napiorkowski <jjn1056 at yahoo.com> wrote:

> --- Bernhard Graf <catalyst at augensalat.de> wrote:
> 
> > I'm trying Cat's chained paths and I like it quite
> > much.
> > 
> > One thing I recognized is that you can't forward
> to
> > a chained path.
> > 
> > Take the Hello-World example in
> > Catalyst::DispatchType::Chained.
> > When I add
> > 
> >   sub index : Private {
> >     my ( $self, $c ) = @_;
> >     $c->forward('/hello/47/world/11');
> > }
> 
> I find it works like this:
> 
> Assume that the '/hello/47/world/11' is referring to
> an action called 'world' in the current package.
> 
> $c->forward(
> $c->uri_for($c->controller->action_for('world'),
> [47,11] );
> 
> But if it's in a different controller you need to
> specify the controller name:
> 
> $c->forward(
>
$c->uri_for($c->controller('mycontroller')->action_for('world'),
> [47,11] );
> 
> I'm pretty sure you can only forward to an endpoint
> in
> the chain (something with 'Args(...)' not
> "CaptureArgs(...)".
> 
> If the args are already captured in the current
> action
> you can do like:
> 
> $c->forward(
> $c->uri_for($c->controller->action_for('world'),
> $c->captures );
> 
> But you need to pass the exactly needed number of
> args, if "$c->captures" is an arrayref to three
> things
> you'll need to shorten it with, $c->captures->[0,1]
> or
> whichever are the correct captures.
> 
> Check out the docs for $c->uri_for in the main
> catalyst docs:
> 
>
http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7003/lib/Catalyst.pm#%24c-%3Euri_for(_%24path%2C_%40args%3F%2C_%5C%25query_values%3F_)
> 
> This is one of the more handy things that showed up
> with 5.7 (I think :) ).
> 
> --john
> 
> > 
> > then for http://my.host/greeting I get
> > Couldn't forward to command "/hello/47/world/11":
> > Invalid action or component.

My apologies, my coffee didn't sink in.  I thought you
were trying to redirect or make a link.  I don't think
you can do

$c->forward('world', [47,11])

since the docs say that arrayref goes into the
$c->request->args not  $c->request->captures.  It's
worth a try though.

Usually when I need this I'm redirecting instead of
forwarding since I want the URL in the browser to
change.

I'll check my code and see if I tried this somewhere.

--john


> > 
> > Is this a bug or is there a reason why this cannot
> > work?
> > -- 
> > Bernhard Graf
> > 
> > _______________________________________________
> > List: Catalyst at lists.rawmode.org
> > Listinfo:
> > http://lists.rawmode.org/mailman/listinfo/catalyst
> > Searchable archive:
> >
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> > Dev site: http://dev.catalyst.perl.org/
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo:
> http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst mailing list