Hi
Currently I am re-writing an existing Perl based web survey system. I am
using OO techniques but am new to these concepts and implementation details.
My setup is Mod_Perl, Apache, MySQL and Perl 5.004
My intention is to have a number of classes that 'shadow' their namesake DB
tables. Eg. a 'user' MySQL table and a 'user' Perl class that provides the
methods to deal with real world users. The 'user' class, (and all other DB
table classes) will subclass a class I'm calling 'database'.
In an ideal world, (although correct me if I'm wrong about this...) the
'database' class would subclass 'DBI'. However, I tried this and found it
wasn't straight-forward, a bit of Google homework seemed to suggest that it
would be a can of worms so instead I'm settling for initialising the
database class when each new http request is made and making a seperate DBI
object that 'user' and 'database' methods can use to perform the actual
interaction with MySQL.
My question: What is the best way to handle that DBI object? Do I have to
keeping passing it around as and when required or can I store a seperate
reference to it in each of the table classes that I'm creating? Even
better, can I make it global in scope to my 'database' class, I'm thinking
that this would be a good solution but am concerned because I've always
avoided global variables because of the Mod_Perl issues (ie. system users
start getting each others data). How do I make something globally scoped to
a package but ensure that values remain unique to the owners of each and
every http request?
Appreciate any help, (specific advice or just point me in the right
direction) from those that know about these things.
Cheers
Sparky