[Catalyst] Another RFC. $c->call()
Matt S Trout
dbix-class at trout.me.uk
Fri Apr 14 16:16:48 CEST 2006
Bill Moseley wrote:
> 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 );
>
> ...
> }
For that, I'd use a custom Action class that overrides $action->match to
return 0 if valid_id doesn't pass. Then dispatch would fall back to the
default automatically.
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Catalyst
mailing list