line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::Driver::File; |
2
|
|
|
|
|
|
|
$CHI::t::Driver::File::VERSION = '0.61'; |
3
|
2
|
|
|
2
|
|
474
|
use strict; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
5
|
2
|
|
|
2
|
|
429
|
use CHI::Test; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
16
|
|
6
|
2
|
|
|
2
|
|
15
|
use CHI::Test::Util qw(random_string); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
126
|
|
7
|
2
|
|
|
2
|
|
15
|
use CHI::Util qw(fast_catdir unique_id); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
104
|
|
8
|
2
|
|
|
2
|
|
11
|
use File::Basename; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
226
|
|
9
|
2
|
|
|
2
|
|
16
|
use File::Path; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
140
|
|
10
|
2
|
|
|
2
|
|
768
|
use File::Temp qw(tempdir); |
|
2
|
|
|
|
|
18315
|
|
|
2
|
|
|
|
|
104
|
|
11
|
2
|
|
|
2
|
|
17
|
use base qw(CHI::t::Driver); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1558
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $root_dir; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new_cache_options { |
16
|
196
|
|
|
196
|
0
|
397
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
196
|
|
66
|
|
|
654
|
$root_dir ||= tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ); |
19
|
196
|
|
|
|
|
2166
|
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.61'; |
25
|
2
|
|
|
2
|
|
17
|
use Moo; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
22
|
|
26
|
|
|
|
|
|
|
extends 'CHI::Driver::File'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub generate_temporary_filename { |
29
|
2
|
|
|
2
|
0
|
10
|
my ( $self, $dir, $file ) = @_; |
30
|
2
|
|
|
|
|
8
|
return undef; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
package CHI::t::Driver::File::BadTempDriver; |
36
|
|
|
|
|
|
|
$CHI::t::Driver::File::BadTempDriver::VERSION = '0.61'; |
37
|
2
|
|
|
2
|
|
1047
|
use Moo; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
9
|
|
38
|
|
|
|
|
|
|
extends 'CHI::Driver::File'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub generate_temporary_filename { |
41
|
2
|
|
|
2
|
0
|
9
|
my ( $self, $dir, $file ) = @_; |
42
|
2
|
|
|
|
|
10
|
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
|
1473
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->{cache} = |
52
|
2
|
|
|
|
|
9
|
$self->new_cache( driver => '+CHI::t::Driver::File::NoTempDriver' ); |
53
|
2
|
|
|
|
|
26
|
$self->test_simple(); |
54
|
|
|
|
|
|
|
$self->{cache} = |
55
|
2
|
|
|
|
|
839
|
$self->new_cache( driver => '+CHI::t::Driver::File::BadTempDriver' ); |
56
|
2
|
|
|
2
|
|
34
|
throws_ok { $self->test_simple() } qr/error during cache set/; |
|
2
|
|
|
|
|
218
|
|
57
|
2
|
|
|
2
|
|
1040
|
} |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
11
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub test_default_depth : Tests { |
60
|
1
|
|
|
1
|
0
|
804
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
6
|
my $cache = $self->new_cache(); |
63
|
1
|
|
|
|
|
10
|
is( $cache->depth, 2 ); |
64
|
2
|
|
|
2
|
|
723
|
} |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub test_creation_and_deletion : Tests { |
67
|
2
|
|
|
2
|
0
|
1539
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
69
|
my $cache = $self->new_cache(); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
17
|
my ( $key, $value ) = $self->kvpair(); |
72
|
2
|
|
|
|
|
10
|
my $cache_file = $cache->path_to_key($key); |
73
|
2
|
|
|
|
|
43
|
my $namespace_dir = $cache->path_to_namespace(); |
74
|
2
|
|
|
|
|
77
|
ok( !-f $cache_file, "cache file '$cache_file' does not exist before set" ); |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
893
|
$cache->set( $key, $value, 0 ); |
77
|
2
|
|
|
|
|
9
|
ok( !defined $cache->get($key) ); |
78
|
2
|
|
|
|
|
944
|
ok( -f $cache_file, "cache file '$cache_file' exists after set" ); |
79
|
2
|
|
|
|
|
825
|
ok( -d $namespace_dir, "namespace dir '$namespace_dir' exists after set" ); |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
810
|
$cache->remove($key); |
82
|
2
|
|
|
|
|
64
|
ok( !-f $cache_file, |
83
|
|
|
|
|
|
|
"cache file '$cache_file' does not exist after remove" ); |
84
|
2
|
|
|
|
|
813
|
ok( -d $namespace_dir, |
85
|
|
|
|
|
|
|
"namespace dir '$namespace_dir' exists after remove" ); |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
755
|
$cache->clear(); |
88
|
2
|
|
|
|
|
44
|
ok( !-d $namespace_dir, |
89
|
|
|
|
|
|
|
"namespace dir '$namespace_dir' does not exist after clear" ); |
90
|
2
|
|
|
2
|
|
941
|
} |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
10
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub test_root_dir_does_not_exist : Tests { |
93
|
2
|
|
|
2
|
0
|
1735
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
17
|
my $parent_dir = |
96
|
|
|
|
|
|
|
tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ); |
97
|
2
|
|
|
|
|
1262
|
my $non_existent_root = fast_catdir( $parent_dir, unique_id() ); |
98
|
2
|
|
|
|
|
55
|
ok( !-d $non_existent_root, "$non_existent_root does not exist" ); |
99
|
2
|
|
|
|
|
855
|
my $cache = $self->new_cache( root_dir => $non_existent_root ); |
100
|
2
|
|
|
|
|
12
|
ok( !defined( $cache->get('foo') ), 'miss' ); |
101
|
2
|
|
|
|
|
809
|
$cache->set( 'foo', 5 ); |
102
|
2
|
|
|
|
|
12
|
is( $cache->get('foo'), 5, 'hit' ); |
103
|
2
|
|
|
|
|
860
|
ok( -d $non_existent_root, "$non_existent_root exists after set" ); |
104
|
2
|
|
|
2
|
|
816
|
} |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub test_ignore_bad_namespaces : Tests { |
107
|
2
|
|
|
2
|
0
|
1513
|
my $self = shift; |
108
|
2
|
|
|
|
|
14
|
my $cache = |
109
|
|
|
|
|
|
|
$self->new_cleared_cache( root_dir => |
110
|
|
|
|
|
|
|
tempdir( "chi-driver-file-XXXX", TMPDIR => 1, CLEANUP => 1 ) ); |
111
|
|
|
|
|
|
|
|
112
|
2
|
|
|
|
|
9
|
foreach my $dir ( ".etc", "+2eetd", 'a@b', 'a+40c', "plain" ) { |
113
|
10
|
|
|
|
|
1240
|
mkpath( join( "/", $cache->root_dir, $dir ) ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
cmp_set( |
116
|
2
|
|
|
|
|
82
|
[ $cache->get_namespaces ], |
117
|
|
|
|
|
|
|
[ '.etd', 'a@c', 'plain' ], |
118
|
|
|
|
|
|
|
'only valid dirs shown as namespaces' |
119
|
|
|
|
|
|
|
); |
120
|
2
|
|
|
2
|
|
762
|
} |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
10
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub test_default_discard : Tests { |
123
|
2
|
|
|
2
|
0
|
1430
|
my $self = shift; |
124
|
2
|
|
|
|
|
15
|
my $cache = $self->new_cleared_cache( is_size_aware => 1 ); |
125
|
2
|
|
|
|
|
43
|
is( $cache->discard_policy, 'arbitrary' ); |
126
|
2
|
|
|
2
|
|
605
|
} |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |