Create a gist now

Instantly share code, notes, and snippets.

use Test::More;
use Test::Mock::Guard qw(mock_guard);
{
package Some::Class;
sub new { bless {} => shift }
sub foo { "foo" }
};
my $o = Some::Class->new;
is $o->foo, 'foo';
{
my $g1 = mock_guard('Some::Class' => +{ foo => sub { 'xxx' } });
is $o->foo, 'xxx';
my $g2 = mock_guard('Some::Class' => +{ foo => sub { 'yyy' } });
is $o->foo, 'yyy';
undef $g2;
};
is $o->foo, 'foo';
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment