1N/A#!/usr/bin/perl
1N/A# -*- mode: perl; perl-indent-level: 2 -*-
1N/A
1N/Ause lib qw(. ..);
1N/Ause Memoize 0.45 qw(memoize unmemoize);
1N/A# $Memoize::Storable::Verbose = 0;
1N/A
1N/Aeval {require Memoize::Storable};
1N/Aif ($@) {
1N/A print "1..0\n";
1N/A exit 0;
1N/A}
1N/A
1N/Asub i {
1N/A $_[0];
1N/A}
1N/A
1N/Asub c119 { 119 }
1N/Asub c7 { 7 }
1N/Asub c43 { 43 }
1N/Asub c23 { 23 }
1N/Asub c5 { 5 }
1N/A
1N/Asub n {
1N/A $_[0]+1;
1N/A}
1N/A
1N/Aeval {require Storable};
1N/Aif ($@) {
1N/A print "1..0\n";
1N/A exit 0;
1N/A}
1N/A
1N/Aprint "1..4\n";
1N/A
1N/A
1N/Aif (eval {require File::Spec::Functions}) {
1N/A File::Spec::Functions->import();
1N/A} else {
1N/A *catfile = sub { join '/', @_ };
1N/A}
1N/A$tmpdir = $ENV{TMP} || $ENV{TMPDIR} || '/tmp';
1N/A$file = catfile($tmpdir, "storable$$");
1N/A1 while unlink $file;
1N/Atryout('Memoize::Storable', $file, 1); # Test 1..4
1N/A1 while unlink $file;
1N/A
1N/Asub tryout {
1N/A my ($tiepack, $file, $testno) = @_;
1N/A
1N/A tie my %cache => $tiepack, $file
1N/A or die $!;
1N/A
1N/A memoize 'c5',
1N/A SCALAR_CACHE => [HASH => \%cache],
1N/A LIST_CACHE => 'FAULT'
1N/A ;
1N/A
1N/A my $t1 = c5();
1N/A my $t2 = c5();
1N/A print (($t1 == 5) ? "ok $testno\n" : "not ok $testno\n");
1N/A $testno++;
1N/A print (($t2 == 5) ? "ok $testno\n" : "not ok $testno\n");
1N/A unmemoize 'c5';
1N/A 1;
1N/A 1;
1N/A
1N/A # Now something tricky---we'll memoize c23 with the wrong table that
1N/A # has the 5 already cached.
1N/A memoize 'c23',
1N/A SCALAR_CACHE => [HASH => \%cache],
1N/A LIST_CACHE => 'FAULT'
1N/A ;
1N/A
1N/A my $t3 = c23();
1N/A my $t4 = c23();
1N/A $testno++;
1N/A print (($t3 == 5) ? "ok $testno\n" : "not ok $testno\n");
1N/A $testno++;
1N/A print (($t4 == 5) ? "ok $testno\n" : "not ok $testno\n");
1N/A unmemoize 'c23';
1N/A}
1N/A