Subject: | SCALAR_CACHE=>[HASH=>...] and LIST_CACHE=>MERGE broken |
The combination SCALAR_CACHE => [HASH => \%cache], LIST_CACHE => 'MERGE' is broken with 1.03. Memoization still work, but the referenzed cache hash is not used anymore. See the attached test script merge.t: this script works with Memoize 1.02 but fails with version 1.03. (The test script should be suitable for inclusion into the Memoize distribution)
Regards,
Slaven
Subject: | merge.t |
#!/usr/bin/perl
use lib '..';
use Memoize 'memoize';
use Test::More;
plan tests => 8;
my %cache;
my $cacheit_counter;
sub cacheit {
$cacheit_counter++;
"cacheit result";
}
memoize 'cacheit', SCALAR_CACHE => [HASH => \%cache], LIST_CACHE => 'MERGE';
{
my $s = cacheit();
is $s, 'cacheit result', 'scalar context';
is $cacheit_counter, 1, 'function called once';
}
{
my @s = cacheit();
is $s[0], 'cacheit result', 'list context';
is $cacheit_counter, 1, 'function not called';
}
cmp_ok keys %cache, ">", 0, 'cache hash is filled';
is((values(%cache))[0], 'cacheit result', 'expected cached value');
%cache = ();
{
my @s = cacheit();
is $s[0], 'cacheit result', 'list context';
is $cacheit_counter, 2, 'function again called after clearing the cache';
}