Re: trying to subclass DBI
- From: tyler@xxxxxx (Tyler MacDonald)
- Date: Thu, 29 Dec 2005 15:24:02 -0800
Tim,
My DBI subclass places connect in it's root class
(DBIx::Transaction):
http://search.cpan.org/src/CRAKRJACK/DBIx-Transaction-0.002/lib/DBIx/Transaction.pm
Is this supposed to work as well, or should I move it into dr? (Is
there a situation/driver where this won't work?)
Thanks,
Tyler
Tim Bunce <Tim.Bunce@xxxxxxxxx> wrote:
> The connect() method needs to be in a MySubDBI::dr package (that's dr not db)
>
> Tim.
>
> On Thu, Dec 29, 2005 at 12:39:39AM +0100, wernerus sebastien wrote:
> > Hi,
> >
> > I'm new to OO programming, and i'd like to subclass DBI for some purpose.
> >
> > I made some tests to figure out how it worked. Here is a sample code
> > that doesn't do anything interesting. It doesn't execute as I
> > expected:
> >
> > ======================
> > package MySubDBI;
> >
> > use strict;
> >
> > use DBI;
> > use vars qw(@ISA);
> > @ISA = qw(DBI);
> >
> > package MySubDBI::db;
> > use vars qw(@ISA);
> > @ISA = qw(DBI::db);
> >
> > sub connect {
> > my ($drh, @args) = @_;
> > my $dbh = $drh->SUPER::connect(@args) or return;
> > $dbh->{private_mysubdbi_test} = 'blabla';
> > print "test0\n";
> > return $dbh;
> > }
> >
> > sub test {
> > my $dbh = shift;
> > return $dbh->{private_mysubdbi_test};
> > }
> >
> > package MySubDBI::st;
> > use vars qw(@ISA);
> > @ISA = qw(DBI::st);
> >
> > package Main;
> >
> > my $dbn = "DBI:mysql:database=***:host=***:port=***";
> >
> > my $dbh = MySubDBI->connect( $dbn, '***', '***' );
> > if ( $dbh ) { print "connection ok\n" } else { print "connection error\n" }
> >
> > print 'test1: ', $dbh->{private_mysubdbi_test}, "\n";
> > print 'test2: ', $dbh->test, "\n";
> > ======================
> >
> > It prints:
> > connection ok
> > test1:
> > test2:
> >
> > Do you know why it doesn't print the string 'test0' and nothing for
> > test1 and test2 ?
>
.
- Follow-Ups:
- Re: trying to subclass DBI
- From: Wernerus Sebastien
- Re: trying to subclass DBI
- References:
- trying to subclass DBI
- From: Wernerus Sebastien
- Re: trying to subclass DBI
- From: Tim Bunce
- trying to subclass DBI
- Prev by Date: Re: trying to subclass DBI
- Next by Date: Re: DBI 1.50 - make problems (cc1: Invalid option)
- Previous by thread: Re: trying to subclass DBI
- Next by thread: Re: trying to subclass DBI
- Index(es):
Relevant Pages
|