NetApp/Filer/TimeoutCache.pm

filter: Statementstmt 40.0% 18 / 45 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.4% 5 / 11 Podpod n/a totaltotal 37.1% 23 / 62 CC 4 SCAR 14.7
CC
4
Cov
35%
EXISTS
12.0
TIEHASH
6.0
STORE
2.0
CRAP 4.4
« NetApp/Snapshot/Delta.pm ↑ Summary NetApp/Snapshot/Schedule.pm »
1  
2 package NetApp::Filer::TimeoutCache;
3  
4 7 our $VERSION = '500.002';
5 7 $VERSION = eval $VERSION; ## no critic: StringyEval
6  
7 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Params::Validate qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub TIEHASH {
Subroutine TIEHASH: not called CC=2 SCAR=17.9
14  
15 0 my $class = shift;
16 0 my (%args) = validate( @_, {
17 lifetime => { type => SCALAR,
18 regex => qr{^\d+$} },
19 });
20  
21 0 ▶ if ( $args{lifetime} <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"lifetime"} <= 0) 0 0 0
22 0 croak("Invalid argument: lifetime must be a positive integer\n");
23 }
24  
25 my %self = (
26 lifetime => $args{lifetime},
27 0 cache => {},
28 );
29  
30 0 return bless \%self => $class;
31  
32 }
33  
34 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
35  
36 0 my $self = shift;
37 0 my ($key, $value) = @_;
38  
39 $self->{cache}->{$key} = {
40 expiration => $self->{lifetime} + time,
41 0 value => $value,
42 };
43  
44 0 return $value;
45  
46 }
47  
48 0 ▶sub FETCH {
Subroutine FETCH: not called CC=1 SCAR=6.9
49 0 my $self = shift;
50 0 my $key = shift;
51 0 return $self->{cache}->{$key}->{value};
52 }
53  
54 0 ▶sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
55 0 my $self = shift;
56 0 my $key = shift;
57 0 my $value = $self->{cache}->{$key}->{value};
58 0 delete $self->{cache}->{$key};
59 0 return $value;
60 }
61  
62 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
63 0 return shift->{cache} = {};
64 }
65  
66 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=3 SCAR=24.8
67  
68 0 my $self = shift;
69 0 my $key = shift;
70  
71 0 ▶ if ( not exists $self->{cache}->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"cache"}{$key}) 0 0 0
72 0 return 0;
73 }
74  
75 0 my $data = $self->{cache}->{$key};
76  
77 0 ▶ if ( $data->{expiration} > time ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{'expiration'} > time) { } 0 0 0
78 0 return 1;
79 } else {
80 0 return 0;
81 }
82  
83 }
84  
85 7 1;
« NetApp/Snapshot/Delta.pm ↑ Summary NetApp/Snapshot/Schedule.pm »