line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::Driver::File; |
2
|
|
|
|
|
|
|
$CHI::t::Driver::File::VERSION = '0.60'; |
3
|
2
|
|
|
2
|
|
352
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
47
|
|
5
|
2
|
|
|
2
|
|
295
|
use CHI::Test; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
6
|
2
|
|
|
2
|
|
10
|
use CHI::Test::Util qw(random_string); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
101
|
|
7
|
2
|
|
|
2
|
|
9
|
use CHI::Util qw(fast_catdir unique_id); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
75
|
|
8
|
2
|
|
|
2
|
|
8
|
use File::Basename; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
117
|
|
9
|
2
|
|
|
2
|
|
8
|
use File::Path; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
10
|
2
|
|
|
2
|
|
794
|
use File::Temp qw(tempdir); |
|
2
|
|
|
|
|
23339
|
|
|
2
|
|
|
|
|
121
|
|
11
|
2
|
|
|
2
|
|
15
|
use base qw(CHI::t::Driver); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1419
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $root_dir; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new_cache_options { |
16
|
196
|
|
|
196
|
0
|
266
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
196
|
|
66
|
|
|
552
|
$root_dir ||= tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ); |
19
|
196
|
|
|
|
|
2153
|
return ( $self->SUPER::new_cache_options(), root_dir => $root_dir ); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
package CHI::t::Driver::File::NoTempDriver; |
24
|
|
|
|
|
|
|
$CHI::t::Driver::File::NoTempDriver::VERSION = '0.60'; |
25
|
2
|
|
|
2
|
|
12
|
use Moo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
26
|
|
|
|
|
|
|
extends 'CHI::Driver::File'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub generate_temporary_filename { |
29
|
2
|
|
|
2
|
0
|
6
|
my ( $self, $dir, $file ) = @_; |
30
|
2
|
|
|
|
|
6
|
return undef; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
package CHI::t::Driver::File::BadTempDriver; |
36
|
|
|
|
|
|
|
$CHI::t::Driver::File::BadTempDriver::VERSION = '0.60'; |
37
|
2
|
|
|
2
|
|
1041
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
6
|
|
38
|
|
|
|
|
|
|
extends 'CHI::Driver::File'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub generate_temporary_filename { |
41
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $dir, $file ) = @_; |
42
|
2
|
|
|
|
|
7
|
return "/dir/does/not/exist/$file"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Test that we can override how temporary files are generated |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
sub test_generate_temporary_filename : Tests { |
49
|
2
|
|
|
2
|
0
|
537
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
15
|
$self->{cache} = |
52
|
|
|
|
|
|
|
$self->new_cache( driver => '+CHI::t::Driver::File::NoTempDriver' ); |
53
|
2
|
|
|
|
|
78
|
$self->test_simple(); |
54
|
2
|
|
|
|
|
679
|
$self->{cache} = |
55
|
|
|
|
|
|
|
$self->new_cache( driver => '+CHI::t::Driver::File::BadTempDriver' ); |
56
|
2
|
|
|
2
|
|
70
|
throws_ok { $self->test_simple() } qr/error during cache set/; |
|
2
|
|
|
|
|
134
|
|
57
|
2
|
|
|
2
|
|
822
|
} |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub test_default_depth : Tests { |
60
|
1
|
|
|
1
|
0
|
242
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
7
|
my $cache = $self->new_cache(); |
63
|
1
|
|
|
|
|
13
|
is( $cache->depth, 2 ); |
64
|
2
|
|
|
2
|
|
521
|
} |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
7
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub test_creation_and_deletion : Tests { |
67
|
2
|
|
|
2
|
0
|
322
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
10
|
my $cache = $self->new_cache(); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
15
|
my ( $key, $value ) = $self->kvpair(); |
72
|
2
|
|
|
|
|
16
|
my $cache_file = $cache->path_to_key($key); |
73
|
2
|
|
|
|
|
37
|
my $namespace_dir = $cache->path_to_namespace(); |
74
|
2
|
|
|
|
|
54
|
ok( !-f $cache_file, "cache file '$cache_file' does not exist before set" ); |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
850
|
$cache->set( $key, $value, 0 ); |
77
|
2
|
|
|
|
|
17
|
ok( !defined $cache->get($key) ); |
78
|
2
|
|
|
|
|
731
|
ok( -f $cache_file, "cache file '$cache_file' exists after set" ); |
79
|
2
|
|
|
|
|
804
|
ok( -d $namespace_dir, "namespace dir '$namespace_dir' exists after set" ); |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
714
|
$cache->remove($key); |
82
|
2
|
|
|
|
|
40
|
ok( !-f $cache_file, |
83
|
|
|
|
|
|
|
"cache file '$cache_file' does not exist after remove" ); |
84
|
2
|
|
|
|
|
766
|
ok( -d $namespace_dir, |
85
|
|
|
|
|
|
|
"namespace dir '$namespace_dir' exists after remove" ); |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
690
|
$cache->clear(); |
88
|
2
|
|
|
|
|
29
|
ok( !-d $namespace_dir, |
89
|
|
|
|
|
|
|
"namespace dir '$namespace_dir' does not exist after clear" ); |
90
|
2
|
|
|
2
|
|
668
|
} |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub test_root_dir_does_not_exist : Tests { |
93
|
2
|
|
|
2
|
0
|
416
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
14
|
my $parent_dir = |
96
|
|
|
|
|
|
|
tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ); |
97
|
2
|
|
|
|
|
845
|
my $non_existent_root = fast_catdir( $parent_dir, unique_id() ); |
98
|
2
|
|
|
|
|
43
|
ok( !-d $non_existent_root, "$non_existent_root does not exist" ); |
99
|
2
|
|
|
|
|
1050
|
my $cache = $self->new_cache( root_dir => $non_existent_root ); |
100
|
2
|
|
|
|
|
20
|
ok( !defined( $cache->get('foo') ), 'miss' ); |
101
|
2
|
|
|
|
|
855
|
$cache->set( 'foo', 5 ); |
102
|
2
|
|
|
|
|
7
|
is( $cache->get('foo'), 5, 'hit' ); |
103
|
2
|
|
|
|
|
996
|
ok( -d $non_existent_root, "$non_existent_root exists after set" ); |
104
|
2
|
|
|
2
|
|
666
|
} |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
7
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub test_ignore_bad_namespaces : Tests { |
107
|
2
|
|
|
2
|
0
|
374
|
my $self = shift; |
108
|
2
|
|
|
|
|
12
|
my $cache = |
109
|
|
|
|
|
|
|
$self->new_cleared_cache( root_dir => |
110
|
|
|
|
|
|
|
tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ) ); |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
6
|
foreach my $dir ( ".etc", "+2eetd", 'a@b', 'a+40c', "plain" ) { |
113
|
10
|
|
|
|
|
983
|
mkpath( join( "/", $cache->root_dir, $dir ) ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
cmp_set( |
116
|
2
|
|
|
|
|
66
|
[ $cache->get_namespaces ], |
117
|
|
|
|
|
|
|
[ '.etd', 'a@c', 'plain' ], |
118
|
|
|
|
|
|
|
'only valid dirs shown as namespaces' |
119
|
|
|
|
|
|
|
); |
120
|
2
|
|
|
2
|
|
567
|
} |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
10
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub test_default_discard : Tests { |
123
|
2
|
|
|
2
|
0
|
308
|
my $self = shift; |
124
|
2
|
|
|
|
|
12
|
my $cache = $self->new_cleared_cache( is_size_aware => 1 ); |
125
|
2
|
|
|
|
|
20
|
is( $cache->discard_policy, 'arbitrary' ); |
126
|
2
|
|
|
2
|
|
459
|
} |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
6
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |