line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Dir::Dumper::DigestCache::FS; |
2
|
|
|
|
|
|
|
$File::Dir::Dumper::DigestCache::FS::VERSION = '0.6.5'; |
3
|
2
|
|
|
2
|
|
91774
|
use warnings; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
459
|
use autodie; |
|
2
|
|
|
|
|
15556
|
|
|
2
|
|
|
|
|
11
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12689
|
use parent 'File::Dir::Dumper::Base'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
137
|
use 5.012; |
|
2
|
|
|
|
|
10
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
480
|
use Class::XSAccessor accessors => { _path => '_path', }; |
|
2
|
|
|
|
|
2394
|
|
|
2
|
|
|
|
|
17
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
453
|
use File::Basename qw/ dirname /; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
224
|
|
14
|
2
|
|
|
2
|
|
16
|
use File::Spec (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
15
|
2
|
|
|
2
|
|
12
|
use File::Path 2.00 qw/ make_path /; |
|
2
|
|
|
|
|
49
|
|
|
2
|
|
|
|
|
94
|
|
16
|
2
|
|
|
2
|
|
500
|
use JSON::MaybeXS (); |
|
2
|
|
|
|
|
5778
|
|
|
2
|
|
|
|
|
933
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _init |
20
|
|
|
|
|
|
|
{ |
21
|
2
|
|
|
2
|
|
7
|
my ( $self, $args ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $basepath = $args->{params}->{path} |
24
|
2
|
50
|
|
|
|
9
|
or die "path not specified as a parameter!"; |
25
|
2
|
|
|
|
|
31
|
$self->_path( File::Spec->catdir( $basepath, 'digests-cache-dir' ) ); |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
6
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _slurp |
32
|
|
|
|
|
|
|
{ |
33
|
7
|
|
|
7
|
|
132
|
my $filename = shift; |
34
|
|
|
|
|
|
|
|
35
|
7
|
50
|
|
|
|
17
|
open my $in, '<', $filename |
36
|
|
|
|
|
|
|
or die "Cannot open '$filename' for slurping - $!"; |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
|
|
719
|
local $/; |
39
|
7
|
|
|
|
|
170
|
my $contents = <$in>; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
|
|
35
|
close($in); |
42
|
|
|
|
|
|
|
|
43
|
7
|
|
|
|
|
463
|
return $contents; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_digests |
47
|
|
|
|
|
|
|
{ |
48
|
6
|
|
|
6
|
1
|
520
|
my ( $self, $args ) = @_; |
49
|
6
|
|
|
|
|
14
|
my $mtime = $args->{mtime}; |
50
|
6
|
|
|
|
|
20
|
my $path = File::Spec->catfile( $self->_path, @{ $args->{path} } ); |
|
6
|
|
|
|
|
100
|
|
51
|
6
|
|
|
|
|
16
|
my $cb = $args->{calc_cb}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $update = sub { |
54
|
5
|
|
|
5
|
|
23
|
open my $out, '>', $path; |
55
|
5
|
|
|
|
|
5068
|
$out->print( JSON::MaybeXS->new( canonical => 1 ) |
56
|
|
|
|
|
|
|
->encode( +{ mtime => $mtime, digests => scalar( $cb->() ) } ) |
57
|
|
|
|
|
|
|
); |
58
|
5
|
|
|
|
|
182
|
close $out; |
59
|
|
|
|
|
|
|
|
60
|
5
|
|
|
|
|
2422
|
return; |
61
|
6
|
|
|
|
|
21
|
}; |
62
|
6
|
100
|
|
|
|
132
|
if ( !-f $path ) |
63
|
|
|
|
|
|
|
{ |
64
|
4
|
|
|
|
|
871
|
make_path( dirname($path) ); |
65
|
4
|
|
|
|
|
20
|
$update->(); |
66
|
|
|
|
|
|
|
} |
67
|
6
|
|
|
|
|
15
|
while (1) |
68
|
|
|
|
|
|
|
{ |
69
|
7
|
|
|
|
|
39
|
my $json = |
70
|
|
|
|
|
|
|
JSON::MaybeXS->new( canonical => 1 )->decode( _slurp($path) ); |
71
|
7
|
100
|
|
|
|
40
|
if ( $json->{mtime} == $mtime ) |
72
|
|
|
|
|
|
|
{ |
73
|
6
|
|
|
|
|
67
|
return $json->{digests}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else |
76
|
|
|
|
|
|
|
{ |
77
|
1
|
|
|
|
|
4
|
$update->(); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
die "Bug"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; # End of File::Dir::Dumper |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |