Re: dynamically defining base class for a CDBI table module
[prev]
[thread]
[next]
[Date index for 2005/03/11]
On 10 Mar 2005, at 20:18, Gianni, Andrew wrote:
> The app will likely eventually run under mod_perl, in which case
> Class::DBI::Factory looks perfect. In the meantime, however, can I
> expect to take a significant performance hit by using
> Class::DBI::Factory in a non-mod_perl environment? =46rom the pod:
>
> The factory object will do as little work and load as little machinery
> as possible, but it's still a relatively expensive thing to build.
I don't think using CDF would add significantly to the cost of=20
launching your application, so I'd better change that paragraph :)
The factory adds a little overhead, but my point was that the task of=20
loading all your CDBI data classes, making the database connection and=20=
preparing template handlers and other machinery is already quite=20
substantial, and that the factory offers an easy way to do that work=20
only once.
=46rom your original question:
> I have a number of schemas that contain tables that are accessed by
> multiple applications. Rather than redefining the modules for each
> application to use the CGIP base class for the project, I'd like to be
> able to define the CDBI table modules in a central location, but I=20
> would
> like to be able to dynamically have it set the appropriate base class,
If I've understood this, it's a variation on a common CDBI problem: you=20=
want to use the same data classes in slightly different ways under=20
different circumstances. Changing their behaviour by shuffling the=20
superclass is a neat idea. I doubt that it will be very workable under=20=
mod_perl, but it's hard to say without knowing more about how you want=20=
the behaviour of the classes to change. If, as your other message=20
suggests, all you really need is to supply the right database handle to=20=
each application, then =C7lass::DBI::Factory is just what you need and=20=
will make your life a lot easier when you move to mod_perl.
If you don't want the extra machinery, you can accomplish something=20
similar with a db_Main method that keeps a hash of handles (probably in=20=
the form of closures generated by Ima::DBI) and consults its=20
environment before returning the right one.
best
will
ps. the handler base class included with the latest version of CDF is=20
for mod_perl 2 only, and fairly new: people are using it, but I'd treat=20=
it as a beta if I were you.