View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Mark Fowler > Devel-UseFromCommandLineOnly > Devel::UseFromCommandLineOnly



Annotate this POD

View/Report Bugs
Module Version: 1.00   Source  


Devel::UseFromCommandLineOnly - use a module from the command line only


   package Foo;
   use base qw(Devel::UseFromCommandLineOnly);

   # it's okay to use from the command line
   # these examples will work
   perl -MFoo -E 'say "This will work!"'
   perl -MFoo -E 'say "This will work!"'
   echo 'use Foo; use 5.010; say "This will work!' | perl

   # but not from a file or module
   # these examples will die
   echo "use Foo;" > /tmp/; perl /tmp/
   echo "package Bar; use Foo;" > /tmp/; perl -I/tmp -MBar


This module prevents you from loading any subclass of it from anywhere but the command line.

This is most useful for writing development tools that monkeypatch other people's code. These hacks are fine to enable from the command line during development, but you wouldn't want to allow anyone to perminatly install them in any code that they could ship as the hacks could break at any point. See Test::EnhancedIs as a good example of this.

To use it you simply subclass the module:

  package Foo;
  use base qw(Devel::UseFromCommandLineOnly);

This exposes an import routine that checks if you're calling it from a script or module or from the command line and throws an exception if it's the former.

Disabling this module's functionality

The one place that subclasses of this module will be needed to be loaded from within a script that is testing that subclass. In this case it's possible to override this module's behavior:


  use Test::More tests => 1;
  use Foo qw(disable_command_line_checks);
  isa_ok(Foo->new(), "Foo");

End users should NEVER EVER DO THIS. Or, if they do, they're playing with fire and deserve to get burnt...


Written by Mark Fowler <>

Copryright Mark Fowler 2009. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


None known.

Please see for details of how to submit bugs, access the source control for this project, and contact the author.



syntax highlighting: