zigorou/p5-test-mock-guard — pull request #6 by hitode909 (2014-01-12 10:01:47+00:00)
Title: Fix when mock instance and call as class method

# Problem
1. Mock an instance's method.
2. Call as a class method.
3. It dies.

## test case
```perl
use strict;
use warnings;a

use Test::More;
use Test::Mock::Guard qw(mock_guard);

package Some::Class;
sub new { bless {} => shift }
sub foo { "foo" }

package main;

my $obj = Some::Class->new;

is $obj->foo, 'foo';
is Some::Class::foo, 'foo';

{
my $guard = mock_guard($obj, { foo => sub { "bar" } } );
is $obj->foo, 'bar';
is Some::Class::foo($obj), 'bar';
is Some::Class::foo, 'foo';
};

is $obj->foo, 'foo';
is +Some::Class::foo, 'foo';

done_testing;
```

## output
```
t/10_instance_and_class.t .. 1/? Use of uninitialized value $klass in hash element at /Users/hitode909/co/p5-test-mock-guard/blib/lib/Test/Mock/Guard.pm line 208.
Use of uninitialized value $refaddr in exists at /Users/hitode909/co/p5-test-mock-guard/blib/lib/Test/Mock/Guard.pm line 208.
Use of uninitialized value $klass in hash element at /Users/hitode909/co/p5-test-mock-guard/blib/lib/Test/Mock/Guard.pm line 213.
Use of uninitialized value in subroutine entry at /Users/hitode909/co/p5-test-mock-guard/blib/lib/Test/Mock/Guard.pm line 213.
Can't use string ("") as a subroutine ref while "strict refs" in use at /Users/hitode909/co/p5-test-mock-guard/blib/lib/Test/Mock/Guard.pm line 213.
# Tests were run but no plan was declared and done_testing() was not seen.
t/10_instance_and_class.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
All 4 subtests passed
```

# Solution

This pull request changed to pass the original method to `_mocked` function and call it.