in reply to Re: Catalyst Redirect Hints?
in thread Catalyst Redirect Hints?

If you put that in a auto function you don't even need to call it from the controller action. At my current project I am using this base controller for the protected area.
package XXXXX::SecureBaseController; use strict; use warnings; use parent 'Catalyst::Controller'; sub auto: Private { my ( $self, $c ) = @_; # ungültiges User-Objekt in der Session unless ( $c->session->{user} ) { # Umleitung zum Login $c->response->redirect('/login/'.$c->request->path); return; } return 1; } 1;


holli

When you're up to your ass in alligators, it's difficult to remember that your original purpose was to drain the swamp.

Replies are listed 'Best First'.
Re^3: Catalyst Redirect Hints?
by Your Mother (Archbishop) on Mar 26, 2009 at 05:32 UTC

    Nice approach++. I also generally do this stuff in auto() as well but not that way. I may adopt that myself. It's quite direct.

    Update: Oh, but I would change part of it.

    $c->response->redirect('/login/'.$c->request->path);

    Should be-

    $c->response->redirect($c->uri_for('/login', $c->request->path));

    Redirects are supposed to be absolute URIs (per the HTTP spec) and even though most stuff accommodates the relative ones there is at least one real world bug: I've seen them do freaky stuff in mod_perl; internally redispatching to an unrelated part of the app. That was a drag to track down.