blib/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
« blib/lib/Code/TidyAll/CacheModel.pm ↑ Summary blib/lib/Code/TidyAll/Util.pm »
1 package Code::TidyAll::Cache;
2  
3 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 35 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use Path::Tiny qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use Specio::Library::Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 35 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 35 our $VERSION = '0.83';
13  
14 35 has cache_dir => (
15 is => 'ro',
16 isa => t('Path'),
17 required => 1,
18 );
19  
20 sub get {
21 120 ▶ my ( $self, $key ) = @_;
Subroutine get: called CC=2 SCAR=6.9
Pod undocumented
22  
23 120 my $file = $self->_path_for_key($key);
24 120 ▶ if ( $file->exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->exists) { } 31 89 120
25 31 return $file->slurp_raw;
26 }
27 else {
28 89 return undef;
29 }
30 }
31  
32 sub set {
33 83 ▶ my ( $self, $key, $value ) = @_;
Subroutine set: called CC=1 SCAR=0.0
Pod undocumented
34  
35 83 my $file = $self->_path_for_key($key);
36 83 $file->parent->mkpath( { mode => 0755 } );
37 83 $file->spew_raw($value);
38  
39 83 return;
40 }
41  
42 sub remove {
43 0 ▶ my ( $self, $key, $value ) = @_;
Subroutine remove: not called CC=1 SCAR=6.9
Pod undocumented
44  
45 0 $self->_path_for_key($key)->remove;
46  
47 0 return;
48 }
49  
50 sub _path_for_key {
51 203 ▶ my ( $self, $key ) = @_;
Subroutine _path_for_key: called CC=1 SCAR=0.0
52  
53 203 my $sig = sha1_hex($key);
54 203 return $self->cache_dir->child( substr( $sig, 0, 1 ), "$sig.dat" );
55 }
56  
57 35 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
« blib/lib/Code/TidyAll/CacheModel.pm ↑ Summary blib/lib/Code/TidyAll/Util.pm »