See t/subclass.t in the DBI distribution.

Tim.

On Wed, Jul 18, 2001 at 02:04:44PM -0400, Steve Sapovits wrote:
> 
> It's documented somwhere and it's not experimental --
> I've been using a DBI subclass for almost two years.
> 
> The reason for having to subclass different pieces is
> that the DBI file actually contains a few related 
> packages.  You need to subclass all of them to get things
> to work.
> 
> If you get stuck, email me directly and I'll send you my
> simple DBI subclass as an example, the caveat being that
> it uses one or two internal pieces I can't send you.  So
> it's good as a template but it won't work as is.
> 
> ----
> Steve Sapovits
> Global Sports Interactive
> Work Email: [EMAIL PROTECTED]
> Home Email: [EMAIL PROTECTED]
> Work Phone: 610-491-7087
> Cell:       610-574-7706
> Pager:      877-239-4003
> 
> > -----Original Message-----
> > From:       Karger, Amir [SMTP:[EMAIL PROTECTED]]
> > Sent:       Wednesday, July 18, 2001 2:01 PM
> > To: DBI Perl mailing List (E-mail)
> > Subject:    RE: inheriting from DBI::db
> > 
> > > > I'm planning on inheriting from DBI::db.
> > > >
> > > > My question is, is it safe to inherit from DBI::db? 
> > >
> > > From: Mitch Helle-Morrissey [mailto:[EMAIL PROTECTED]]
> > > 
> > > Look at the subclass.t test file that comes with the DBI 
> > > distribution.  In
> > > short, you'll need to inherit from all three DBI classes: 
> > > DBI, DBI::db, and
> > > DBI::st.  You'll need to use the init_rootclass() method so 
> > > your constructor
> > > returns an object of the type you created instead of a DBI::db object.
> > > 
> > > I've written a subclass which works fine.
> > > 
> > > Mitch
> > 
> > Interesting! I guess it's not documented yet because it's still
> > experimental?
> > 
> > Is this really necessary, though? Why can't I just say:
> > 
> > --------------
> > package MyDBI;
> > MyDBI::ISA = qw(DBI::db);
> > 
> > sub connect {
> >     my $class = shift;
> >     my $dbh = SUPER::connect(@_);
> >     bless $dbh, $class;
> >     $dbh->do_other_fancy_things;
> >     return $dbh;
> > }
> > 
> > sub do_other_fancy_things {
> >     # highly secret and exciting code not yet written
> > }
> > ---------------
> > 
> > Then, it seems to me, for everything except connect, the regular DBI stuff
> > will happen, right? I'm a bit wary of using the init_rootclass since 
> > (a) others may be using my code for Important Things, and (b) subclass.t
> > says, "This whole mechanism is new and experimental - it may change!"
> > 
> > Amir Karger
> > Curagen Corporation 

Reply via email to