Re: [PATCH 5.6.1] OS2 Configure
[p5sagit/p5-mst-13.2.git] / lib / Memoize / t / tie_storable.t
CommitLineData
a0cb3900 1#!/usr/bin/perl
2# -*- mode: perl; perl-indent-level: 2 -*-
3
4use lib qw(. ..);
5use Memoize 0.45 qw(memoize unmemoize);
6# use Memoize::Storable;
7# $Memoize::Storable::Verbose = 0;
8
9sub i {
10 $_[0];
11}
12
13sub c119 { 119 }
14sub c7 { 7 }
15sub c43 { 43 }
16sub c23 { 23 }
17sub c5 { 5 }
18
19sub n {
20 $_[0]+1;
21}
22
23eval {require Storable};
24if ($@) {
25 print "1..0\n";
26 exit 0;
27}
28
29print "1..4\n";
30
31
32if (eval {require File::Spec::Functions}) {
33 File::Spec::Functions->import();
34} else {
35 *catfile = sub { join '/', @_ };
36}
37$tmpdir = $ENV{TMP} || $ENV{TMPDIR} || '/tmp';
38$file = catfile($tmpdir, "storable$$");
39unlink $file;
40tryout('Memoize::Storable', $file, 1); # Test 1..4
41unlink $file;
42
43sub tryout {
44 my ($tiepack, $file, $testno) = @_;
45
46
47 memoize 'c5',
48 SCALAR_CACHE => ['TIE', $tiepack, $file],
49 LIST_CACHE => 'FAULT'
50 ;
51
52 my $t1 = c5();
53 my $t2 = c5();
54 print (($t1 == 5) ? "ok $testno\n" : "not ok $testno\n");
55 $testno++;
56 print (($t2 == 5) ? "ok $testno\n" : "not ok $testno\n");
57 unmemoize 'c5';
58 1;
59 1;
60
61 # Now something tricky---we'll memoize c23 with the wrong table that
62 # has the 5 already cached.
63 memoize 'c23',
64 SCALAR_CACHE => ['TIE', $tiepack, $file],
65 LIST_CACHE => 'FAULT'
66 ;
67
68 my $t3 = c23();
69 my $t4 = c23();
70 $testno++;
71 print (($t3 == 5) ? "ok $testno\n" : "not ok $testno\n");
72 $testno++;
73 print (($t4 == 5) ? "ok $testno\n" : "not ok $testno\n");
74 unmemoize 'c23';
75}
76