blob: c6abb507ea645d7f9721aff00876a2dd95d0045f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/usr/bin/perl
use lib '..';
use Memoize;
my $n = 0;
if (-e '.fast') {
print "1..0\n";
exit 0;
}
print "1..11\n";
++$n; print "ok $n\n";
my $READFILE_CALLS = 0;
my $FILE = './TESTFILE';
sub writefile {
my $FILE = shift;
open F, "> $FILE" or die "Couldn't write temporary file $FILE: $!";
print F scalar(localtime), "\n";
close F;
}
sub readfile {
$READFILE_CALLS++;
my $FILE = shift;
open F, "< $FILE" or die "Couldn't write temporary file $FILE: $!";
my $data = <F>;
close F;
$data;
}
memoize 'readfile',
SCALAR_CACHE => ['TIE', 'Memoize::ExpireFile', ],
LIST_CACHE => 'FAULT'
;
++$n; print "ok $n\n";
writefile($FILE);
++$n; print "ok $n\n";
sleep 1;
my $t1 = readfile($FILE);
++$n; print "ok $n\n";
++$n; print ((($READFILE_CALLS == 1) ? '' : 'not '), "ok $n\n");
my $t2 = readfile($FILE);
++$n; print "ok $n\n";
++$n; print ((($READFILE_CALLS == 1) ? '' : 'not '), "ok $n\n");
++$n; print ((($t1 eq $t2) ? '' : 'not '), "ok $n\n");
sleep 2;
writefile($FILE);
my $t3 = readfile($FILE);
++$n; print "ok $n\n";
++$n; print ((($READFILE_CALLS == 2) ? '' : 'not '), "ok $n\n");
++$n; print ((($t1 ne $t3) ? '' : 'not '), "ok $n\n");
END { 1 while unlink 'TESTFILE' }
|