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

Why not just
use Test::More tests => 2; for (1 .. 2) { eval "require Foo" or delete $INC{'Foo.pm'}; ok( $@, "Saw error loading Foo" ); } __END__ ok 1 - Saw error loading Foo ok 2 - Saw error loading Foo

delete doesn't clear $@.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

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

    For a real module, if warnings are on, that is likely to provoke "subroutine redefined" warnings.

    The example is intentionally simplistic. The real case was "eval require" in a subroutine in a module that later wound up being used inside a loop. It's not that I don't know how to work around this issue -- it just never occurred to me that this was the behavior of 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.