Returns an object that will mock subroutines in the specified $package.
If there is no $VERSION defined in $package, the module will be automatically loaded. You can override this behaviour by setting the no_auto option:
|get_package()||Returns the target package name for the mocked subroutines|
|is_mocked($subroutine)||Returns a boolean value indicating whether or not the subroutine is currently mocked|
|mock($subroutine => \&coderef)||
Temporarily replaces one or more subroutines in the mocked module. A subroutine
can be mocked with a code reference or a scalar. A scalar will be recast as a
subroutine that returns the scalar.
The following statements are equivalent:
The following statements are in fact equivalent:
However, undef is a special case. If you mock a subroutine with undef it will install an empty subroutine
rather than a subroutine that returns undef:
You can call mock() for the same subroutine many times, but when you call unmock(), the original subroutine is restored (not the last mocked instance).
If you are trying to mock a subroutine exported from another module, this may not behave as you initialy would expect, since Test::MockModule is only mocking at the target module, not anything importing that module. If you mock the local package, or use a fully qualified function name, you will get the behavior you desire:
If you are trying to mock a subroutine that was exported into a module that youre trying to test, rather than mocking the subroutine in its originating module, you can instead mock it in the module you are testing:
|original($subroutine)||Returns the original (unmocked) subroutine|
|unmock($subroutine [, ...])||Restores the original $subroutine. You can specify a list of subroutines to unmock() in one go.|
|unmock_all()||Restores all the subroutines in the package that were mocked. This is automatically called when all Test::MockObject objects for the given package go out of scope.|
Current Maintainer: Geoff Franks <email@example.com>
Original Author: Simon Flack <simonflk _AT_ cpan.org>
Copyright 2004 Simon Flack <simonflk _AT_ cpan.org>. All rights reserved
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
|perl v5.20.3||TEST::MOCKMODULE (3)||2016-04-03|