in reply to How not to check if a module is installed

I think it is high time for a new special global to cache the return value from the first time a module was required.

It seems a bug in Perl for "require Foo::Bar;" to succeed when Foo/Bar.pm is in a failing state (such as not existing). I understand the mechanism of this behavior but I still consider it a bug that a reasonable use of eval has the unfortunate consequnce.

Now, with a new %LIB (or whatever it gets called) to hold the value returned by the first require, then subsequent requires can return the same thing as the first require did. This fixes the above bug. It also allows modules to usefully return a value to the script/module(s) that require them (something I've seen more than one good use for).

- tye        

  • Comment on Re: How not to check if a module is installed (bug)

Replies are listed 'Best First'.
Re^2: How not to check if a module is installed (bug)
by xdg (Monsignor) on Oct 24, 2007 at 16:46 UTC

    While people might cringe at the idea, maybe that's something useful that could be hacked into UNIVERSAL::require.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.