[Catalyst] Changing a base url in mod_perl

Matt S Trout dbix-class at trout.me.uk
Fri Dec 30 23:44:03 CET 2005


On Fri, Dec 30, 2005 at 02:18:56PM -0800, Ovid wrote:
> --- Matt S Trout <dbix-class at trout.me.uk> wrote:
> 
> > Why do you need to specify this at build time? Under (e.g.) 
> > mod_perl Catalyst will auto-detect it's base URL and Just 
> > Handle It, and in the general case it's trivial to set the
> > base URL from a config.yml
> 
> Hi Matt,
> 
> That's what I thought, but I'm doing something wrong.  I'm used to
> programming under mod_perl, but not setting it up.  My httpd.conf has
> something like the following:
> 
>     sub login : Local {
>         my ( $self, $c ) = @_;
> 
>         $c->stash->{template} = 'login.tt';
>         $c->session->{referer} ||= $c->req->path;
>         if ( !$c->login() ) {
>             $c->log->debug('login failed');
>             $c->stash->{message} = 'Login failed.';
>             $c->forward('Kinetic::UI::Catalyst::V::TT');
>         }
>         else {
>             if ( $c->session->{referer} =~ m{^/?login} ) {
>                 $c->session->{referer} = '/';
>             }
>             $c->log->debug('login succeeded');
>             $c->res->redirect( $c->session->{referer} || '/' );
>         }
>     }
> 
> Now that I look at this, I'm guessing that I am handling the referer
> wrong, but I can't really tell.  I'm sort of cargo-culting this along.

Hmm. I'd vote for

$c->session->{referer} ||= $c->uri_for($c->req->path);

and then just

$c->res->redirect( $c->session->{referer} );

(sorting out the m{^/?login} to respect $c->req->base left as an exercise
for the reader :)

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