[ABE.pm] subclassing the DBI

Phil Lawrence phil at five-lawrences.com
Fri May 26 05:25:49 PDT 2006


On May 22, 2006, at 9:09 PM, Faber J. Fedor wrote:
> ... What I was trying to do was to build on the $self
> object, i.e. my base class defines $self->{date}, $self->{template},
> etc. which all of the derived classes need.  Then each derived class
> adds to $self the variables the derived class needs.  This way I don't
> need to call '$dbh = get_dbh()' in every function that needs to do  
> a SQL
> stmt (which are quite a few).

Sorry I'm a few days late, especially since this is something I know  
a *lot* about.  Subclassing the DBI is non-trivial.  I think Ricardo  
elsewhere gave the usual Perl answers for subclassing, but you need  
to know up front that it's different with DBI.

[time passes]

rats!  can't my subclassing example!  Maybe it's on my laptop, I'll  
check later.  Probably you can google my name and "subclassing the  
DBI" or something and get most of the details.  But if you do it  
right everything then works the Way It Should...  e.g. you can see in  
the following call to my subclassed module I've expanded the connect 
() method a bit, but it does all the original stuff too.

our $dbh = LUDBI->lu_connect
            (
              $sid
            , 'user_name'
            , $ENV{SUPER_SECRET_PWD}
            , {LUDBI_interact=> 
$LUDBI_interact,PrintError=>0,RaiseError=>1,AutoCommit=>0}
            )
     or die "Couldn't connect!";
DBI->trace(3,"$0.trace.log") if $trace;
$DBI::neat_maxlen = 4600 if $trace;


Phil




More information about the ABE-pm mailing list