[Catalyst] Another RFC. $c->call()
Bill Moseley
moseley at hank.org
Fri Apr 14 15:58:21 CEST 2006
On Fri, Apr 14, 2006 at 03:34:39AM +0200, Sebastian Riedel wrote:
> What about:
>
> $c->action('/foo/bar')->forward;
> $c->action('/foo/bar')->detach;
>
> or (suggested by mst):
>
>
> $c->forward( $c->action('/foo/bar') );
> $c->detach( $c->action('/foo/bar') );
That would work, and then in my App base I could define my own
method wrappers to name them what I like.
Still, seems like (from the volume of responses) that there would be
use for a new built-in method. Whatever it's called. Can't change
forward's behavior without breaking existing apps.
And one request is that if called *without* any arguments it defaults
to the default/list action.
$c->forward2;
I have controllers that commonly include a null Path attribute for a
"list" method. In my other actions I often want to "forward" to the
list action if input params are bad. So it's nice to not have to
name that action by name.
package App::C::Admin::User;
# show paged list of all users for /admin/user
sub list : Path {
my ( $self, $c ) = @_;
$c->paged_list( class => DB::User );
}
# edit for /admin/usrer/edit/3445
sub edit : Local {
my ( $self, $c, $id ) = @_;
# display list if bad $id passed in
return $c->forward2 unless $self->valid_id( $id );
...
}
My internal_redirect() that prompted this discussion on #catalyst
does this:
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;
}
--
Bill Moseley
moseley at hank.org
More information about the Catalyst
mailing list