[Melbourne-pm] module importing

Jacinta Richardson jarich at perltraining.com.au
Wed May 23 16:52:35 PDT 2007


Josh Heumann wrote:

> Thank you both for your help.  Since I'm using Catalyst, the database
> connection bit has to happen at compile time [1]

> [1]: AFAIK.  If someone knows more about how Catalyst works, or if
> there's even a way to tell it which db to use that's internal to
> Catalyst, please let me know.

G'day Josh,

I am certain you're attempting to do this the wrong way.  "use"ing a module is
the same as writing:

BEGIN { require 'MyModule.pm'; MyModule::import(...) }

Thus the import isn't strictly called at run-time per-se, but it is called after
the module has been evaluated in full, and before the next module is loaded.

Unfortunately I don't know enough Catalyst to tell you exactly how to solve
this, but I've spoken to a couple of people and they've suggested that:

* You can change your database connection details in the yaml config (which is
loaded at runtime).  Thus you can have different yaml files for production than
testing, and just put the preferred one first in the path.

* If you really want to do this in code then you might want to look at
Catalyst::Plugin::ConfigLoader and extend that.  Or instantiate something before
MyApp->setup.

Failing all else you will probably find an answer by asking on #catalyst on
irc.perl.org.  If you do find a good solution then the documentation could do
with a recipe on it.

All the best,

	Jacinta

-- 
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
 (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |


More information about the Melbourne-pm mailing list