Test::MockObject - Not a subroutine reference

The perl module Test::MockObject can be used to create fake objects with specific methods. If you try to mock a method but pass something that is not a method reference, it will give the following error:

Not a subroutine reference at /usr/share/perl5/Test/MockObject.pm line 234.

This is because you did something like this:

my $mock = Test::MockObject->new();
$mock->mock(some_method => 'some_value');  # Wrong

You can use mock only with a subroutine, or use set_always with a value:

my $mock = Test::MockObject->new();
$mock->mock(some_method => sub { return 'some_value'; });
$mock->set_always(some_method => 'some_value');