Hey everyone,

I was writing unit tests for some code, and needed to mock up a library,
something that I've done many times before.  I usually put my mock libraries
into 't/lib', and then do something like this:

 use lib 't/lib';
 use LWP::Simple; # this is a mocked library

This works pretty well, but sometimes when you have several mocked libraries
for a big suite, it can be tricky to get them loaded in the right order.
Maybe you want to pick and choose which of the mocked libraries you're going
to use for this test.

So I just hacked up mocked.pm, which will only load libraries from t/lib.
The above example would look like:

 use mocked 'LWP::Simple';

This is a bit better, because you know it's only going to look into t/lib.
So you don't run the risk of actually loading the real library, and you
don't pollute @INC for subsequent module loads.  It's also nicely self
documenting.

Anyways, this is a little hack, but it seems useful to me.

Cheers,
Luke

Reply via email to