lib/Code/TidyAll/Cache.pm

filter: Statementstmt 91.8% 34 / 37 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 3 totaltotal 86.5% 45 / 52 CC 2 SCAR 2.4
CC
2
Cov
92%
get
2.0
remove
2.0
BEGIN
1.0
CRAP 1.3
« t/lib/TestHelper/Plugin/RepeatFoo.pm ↑ Summary blib/lib/Code/TidyAll/Util.pm »
1 package Code::TidyAll::Cache;
2  
3 58 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 58 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 58 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 58 ▶use Path::Tiny qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 58 ▶use Specio::Library::Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 58 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 58 our $VERSION = '0.85';
13  
14 58 has cache_dir => (
15 is => 'ro',
16 isa => t('Path'),
17 required => 1,
18 );
19  
20 139 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod undocumented
21 139 my ( $self, $key ) = @_;
22  
23 139 my $file = $self->_path_for_key($key);
24 139 ▶ if ( $file->exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->exists) { } 43 96 139
25 43 return $file->slurp_raw;
26 }
27 else {
28 96 return undef;
29 }
30 }
31  
32 90 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod undocumented
33 90 my ( $self, $key, $value ) = @_;
34  
35 90 my $file = $self->_path_for_key($key);
36 90 $file->parent->mkpath( { mode => 0755 } );
37 90 $file->spew_raw($value);
38  
39 90 return;
40 }
41  
42 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my ( $self, $key, $value ) = @_;
44  
45 0 $self->_path_for_key($key)->remove;
46  
47 0 return;
48 }
49  
50 229 ▶sub _path_for_key {
Subroutine _path_for_key: called CC=1 SCAR=0.0
51 229 my ( $self, $key ) = @_;
52  
53 229 my $sig = sha1_hex($key);
54 229 return $self->cache_dir->child( substr( $sig, 0, 1 ), "$sig.dat" );
55 }
56  
57 58 1;
58  
59 # ABSTRACT: A simple caching engine which stores key/value pairs
60  
61 __END__
« t/lib/TestHelper/Plugin/RepeatFoo.pm ↑ Summary blib/lib/Code/TidyAll/Util.pm »