Skip to content

Instantly share code, notes, and snippets.

@cho45
Created September 1, 2011 10:42
Show Gist options
  • Save cho45/1185921 to your computer and use it in GitHub Desktop.
Save cho45/1185921 to your computer and use it in GitHub Desktop.
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