Author: timbo
Date: Wed Jan 11 05:39:50 2006
New Revision: 2389

Modified:
   dbi/trunk/Changes
   dbi/trunk/DBI.pm
   dbi/trunk/t/30subclass.t
Log:
Clarified the 'Subclassing the DBI' docs.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Wed Jan 11 05:39:50 2006
@@ -12,6 +12,7 @@ DBI::Changes - List of significant chang
 
   Changed DBI::ProfileData to be more forgiving of systems with
     unstable clocks (where time may go backwards occasionally).
+  Clarified the 'Subclassing the DBI' docs.
 
   Added 'fetch array of hash refs' example to selectall_arrayref
     docs thanks to Tom Schindl.

Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm    (original)
+++ dbi/trunk/DBI.pm    Wed Jan 11 05:39:50 2006
@@ -6616,7 +6616,7 @@ To setup the inheritance hierarchy the @
 should include C<DBI::db> and the @ISA variable in C<MySubDBI::st>
 should include C<DBI::st>.  The C<MySubDBI> root class itself isn't
 currently used for anything visible and so, apart from setting @ISA
-to include C<DBI>, it should be left empty.
+to include C<DBI>, it can be left empty.
 
 So, having put your overriding methods into the right classes, and
 setup the inheritance hierarchy, how do you get the DBI to use them?
@@ -6629,12 +6629,13 @@ or specifying a C<RootClass> attribute:
 
   $dbh = DBI->connect(..., { RootClass => 'MySubDBI' });
 
-The only difference between the two is that using an explicit
-RootClass attribute will make the DBI automatically attempt to load
-a module by that name if the class doesn't exist.
-
 If both forms are used then the attribute takes precedence.
 
+The only differences between the two are that using an explicit
+RootClass attribute will a) make the DBI automatically attempt to load
+a module by that name if the class doesn't exist, and b) won't call
+your MySubDBI::connect() method, if you have one.
+
 When subclassing is being used then, after a successful new
 connect, the DBI->connect method automatically calls:
 

Modified: dbi/trunk/t/30subclass.t
==============================================================================
--- dbi/trunk/t/30subclass.t    (original)
+++ dbi/trunk/t/30subclass.t    Wed Jan 11 05:39:50 2006
@@ -6,6 +6,7 @@ $|=1;
 $^W=1;
 
 my $calls = 0;
+my %my_methods;
 
 
 # =================================================
@@ -19,21 +20,16 @@ my $calls = 0;
 package MyDBI;
 @MyDBI::ISA = qw(DBI);
 
-package MyDBI::dr;
[EMAIL PROTECTED]::dr::ISA = qw(DBI::dr);
-
-sub connect {
-    my ($drh, $dsn, $user, $pass, $attr) = @_;
-    my $dbh = $drh->SUPER::connect($dsn, $user, $pass, $attr);
-    delete $attr->{CompatMode};        # to test clone
-    return $dbh;
-}
+# the MyDBI::dr::connect method is NOT called!
+# you can either override MyDBI::connect()
+# or use MyDBI::db::connected()
 
 package MyDBI::db;
 @MyDBI::db::ISA = qw(DBI::db);
 
 sub prepare {
     my($dbh, @args) = @_;
+    ++$my_methods{prepare};
     ++$calls;
     my $sth = $dbh->SUPER::prepare(@args);
     return $sth;
@@ -45,6 +41,7 @@ package MyDBI::st;
 
 sub fetch {
     my($sth, @args) = @_;
+    ++$my_methods{fetch};
     ++$calls;
     # this is just to trigger (re)STORE on exit to test that the STORE
     # doesn't clear any erro condition
@@ -169,4 +166,5 @@ $dbh = eval { nonesuch2->connect("dbi:Sp
 ok( !defined($dbh), "Failed connect #2" );
 is(substr($@,0,36), q{Can't locate object method "connect"});
 
+print "@{[ %my_methods ]}\n";
 1;

Reply via email to