[Catalyst] Detach won't detach?

Ash Berlin ash_cpan at firemirror.com
Mon Jan 26 19:02:32 GMT 2009


On 26 Jan 2009, at 18:56, koniczynek wrote:

> Hello Everyone,
>
> I am trying to accomplish what seems to be impossible. There is a
> controller, and inside this controller there are 3 methods:
> - auto
> - do_something
> - end
>
> In auto I am testing if user is logged in, if so I am detaching to the
> do_something function, if not, I am redirecting to the / In end  
> function
> there is nothing at this point. The code looks somehow like this:
>
> sub auto :Private {
>  my ( $self, $c ) = @_;
>
>  $c->log->debug('action start');
>  if ( ! user_logged_in) {
>    $c->redirect( $c->req->base );
>  } else {
>    $c->detach( $c->action->{name} );
>  }
>  $c->log->debug('action end');
> }

detach in auto does not detach/stop processing the entire request,  
just the chain of auto commands.

To stop the request from in auto you need to return a false value. I'm  
fairly sure this is documented somewhere - cant look now as i'm on a  
painfully slow link

FWIW, I'd personally do this with chained actions, but its your choice.

-ash



More information about the Catalyst mailing list