10 use Test::More tests => 28;
15 open my $h, '<', File::Spec->catfile($dir, $key) or return;
19 sub exists { my ($key, $dir) = @_; return -f File::Spec->catfile($dir, $key) }
21 my $directory = File::Spec->catdir(File::Spec->updir, 'lib');
23 tie my %hash, 'Tie::Memoize', \&slurp, $directory, \&exists,
24 { fake_file1 => 123, fake_file2 => 45678 },
25 { 'strict.pm' => 0, known_to_exist => 1 };
27 ok(not exists $hash{'strict.pm'});
28 ok(exists $hash{known_to_exist});
29 ok($hash{fake_file2} eq 45678);
30 ok($hash{fake_file1} eq 123);
31 ok(exists $hash{known_to_exist});
32 ok(not exists $hash{'strict.pm'});
33 ok(not defined $hash{fake_file3});
34 ok(not defined $hash{known_to_exist});
35 ok(not exists $hash{known_to_exist});
36 ok(not exists $hash{'strict.pm'});
37 my $c = slurp('constant.pm', $directory);
39 ok($hash{'constant.pm'} eq $c);
40 ok($hash{'constant.pm'} eq $c);
41 ok(not exists $hash{'strict.pm'});
42 ok(exists $hash{'blib.pm'});
46 tie %hash, 'Tie::Memoize', \&slurp, $directory;
48 ok(exists $hash{'strict.pm'}, 'existing file');
49 ok(not exists $hash{fake_file2});
50 ok(not exists $hash{fake_file1});
51 ok(not exists $hash{known_to_exist});
52 ok(exists $hash{'strict.pm'}, 'existing file again');
53 ok(not defined $hash{fake_file3});
54 ok(not defined $hash{known_to_exist});
55 ok(not exists $hash{known_to_exist});
56 ok(exists $hash{'strict.pm'}, 'existing file again');
57 ok($hash{'constant.pm'} eq $c);
58 ok($hash{'constant.pm'} eq $c);
59 ok(exists $hash{'strict.pm'}, 'existing file again');
60 ok(exists $hash{'blib.pm'}, 'another existing file');