[Catalyst] redirect problem

John Beppu john.beppu at gmail.com
Mon Apr 17 07:18:28 CEST 2006


On 4/16/06, fayland <fayland at gmail.com> wrote:
> see these code:
>
> sub test : Global {
>     my ( $self, $c ) = @_;
>     unless ($c->user_exists) {
>         $c->res->redirect('/login');
> #        return 1;
>     }
>     $c->res->body($c->user->user_id);
> }
>
> it complains like *|Can't call method "user_id" on an undefined value*,
> I know I don't log in.
> *But* I expect that the "redirect" should be immediately occurred. it
> shouldn't meet the $c->user->user_id
> Now it seems that the "redirect" runs after the whole subroutine.

You are correct.  Redirects don't happen immediately.

> Firstly make sure that the subroutine don't have any problem, then
> "redirect".
> but the "$c->user->user_id" is not a problem if the "user_exists".
>
> uncomment the "return 1;" would work, but it's not such comfortable.
> any thoughts?

That's the way you should do it.



More information about the Catalyst mailing list