|
I am trying to mock FooModule1::foo1()
foo1() is called by FooModule2::foo2().
foo1() will mock when coded as follows:
sub foo2
{
...
FooModule1::foo1();
return;
}
but not with out the package name:
sub foo2
{
...
foo1();
return;
}
When no package name is specified, then the real foo1() is called.
Here is code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Test::More qw(no_plan);
use Test::MockModule;
use FooModule1;
use FooModule2;
my $module = 'FooModule1';
use_ok ($module) or exit;
can_ok ($module, 'foo1' );
{
my $foo1Output;
my $lib = Test::MockModule->new('FooModule1');
$lib->mock ('foo1', sub {$fooOutput = shift; print "Is this mine?\n";} );
FooModule2::foo2();
print "Test: $foo1Output";
}
Please help. Thanks!
|