I'm new to OO Perl, and have a question about storing the value
of the $dbh in an object.

This is a Perl CGI(not CGI.pm) DBI application - each cgi script
connects at the start and creates a $dbh which then gets used
throughout the remainder of the script.  For this application,
I created a class - each cgi script creates a new object of the
class, and then each script calls various methods on that
object - many of those methods do database "stuff" that
obviously require the $dbh.

My question is, what is the best method for allowing the object
methods to use the $dbh established at the beginning of a cgi
script?  The 3 options I saw were:

  1. pass the $dbh as an argument to each object method
      - I don't like this method

  2. pass the $dbh in to the "new" method, and set an instance
     $DBH variable equal to that $dbh argument - this allows
     me to access the $DBH instance variable anytime I need
     access to the database handle

  3. in the cgi script, once the $dbh is established, call
     a class method to set a class $DBH variable - and then
     have each object method invoke a class method to return
     the value of the class $DBH variable

I currently have option 2 in effect, but am not really sure
this is the best method.  Anyone else see other methods that
I could use, or have an opinion on which of the 3 options
above is best?  Are there memory(leak?) issues with storing
the $dbh in each object, or memory issues with any of the
options?  Any help is appreciated.

-- 
Hardy Merrill
Mission Critical Linux, Inc.
http://www.missioncriticallinux.com

Reply via email to