in reply to Simulating the absence of a module
I would like to pretend that certain modules are not available.
I'm doing something like this for the next version of Regexp::Assemble. In trying to improve the coverage of my test suite, I handled it slightly differently.
I use eval to load modules in the module, and set package variables to 1 or 0 according to whether I succeed or not. From there, I have conditional code that runs one way or another in the module, according to that result.
In the test suite, I can simply use local to override the variable, and the module then thinks that the module is loaded one instant, and then isn't the next, all in the same run.
In the main module:
use vars '$have_Storable'; $have_Storable = do { eval { require Storable; import Storable 'dclone'; }; $@ ? 0 : 1; }; # ... # code predicated on the setting of $have_Storable
Now in the test suite, I test stuff as usual, and to ensure I test both code paths exercised according to whether Storable is loaded or not, I just do something like this:
{ local $Regexp::Assemble::have_Storable = 0; my $orig = Regexp::Assemble->new->add( qw/ dig dug dog / ); my $clone = $orig->clone; is_deeply( $orig, $clone, 'clone path' ); }
If someone else installs my module and they don't have Storable installed, they'll just exercise the same codepath twice. I don't really care about that. But as the module author, I'll see if I mess up when my coverage statistics decline. That's good enough for me.
Another example of the dictum "any computer problem can be solved with another level of indirection".
- another intruder with the mooring in the heart of the Perl
|
|---|