Michael G Schwern wrote:
On Sat, Sep 24, 2005 at 02:13:46PM -0400, Randy W. Sims wrote:
Is there a way to make C<require> or C<use> fail without manipulating
@INC or hiding the physical file? Or more generally, how do you test all
branches of constructs like:
if ( eval {require Foo} ) {
useFoo();
} elsif ( eval {require Alternate} ) {
useAlternate();
} else {
fake_it();
}
Override CORE::GLOBAL::require.
However, working out all the little nuances and buglets in such an approach
is fraut with peril. Leaving the error message unaltered (as to the file
and line number of the require), maintaining backwards compat (the behavior
of CORE::GLOBAL::require changed between 5.6 and 5.8) and avoiding circular
references (some of the magic around CORE::require appears to be broken) is
tricky enough that I couldn't get it to work fiddling around for about
10 minutes.
I haven't tried overriding yet, but your mention of a change in
internals reminds me of another approach I had tried without success.
The docs imply in its psuedo perl version of C<require> that I might be
able to set $INC{'Foo.pm'} to undef or some false value to cause require
to fail. It does not under 5.8; I haven't tried under other versions
yet. Is that part of the behavior that changed while the docs didn't? or
did I misread something?
Randy.