[Catalyst] Passing connection info to an custom model/external lib

Eric Wright info at rapidsynergy.com
Fri Apr 10 18:59:13 GMT 2009


I have what I hope is not a dumb question. I'm trying to follow best
practices here and am writing a piece of business logic that I feel
should be Catalyst agnostic and therefore am creating a custom model.
(However, at the moment Catalyst is the primary consumer of this lib.)
I'd like to use my DBIC::Schema goodness for DB access and happily
have abstracted that via Catalyst::Model::DBIC::Schema. The thing is I
realized that if I connect to this schema outside of the scope of
Catalyst via DBIx::Class::Schema->connect I have to pass in the
connection info separately which really bugs me because I've already
defined it via a configuration file for the Catalyst app (using
Config::General). I suppose I could just pass that info into the model
but that seems messy and redundant to me. If I subclass
Catalyst::Model well then I'm tightly coupled with Catalyst again. I'd
like to just be able to glue the model to Catalyst and do a:

$c->model('MyCustomModel')->foo(...)

and it just work.

It seems to me there should be a simple way for this schema to know
its connection info based on context and I figured there's like a
slick Catalyst ninja kind of method for doing this that my brain is
just not grasping at the moment. How do you do this sort of thing? Is
the magic in the Catalyst glue?

Thanks in advance for any advice/thoughts/comments...

-Eric



More information about the Catalyst mailing list