pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

What's the best way/place to do some global init code in Catalyst? IE, I want to set some default values at startup, not in my controller.

I have some Authen::Simple classes that I'm using. I'm loading them from the config file, so I never touch them in code except to say authenticate($username,$password) in my controllers. I want to pass the $c->log object to Authen::Simple::X object to use for logging. Near as I can tell, the time/place to do that would be in some handy init subroutine, but I don't see an obvious one in the docs.

Thanks!
--Pileofrogs

Replies are listed 'Best First'.
Re: Catalyst Init?
by holli (Abbot) on Apr 02, 2009 at 17:46 UTC
    package MyApp::BaseController; use parent 'Catalyst::Controller'; sub auto : Private { my ( $self, $c ) = @_; $c->log->info( 'this happens on every request' ); return 1; # return true to continue the request } 1; package MyApp::SomeController; use parent 'MyApp::BaseController'; # snip 1;
    Update: somewhat related


    holli

    When you're up to your ass in alligators, it's difficult to remember that your original purpose was to drain the swamp.
Re: Catalyst Init?
by Your Mother (Archbishop) on Apr 02, 2009 at 17:41 UTC

    Maybe subclass setup in your app base; MyApp.pm. Be careful of things that make you start to do that sort of stuff. It smells like a design problem. I'd float it, and maybe How to NOT load a Catalyst Model?, on the Cat list too to get a wider set of Cat-eyes on it.