[Catalyst] Re: Sharing a database handle between components

Aristotle Pagaltzis pagaltzis at gmx.de
Sat Feb 9 18:55:17 GMT 2008


* Matt S Trout <dbix-class at trout.me.uk> [2008-02-09 19:15]:
> What was wrong with just making the dbh acquired from -
> 
> Scalar::Defer::lazy { $app->model('Foo')->schema->storage->dbh }
> 
> ?

Actually, that fails: T::P::DBI::new calls `prepare_cached` on
the DBH, causing the deferred scalar to cash in right away, thus
defeating the lazification.

It might work to make the entire Template::Provider::DBI
instantiation lazy. That is then too at the mercy of when TT
tries to cash in the deferred scalar I put in `LOAD_TEMPLATES`,
though, so it would work more by chance than design.

Another thing is that with my current solution, MyApp::View::TT
does not refer to a specific model itself; it is the MyApp class
that wires the DBH from a specific model into the view that needs
the DBH. This coupling is IMO more correct than coupling the view
class to a particular model class.

So it seems to me that the clean way to do this is definitely to
do some additional setup after Catalyst has finished setting
itself up.

The question is, will running code in the top-level scope of
MyApp after `__PACKAGE__->setup` paint me into a singleton-ish
corner or not? And will it continue working for the foreseeable
future?

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list