Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: What is the /auto/ directory used for? (inheritance--)

by tye (Sage)
on Aug 21, 2006 at 04:20 UTC ( #568465=note: print w/replies, xml ) Need Help??


in reply to Re: What is the /auto/ directory used for?
in thread What is the /auto/ directory used for?

Yes, this error message sucks. It should list the two possible explanations with the most likely ("no such method") stressed more than the other ("*.al file missing because module not properly installed").

Note that this error message is a result of over-use of inheritance. In particular, this line from DBI.pm:

@ISA = qw(Exporter DynaLoader);

means that DBI "is a" Export and "is a" DynaLoader. Which means that if either Exporter or DynaLoad "is a" SomethingElse, then DBI also "is a" SomethingElse.

So some implementation detail of Exporter or DynaLoader becomes the baggage of DBI because it declares itself to be a descendant of them. In this case, the detail is that one (or both) of them "is a" AutoLoader (or similar). So DBI suddenly acts like an AutoLoader even though it had no desire to do so.

It would be better if Exporter and DynaLoader didn't use inheritance to get the AutoLoader functionality. And it would be better if DBI didn't use inheritance to get Exporter nor DynaLoader functionality.

Note that this realization has lead to Exporter now supporting better ways for it to be used, such as:

use Exporter qw( import );

And note that some module authors have realized this problem with DynaLoader and worked around it similarly:

require DynaLoader; # ... DynaLoader::bootstrap( __PACKAGE__ );

It is rather sad that the OO mindset so often jumps to inheritance as the answer for nearly every problem. Here we have two important core modules that mostly just need to provide one subroutine to the modules that use them, yet they encourage inheritance to be used to accomplish this.

It would be nice if DBI would fix this. Since DBI tries to be quite portable, it probably can't assume a modern version of Exporter, so it should instead use something like this:

BEGIN { require Exporter; *import= \&Exporter::import; }

Thus DBI would no longer produce this particularly misleading error message.

- tye        

Replies are listed 'Best First'.
Re^3: What is the /auto/ directory used for? (inheritance--)
by syphilis (Bishop) on Aug 21, 2006 at 09:30 UTC
    Thus DBI would no longer produce this particularly misleading error message

    I couldn't get that to work ... I may well be missing something.

    I tried a variety of the changes you mentioned, but whenever I comment out (in DBI.pm) "@ISA = qw(Exporter DynaLoader);" I get:
    F:\pscrpt>perl -MDBI -e "DBI::FIRSTKEY()" Can't locate object method "dl_load_flags" via package "DBI" at F:/per +lvc7/5.8.8/lib/DynaLoader.pm line 230. BEGIN failed--compilation aborted at F:/perlvc7/site/5.8.8/lib/DBI.pm +line 262. Compilation failed in require. BEGIN failed--compilation aborted.

    And if I don't comment out that line of code in DBI.pm I always get:
    F:\pscrpt>perl -MDBI -e "DBI::FIRSTKEY()" Can't locate auto/DBI/FIRSTKEY.al in @INC (@INC contains: F:/perlvc7/5 +.8.8/lib F:/perlvc7/site/5.8.8/lib F:/perlvc7/site/lib .) at -e line +1

    I guess a patch to DBI.pm would be one simple way for me to see exactly what is required. I'd like to know how to change this behaviour and still use DynaLoader. Digest::MD5 gets it right, but it uses XSLoader instead.

    Cheers,
    Rob

      You just need to add

      sub dl_load_flags { 0 }

      It'd also be good to patch DynaLoader to not require this (and to optionally export the bootstrap function).

      - tye        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-07-23 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?