I am developing a suite of Perl scripts and modules that then get deployed on different machines and systems round our company. Some facilities are dependent on a particular module which may or may not be installed on different machines. I have used 'eval' to detect whether or not this module is available.
I've just had a fault report which came down to the fact that the user had not successfully installed the module on his machine (but didn't realise that he hadn't): but the bug in my code was that I did not, in this case, pass the error condition up to the top level, so it was getting lost, and the script was just silently failing to perform part of its function.
In order to investigate it, I disabled the particular module on my machine, and easily found and fixed the problem. But the only way I could think of to disable it, short of uninstalling it, was to rename the file (which I had to do via sudo, of course).
I am now running all of my tests with this module unavailable, and it has thrown up a few other places where I am not handling the situation properly.
But what I now want to do is to write some tests for this condition: but how can I sensibly make this module unavailable temporarily within an automatic test. I really don't want my tests using sudo to move modules out the way (I may be doing other things on the machine at the same time).
Does anybody know a way that I can tell Perl "Do not find this module, wherever I try to 'use' or 'require' it from, for testing purposes"?
I'm running Perl 5.10.0 (on Fedora 12), and using Test::More and TAP::Harness. Some of our installations are running Perl 5.8, so I am willing to use 5.10 features in testing, but not in the code itself.