title: How to test missing optional perl modules via the command line perl call
body: <p>I have a test suite with hundreds of tests for a perl module I've yet to release which is a command line interface.  Since it is a command line interface, the tests (until possibly now) are all written to drop code into a template and then call the template script using a system call.</p>
  
  <p>I recently added an optional dependency on a 3rd party module that's not a part of core perl.  I know my module works whether that module is installed or not because I have a computer with it installed and one without and the module works without error in each case.  However, I'd like to be able to write a test to confirm that my module will work when the 3rd party module is absent - and I'd like that test to work even if the 3rd party module <em>is</em> installed, but behave as if it wasn't.</p>
  
  <p>Ideally, I could use the structure I've put in place for testing which makes a system call to a template script.  I know I could write a separate test script that manipulates @INC in the BEGIN block, imports the particular methods that use the module, and call them like a unit test.  But I would like to know if there's a way I can use the test structure I've already got all my other tests using, which is to make a system call.</p>
  
  <p>So is there a way to exclude a module from being imported via a perl command line option?  I've tried -M-Module, but the code <code>use Module</code> still imports the module.</p>
  
  <p>Incidentally, my module uses the 3rd party module inside an eval, which is how I made it optional.</p>