[Catalyst] Form handling, urls and web design

Alex Kavanagh alex at tinwood.homelinux.org
Tue Jan 24 20:02:46 CET 2006


At Tue, 24 Jan 2006 06:09:40 -0800,
Bill Moseley wrote:
> 
> On Tue, Jan 24, 2006 at 09:04:37AM +0000, Alex Kavanagh wrote:
> > > I stay away from default.  Use an empty path instead.
> > 
> > Why do you stay away from default?
> 
> It doesn't work like other actions.  First, it doesn't pass arguments
> relative to the controller, rather all arguments from root:
> 
>     Request: http://localhost:3000/path/to/controller/arg1/arg2
> 
>     package App::C::Path::To::Controller;
> 
>     sub default : Private {
>         my ( $self, $c, @args ) = @_;
>         #  @args = (path,to,controller,arg1,arg2)
> 
> 
>     sub foo : Path {
>         my ( $self, $c, @args ) = @_;
>         # @args = (arg1,arg2)
> 
> 

Yes, that makes a lot of sense.

> 
> Second, with "default" match is not set and action is always "default",
> but when using Path they are set just like any other matched
> controller.

Unfortunately, this doesn't so I must've mis-read something in the
docs.  So I'll go hunt this one down.  Thanks for the pointers.


[snip]

> > Um, where is internal_redirect defined?  Is it a plugin? What makes it
> > different from a normal $c->res->redirect ?
> 
> It's when I want to show another controller but without the extra
> round trip to the client.
> 
> =item internal_redirect action @args
> 
> This does a sub-request and returns.  This is useful for jumping to
> another action and making uri_for work relative to the forwarded action (instead
> of the originally matched argument).
> 
> Action is relative to namespace unless it starts with a slash.  If action is
> undefined then the redirect is just to namespace (for use with undefined : Path
> actions).  @args is passed directly to the subrequest.
> 
> $action should be a public path.
> 
> =cut
> 
> 
> sub internal_redirect {
>     my ( $c, $action, @args ) = @_;
> 
>     unless ( defined $action ) {
>         $action = $c->action->namespace;
>     } else {
>         $action = join '/', $c->action->namespace, $action unless $action =~ m!^/!;
>     }
> 
>     $c->res->body( $c->subreq( $action, @args ) );
>     return;
> }

Interesting.  I guess that this goes in your MyApp class so hat it
gets on to the context, $c ?

I'm curious as to what happens if the sub-request then does another
sub-request.  (I realise that this is getting into the internals of
Catalyst, but I am curious!).

Does a 'new' $c get created and with it a new response, request,
etc. or does it overwrite the original?

(I might just go search the code out and see what happens ... no
wonder this takes so long :-) )

Cheers

-- 
Alex.



More information about the Catalyst mailing list