On Sat, Jun 19, 2004 at 09:11:43PM -0200, Gabor Szabo wrote: > > I would like to test a module for unsuccessful "require" while the > required module is installed. That is I'd like ot test how my code would > work if Foo.pm was not present. > > In the middle of a module I have code such as > > eval { > require Foo; > }; > if ($@) { > foo(); > } else { > my_own_foo(); > }
I would structure the code so that the different behavior with and without Foo can be requested explicitly. As a quick hack, something like, BEGIN { $Mod::use_foo = 0 } use Mod; # tests for Mod without Foo then in your module package Mod; $use_foo = 1 unless defined $use_foo; if ($use_foo && do { eval { require Foo }; ! $@ }) { foo(); } else { my_foo(); } As a philosophy, I try to write my code so that it can be tested directly without having to set up a complex environment, in this case, arranging for Foo not to be found. Andrew