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 already installed Foo so I can test the behaviour of the code with Foo. How can I test now the behaviour without Foo ? Removing Foo.pm is not an option. I have some ideas outlined below, but I'd like to get your recommendation. The first solution was to reset @INC = (); so that require won't find Foo. This seems to be good with one minor problem. Just before require Foo; I have require Bar; and I'd like to be able to actually use Bar in the same code. I thought of overriding the built in require function so it will selectively either throw an error message or execute the core behaviour. That is on Foo it will throw an error message while on the rest, including Bar it will do the work. According to the Cookbook (2nd) I cannot override require as of 5.8.1. I am using 5.8.4 right now and tried 1) use ex::override got: require cannot be overridden because it doesn't have a prototype at override.pl line 3 2) use Function::Override; got: Cannot override the non-overridable builtin 'require' 3) rolled my own override using use subs qw(require); and the example code from perldoc -f require This seems to be working. So I am a bit confused for why 1 and 2 are not working while using my own code does. In general I'd like to get your opinion on how to mock unsuccessful require. thanks Gabor