[Catalyst] Init Question and Not Loading a Model Question
Tomas Doran
bobtfish at bobtfish.net
Fri Apr 3 11:56:02 GMT 2009
Dylan Martin wrote:
> I have two questions: 1st, where is a good place to mess with a Cat
> instance after its instantiated its components but not during
> requests?
setup_finalize is the 'approved' hook to run stuff after all the plugins
and components are setup, but before requests start. You need to be a
plugin to do this obviously, and I'd recommend looking at other ways of
doing what you want if possible, its not often you actually need to be a
plugin.
2nd, is there a way to make Cat NOT load a model that's in
> lib/MyApp/Model?
>
> I want to pass the log object in $c->log to an Authen::Simple object
> that I'm using for authentication.
Right, so this is in:
http://cpansearch.perl.org/src/JLMARTIN/Catalyst-Authentication-Credential-Authen-Simple-0.03/lib/Catalyst/Authentication/Credential/Authen/Simple.pm
You have $app right there, and it could just be passed:
https://rt.cpan.org/Ticket/Display.html?id=44778
Has no tests currently, but I'm sure you can fix that, right? :)
> I could have my Login controller
> check that that authentication object has the log object, but it seems
> silly to do that during every request. Maybe I should override setup
> in MyApp.pm? No, that wouldn't work because the components aren't
> instantiated yet... Hmm...
With that patch, unfortunately the requirement will be that you setup
__PACKAGE__->log( My::New::Logger ) (if you need to) before the call to
setup.
> I have a model class in lib/MyApp/Model. I'm running my app on two
> servers. I only want to load my model class on one of my servers. I
> can delete the config settings from MyApp.conf, but it still loads,
> just without my settings. Is there a way to make it not load? Or do
> I have to actually rip the .pm file out of lib/MyApp/Model on the server
> where I don't want it to load?
Pull your model out into an external module, then use
Catalyst::Model::Adaptor to load it.
You can then load a different module (which is blank and contains no
functionality) instead, from config.
But to answer your actual question, no - catalyst will load everything
in your application namespace, there is no way to be flexible.
Cheers
t0m
More information about the Catalyst
mailing list