[Catalyst] begin and detach ?

Matt S Trout dbix-class at trout.me.uk
Tue Jan 24 22:46:00 CET 2006


On Wed, Jan 25, 2006 at 01:30:54AM +0200, raptor wrote:
> hi,
> 
> something like this :
> 
> sub begin : Private {
>   $c->detach('nologin');
> }
> 
> sub list : Local {
> 	....code...
>    $c->log->info('list...');
>    $c->stash(template => 'list.tt');
>       $c->forward('...::View::TT');	
> }
> sub nologin : Private {
>    ....
>    $c->log->info('nologin...');
>    $c->stash(template => 'nologin.tt');
>    $c->forward('...::View::TT');
> }
> 
> 
> why if I access http://localhost/list
> 
> [Wed Jan 25 01:20:30 2006] [catalyst] [debug] Path is "list"
> [Wed Jan 25 01:20:30 2006] [catalyst] [info] nologin...
> [Wed Jan 25 01:20:30 2006] [catalyst] [debug] Rendering template "nologin.tt"
> [Wed Jan 25 01:20:30 2006] [catalyst] [info] list....
> [Wed Jan 25 01:20:30 2006] [catalyst] [debug] Rendering template "list.tt"
> 
> Why is 'list' executed ? 

detach ends the current execution process - begin, auto, main and end are
each a separate set of processing, so detach in begin is localised to begin
and anything you forwarded to from it.

> I try to block access if the user is not logged /using $c->user_exists/..
> other way to do it w/o placing check code inside every action ?

Use an auto sub instead and return 0. Have a look at the flowchart on the
wiki for more details.

-- 
     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