line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Code::TidyAll::Cache; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
187
|
use strict; |
|
27
|
|
|
|
|
63
|
|
|
27
|
|
|
|
|
764
|
|
4
|
27
|
|
|
27
|
|
136
|
use warnings; |
|
27
|
|
|
|
|
57
|
|
|
27
|
|
|
|
|
904
|
|
5
|
|
|
|
|
|
|
|
6
|
27
|
|
|
27
|
|
13711
|
use Digest::SHA qw(sha1_hex); |
|
27
|
|
|
|
|
70501
|
|
|
27
|
|
|
|
|
2178
|
|
7
|
27
|
|
|
27
|
|
7142
|
use Path::Tiny qw(path); |
|
27
|
|
|
|
|
107907
|
|
|
27
|
|
|
|
|
1427
|
|
8
|
27
|
|
|
27
|
|
13274
|
use Specio::Library::Path::Tiny; |
|
27
|
|
|
|
|
3367657
|
|
|
27
|
|
|
|
|
343
|
|
9
|
|
|
|
|
|
|
|
10
|
27
|
|
|
27
|
|
397702
|
use Moo; |
|
27
|
|
|
|
|
281564
|
|
|
27
|
|
|
|
|
186
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.83'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has cache_dir => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => t('Path'), |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get { |
21
|
116
|
|
|
116
|
0
|
2837
|
my ( $self, $key ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
116
|
|
|
|
|
470
|
my $file = $self->_path_for_key($key); |
24
|
116
|
100
|
|
|
|
6037
|
if ( $file->exists ) { |
25
|
31
|
|
|
|
|
870
|
return $file->slurp_raw; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
85
|
|
|
|
|
3139
|
return undef; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub set { |
33
|
79
|
|
|
79
|
0
|
1714
|
my ( $self, $key, $value ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
79
|
|
|
|
|
359
|
my $file = $self->_path_for_key($key); |
36
|
79
|
|
|
|
|
4278
|
$file->parent->mkpath( { mode => 0755 } ); |
37
|
79
|
|
|
|
|
21875
|
$file->spew_raw($value); |
38
|
|
|
|
|
|
|
|
39
|
79
|
|
|
|
|
58136
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub remove { |
43
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $key, $value ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
$self->_path_for_key($key)->remove; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _path_for_key { |
51
|
195
|
|
|
195
|
|
592
|
my ( $self, $key ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
195
|
|
|
|
|
1427
|
my $sig = sha1_hex($key); |
54
|
195
|
|
|
|
|
1401
|
return $self->cache_dir->child( substr( $sig, 0, 1 ), "$sig.dat" ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ABSTRACT: A simple caching engine which stores key/value pairs |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=encoding UTF-8 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 NAME |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Code::TidyAll::Cache - A simple caching engine which stores key/value pairs |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 VERSION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
version 0.83 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SUPPORT |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SOURCE |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHORS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 4 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Jonathan Swartz <swartz@pobox.com> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This software is copyright (c) 2011 - 2022 by Jonathan Swartz. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
102
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The full text of the license can be found in the |
105
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |