[CDBI] Can't override db_Main
"Ryan Tate" <lists-UNebACArQA1Wk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
I am trying to override db_Main as suggested in the wiki for use under
mod_perl, but somehow Ima::DBI keeps overriding my override :-)
I have boiled it down to the following example code, and I only have
this problem if my CDBI subclass is in its own file, so here's that
file:
----
package My::Test::DBI;
use warnings;
use strict;
use base 'Class::DBI';
__PACKAGE__->connection('DBI:mysql:database=test','test','');
sub db_Main{die 'made it!'}
1;
----
And then the calling script:
----
use warnings;
use strict;
use My::Test::DBI;
use Data::Dumper;
print $Class::DBI::VERSION . "\n";
print(Dumper(My::Test::DBI->db_Main));
----
Here's what happens:
----
Subroutine My::Test::DBI::db_Main redefined at
/usr/local/share/perl/5.8.4/Ima/\
DBI.pm line 282.
0.96
$VAR1 = bless( {}, 'DBIx::ContextualFetch::db' );
----
I expected the last line to say "made it!" as in my custom db_Main but
it's clearly defaulting to a db_Main installed by Ima::DBI. How do I
avoid this?
What's odd is that my custom db_Main stays intact if I define my CDBI
subclass in the same file as the test script like so:
----
use warnings;
use strict;
use Data::Dumper;
print(Dumper(My::Test::DBI->db_Main));
package My::Test::DBI;
use warnings;
use strict;
use base 'Class::DBI';
__PACKAGE__->connection('DBI:mysql:database=test','test','');
sub db_Main{die 'made it!'}
----
And here's what happens:
----
made it! at bin/dev/cdbi_dbmain.pl line 17.
----
Not sure what is going on but seems to have something to do with how
the modules are being loaded.