B
Belebele
How can I mock a method on a _single_ object (as opposed to mocking
the method on all the objects of a class)? Consider:
package Foo;
{
sub new {
my $class = shift;
return bless {}, $class;
}
sub bar { print "bar\n" }
}
my ($a_foo, $another_foo) = (new Foo(), new Foo());
sub print_something { print "something\n" }
*Foo::bar = *print_something; # I would like to change the behavior
for only $a_foo, but not for $another_foo
$a_foo->bar(); # print_something
$another_foo->bar(); # print_something
Thanks
the method on all the objects of a class)? Consider:
package Foo;
{
sub new {
my $class = shift;
return bless {}, $class;
}
sub bar { print "bar\n" }
}
my ($a_foo, $another_foo) = (new Foo(), new Foo());
sub print_something { print "something\n" }
*Foo::bar = *print_something; # I would like to change the behavior
for only $a_foo, but not for $another_foo
$a_foo->bar(); # print_something
$another_foo->bar(); # print_something
Thanks