Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Why Does My Class::DBI Program Break Under "use diagnostics" Pragma?

by Wally Hartshorn (Hermit)
on Jul 11, 2003 at 20:03 UTC ( [id://273553]=perlquestion: print w/replies, xml ) Need Help??

Wally Hartshorn has asked for the wisdom of the Perl Monks concerning the following question:

Okay, this is bizarre. In one particular program (which uses Class::DBI), when I "use diagnostics", the program fails to compile, complaining that it cannot find "DBI/db.pm". If I "use warnings" instead, the program compiles fine and runs perfectly.

Consider the following code (stripped of all useful statements), which you can use on your system to determine whether you get the same behavior:


mydemo.pl

#!/usr/bin/perl use strict; use diagnostics; # use warnings works use lib "."; use MyTable;

MyTable.pm

package MyTable; use base 'MyDatabase'; 1;

MyDatabase.pm

package MyDatabase; use base 'Class::DBI'; 1;

When I try to run "mydemo.pl" with "use diagnostics", I get a boatload of errors about being unable to load "DBI/db.pm". Here's a few lines from the start:


Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Can't locate DBI/db.pm in @INC (@INC contains: . /usr/local/li +b/perl5/5.6.1/sun4- solaris /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site _perl/5.6.1/sun4- solaris /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/ perl5/site_perl/5.6.0/sun4- solaris /usr/local/lib/perl5/site_perl/5.6.0 /usr/local/lib/ perl5/site_perl/5.005/sun4- solaris /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/ perl5/site_perl) at (eval 6) line 3. eval 'require DBI::db ;' called at /usr/local/lib/perl5/5.6.1/base.pm line 59 base::import('base', 'DBI::db') called at /usr/local/lib/perl5/site_perl/5.6.1/Ima/DBI.pm line 645 Ima::DBI::db::BEGIN() called at DBI/db.pm line 0 eval {...} called at DBI/db.pm line 0 require Ima/DBI.pm called at (eval 5) line 3 eval 'require Ima::DBI ;' called at /usr/local/lib/perl5/5.6.1/base.pm line 59 base::import('base', 'Class::Accessor', 'Class::Data::Inherita +ble', 'Ima ::DBI') called at /usr/local/lib/perl5/site_perl/5.6.1/Class/DBI.pm line 6 Class::DBI::__::Base::BEGIN() called at DBI/db.pm line 0 eval {...} called at DBI/db.pm line 0 require Class/DBI.pm called at (eval 3) line 3 eval 'require Class::DBI ;' called at /usr/local/lib/perl5/5.6.1/base.pm line 59

It goes on and on like that. Just change "diagnostics" to "warnings" and the problems go away (not to mention that, with the actual code in place, the program works).

What kind of weirdness have I stumbled across? Has anyone else seen something like this? (I spent about 5 hours trying to figure out why one program was working while a similar program -- use had the "use diagnostics" line -- was not!) This is Perl 5.6.1 under Sun Solaris 7.

Wally Hartshorn

(Plug: Visit JavaJunkies, PerlMonks for Java)

Replies are listed 'Best First'.
Re: Why Does My Class::DBI Program Break Under "use diagnostics" Pragma?
by pfaut (Priest) on Jul 12, 2003 at 12:12 UTC

    I just entered the code on your base node and it works fine on my system. Perl 5.6.1 on linux with Class::DBI 0.91.

    90% of every Perl application is already written.
    dragonchild
(jeffa) Re: Why Does My Class::DBI Program Break Under "use diagnostics" Pragma?
by jeffa (Bishop) on Jul 12, 2003 at 15:48 UTC
    Unlike pfaut, i tried your code and it failed in the same manner. I used Class::DBI version 0.93 on two Linux boxes - one with Perl 5.6.0 and the other with 5.6.1. Both failed. One bizarre item that i can't figure out about this is that there is no DBI/dbi.pm file ... DBI::db is sort of automagically created somewhere inside of DBI.pm (note there there is no DBI::db package declaration either). I wonder how pfaut was able to get your code to work ...

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      I looked at %INC after the program got started and dumped versions. Here's what I got. The code:

      #!/usr/bin/perl use strict; use diagnostics; use lib "."; use MyTable; print <<"END"; Exporter = $Exporter::VERSION Carp = $Carp::VERSION XSLoader = $XSLoader::VERSION Class::DBI::Query = $Class::DBI::Query::VERSION DynaLoader = $DynaLoader::VERSION lib = $lib::VERSION Class::Trigger = $Class::Trigger::VERSION Exporter::Heavy = $Exporter::Heavy::VERSION DBI = $DBI::VERSION Class::WhiteHole = $Class::WhiteHole::VERSION MyDatabase = $MyDatabase::VERSION constant = $constant::VERSION Class::DBI::ColumnGrouper = $Class::DBI::ColumnGrouper::VERSION strict = $strict::VERSION diagnostics = $diagnostics::VERSION base = $base::VERSION vars = $vars::VERSION Config = $Config::VERSION warnings::register = $warnings::register::VERSION warnings = $warnings::VERSION Class::Data::Inheritable = $Class::Data::Inheritable::VERSION Ima::DBI = $Ima::DBI::VERSION Class::Accessor = $Class::Accessor::VERSION MyTable = $MyTable::VERSION Class::DBI = $Class::DBI::VERSION overload = $overload::VERSION AutoLoader = $AutoLoader::VERSION Data::Dumper = $Data::Dumper::VERSION END

      The output:

      Exporter = 5.562 Carp = XSLoader = 0.01 Class::DBI::Query = DynaLoader = 1.04 lib = 0.5564 Class::Trigger = 0.08 Exporter::Heavy = DBI = 1.32 Class::WhiteHole = 0.03 MyDatabase = -1, set by base.pm constant = 1.02 Class::DBI::ColumnGrouper = strict = 1.01 diagnostics = base = 1.98 vars = Config = warnings::register = warnings = Class::Data::Inheritable = 0.02 Ima::DBI = 0.28 Class::Accessor = 0.17 MyTable = Class::DBI = 0.91 overload = AutoLoader = 5.58 Data::Dumper = 2.102
      90% of every Perl application is already written.
      dragonchild

      Well, I'm still not sure what the cause was, but I figured out how to fix it -- upgrade to Perl 5.8.0. :-) I had been using Perl 5.6.1 and Class::DBI 0.92. Switching to Perl 5.8.0 made the problem go away. I don't know if I just had some weirdness in my configuration or if it was an odd conflict between 5.6.1 and 0.92. In any case, it works now and I'm tired of struggling with it.

      Weird. And one of the biggest time-sucks I've ever had the misfortune to get pulled into. :-(

      Thanks for verifying that I wasn't 100% nuts!

      Wally Hartshorn

      (Plug: Visit JavaJunkies, PerlMonks for Java)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://273553]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found