[Catalyst] Trouble with Chained Actions and Redirects?

Robert 'phaylon' Sedlacek phaylon at dunkelheit.at
Tue Sep 19 16:05:06 CEST 2006


John Napiorkowski said:
> I didn't know you could detach without an arg.  That
> sounds like want I want.

That's docced in Catalyst.pm, tho I think it was only added recently.

> I have to think I'm not the only one with this
> confusion.  Maybe we could alias $c->end to $c->detach
> or something to make it clear in the docs how to stop
> the execution right away?

$c->end would break if you have a sub end : Private in your MyApp.pm (not
encouraged, as we have Root controllers now, but some people might still
be using this). Personally, I find this function in ->detach more clean
than adding another keyword that just does ->detach but doesn't take
arguments.

> Or even a $c->response->redirect_and_end() could do it.

Well, but then you'd have functionality affecting the execution flow
placed in Catalyst::Response, which is also not rather clean.

> I mean most of the time when you redirect what you are
> looking for is catalyst to stop right there (at least
> for me but I can see reasons why you might want it to
> continue for logging and so forth).  I think it's
> intuitive to think that dire

The API is released, can't be changed now anyway. And while I've been
bitten by this in the beginning as well one or two times, I now rather
appreciate it that ->detach (and return 0 in auto's) is the only thing
stopping the execution chain.

> I suppose it could be a trivial plugin as well.

Wouldn't even need to. It's just an (untested)

  sub MyApp::redirect_and_stop {
      my $c = shift;
      $c->response->redirect(@_);
      $c->detach;
  }

and a call via $c->redirect_and_stop( $c->uri_for('/foo', $foo) );




More information about the Catalyst mailing list