Subject: | Arg gathering subs should deep copy the args as they are when recorded rather then copying a reference |
Date: | Wed, 31 Oct 2018 12:57:48 -0500 |
To: | <bug-Test-MockObject [...] rt.cpan.org> |
From: | <jbruce [...] blosm.com> |
I think that args provided to mocked methods should be deep copied to
preserve their values at the time. It looks like they are being stored by
reference currently.
This code illustrates the issue:
my $mock = Test::MockObject->new();
$mock->mock('foo', sub{});
My $i = 1;
my %args = (
trackey_thing => 1
);
my $obj = { fake_thing => $mock };
while($i < 5){
$obj->{fake_thing}->foo(\%args);
$args{trackey_thing}++;
$i++;
}
my ($first_call, $first_args) = $mock->next_call();
print $first_args->[1]->{trackey_thing}; // prints 5 because that is the
value of the last iteration
John Bruce
Senior Software Engineer
<http://blosm.com/> b <http://blosm.com/> l <http://blosm.com/> osm.com
424.888.4BEE