The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


mocked - use mocked libraries in unit tests


  # use a fake LWP::Simple for testing from t/lib/LWP/
  use mocked 'LWP::Simple';
  my $text = get($url);

  # use a fake WWW::Mechanize for testing from t/mock-libs/WWW/
  use mocked [qw(WWW::Mechanize t/mock-libs)];


Often during unit testing, you may find the need to use mocked libraries to test edge cases, or prevent unit tests from using slow or external code.

This is where mocking libraries can help.

When you mock a library, you are creating a fake one that will be used in place of the real one. The code can do as much or as little as is needed.

Use as a safety measure (be sure you're actually using the mocked module), and as a way to document the tests for future maintainers.



The real @INC that we are over-ridding is stored here while we are loading the mocked library.



With a package name, this function will ensure that the module you specify is loaded from t/lib.

You can also pass an array reference containing the package name and a directory from which to load it from.


Luke Closs, <cpan at> Scott McWhirter, <kungfuftr at>


Ingy döt net, for


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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 112:

Non-ASCII character seen before =encoding in 'döt'. Assuming UTF-8