trying to subclass DBI



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 ?
.



Relevant Pages

  • Re: How to use select (select(2)) in Perl?
    ... The assignment has to ... >} occur in a different package from that which you are assigning into. ... as long as use vars continues to work. ... especially in such a way that it was doing the importing from the ...
    (comp.lang.perl.misc)
  • Re: our vs. use vars
    ... > except that use vars is backwards compatable. ... All these code snippets pass strict, and they each set the package ... a "use vars" declaration doesn't extend ...
    (perl.beginners)
  • Re: "use strict" in a module
    ... use strict; ... use Exporter; ... use vars qw/@ISA @EXPORT/; ... Global symbol "$x" requires explicit package name at FooPkg.pm ...
    (comp.lang.perl.misc)
  • Re: about the vars scope
    ... These codes are written by famous mod_perl expert Stas Berkman,do you know it? ... >>>(total transparency outside of the package), it can act as an acceptable ... >>>This means any variable declared by vars can be accessed outside of the ... >>>The second part of the understanding comes from Exporter. ...
    (perl.beginners)
  • Modules inter-relay ?
    ... package will be used through out the other project ... use LocalePrint; ... sub PhaseError { ... # using %vars ...
    (perl.beginners)