blib/lib/Tie/CacheRedisDB.pm

filter: Statementstmt 29.6% 19 / 64 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 30.0% 6 / 20 Podpod 0.0% 0 / 2 totaltotal 22.7% 25 / 110 CC 10 SCAR 30.8
CC
10
Cov
23%
TIEHASH
72.0
_check_dirty
6.0
UNTIE
6.0
CRAP 21.7
↑ Summary
1 package Tie::CacheRedisDB;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our $VERSION = '1.0.1';
7  
8 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Cache::RedisDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub TIEHASH {
Subroutine TIEHASH: not called CC=8 SCAR=42.8
13 0 my ($self, $addr, $args) = @_;
14  
15 # Don't want to be crazy strict, but at least something which implies they know how this works.
16 0 my $whatsit = reftype $args;
17  
18 0 ▶ croak 'Must supply a lookup element' unless defined $addr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $addr 0 0 0
19 0 ▶ croak 'Arguments must be supplied as a hash reference.'
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $whatsit or ($whatsit // "") eq "HASH" 0 0 0
Condition0%0/5
not defined $whatsit or ($whatsit // "") eq "HASH"
l!l&&r!l&&!r
000
$whatsit // ""
l!l
00
MC/DC0%0/2
not defined $whatsit or ($whatsit // "") eq "HASH"
not defined $whatsit $whatsit
Truth table0%0/3
not(A) or B
A= not defined $whatsitB= $whatsit
ABresult
1X1
011
000
20 unless (not defined $whatsit)
21 or (($whatsit // '') eq 'HASH');
22  
23 0 ▶ my $where = [$args->{namespace} // "TIECACHEREDISDB", $addr];
Condition0%0/2
$args->{"namespace"} // "TIECACHEREDISDB"
l!l
00
MC/DC0%0/1
$args->{"namespace"} // "TIECACHEREDISDB"
$args->{"namespace"}
Truth table0%0/2
A
A= $args->{"namespace"}
Aresult
11
00
24  
25 my $node = {
26 EXP_SECONDS => $args->{expiry},
27 0 ▶ CAN_MISS => $args->{can_miss} // 2,
Condition0%0/4
$args->{"can_miss"} // 2
l!l
00
"Cache::RedisDB"->get(@$where) // {}
l!l
00
MC/DC0%0/1
$args->{"can_miss"} // 2
$args->{"can_miss"}
MC/DC0%0/1
"Cache::RedisDB"->get(@$where) // {}
"Cache::RedisDB"->get(@$where)
Truth table0%0/2
A
A= $args->{"can_miss"}
Aresult
11
00
Truth table0%0/2
A
A= "Cache::RedisDB"->get(@$where)
Aresult
11
00
28 DIRTY => 0,
29 DEL_ON_UNTIE => 0,
30 WHERE => $where,
31 DATA => Cache::RedisDB->get(@$where) // {},
32 };
33  
34 0 return bless $node, $self;
35 }
36  
37 0 ▶sub FETCH {
Subroutine FETCH: not called CC=1 SCAR=6.9
38 0 my ($self, $key) = @_;
39  
40 0 return $self->{DATA}->{$key};
41 }
42  
43 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
44 0 my ($self, $key, $val) = @_;
45  
46 0 $self->{DATA}->{$key} = $val;
47 0 return $self->_check_dirty;
48 }
49  
50 0 ▶sub _check_dirty {
Subroutine _check_dirty: not called CC=2 SCAR=17.9
51 0 my $self = shift;
52  
53 0 $self->{DIRTY} += 1;
54 $self->sync
55 0 ▶ if ($self->{DIRTY} > $self->{CAN_MISS}); # Need to hit the backing store
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DIRTY"} > $self->{"CAN_MISS"} 0 0 0
56  
57 0 return;
58 }
59  
60 0 ▶sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
61 0 my ($self, $key) = @_;
62  
63 0 my $val = delete $self->{DATA}->{$key};
64 0 $self->_check_dirty;
65  
66 0 return $val;
67 }
68  
69 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
70 0 my $self = shift;
71  
72 0 $self->{DATA} = {};
73 0 return $self->sync;
74  
75 }
76  
77 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
78 0 my ($self, $key) = @_;
79  
80 0 return exists $self->{DATA}->{$key};
81 }
82  
83 0 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: not called CC=1 SCAR=6.9
84 0 my $self = shift;
85  
86 0 return each %{$self->{DATA}};
87 }
88  
89 0 ▶sub NEXTKEY {
Subroutine NEXTKEY: not called CC=1 SCAR=6.9
90 0 my $self = shift;
91  
92 0 return each %{$self->{DATA}};
93 }
94  
95 0 ▶sub SCALAR {
Subroutine SCALAR: not called CC=1 SCAR=6.9
96 0 my $self = shift;
97  
98 0 return scalar %{$self->{DATA}};
99 }
100  
101 0 ▶sub UNTIE {
Subroutine UNTIE: not called CC=2 SCAR=17.9
102 0 my $self = shift;
103  
104 return ($self->{DEL_ON_UNTIE})
105 0 ▶ ? Cache::RedisDB->del(@{$self->{WHERE}})
Branch: 1 branch
BranchTrueFalseTotal
$self->{'DEL_ON_UNTIE'} ? : 0 0 0
106 : $self->sync;
107 }
108  
109 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
110 0 my $self = shift;
111  
112 0 return $self->UNTIE;
113 }
114  
115 0 ▶sub sync {
Subroutine sync: not called CC=1 SCAR=6.9
Pod undocumented
116 0 my $self = shift;
117  
118 0 Cache::RedisDB->set(@{$self->{WHERE}}, $self->{DATA}, $self->{EXP_SECONDS});
119  
120 0 return $self->{DIRTY} = 0; # Since we've sync'd it's not longer dirty,
121 }
122  
123 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
124 0 my $self = shift;
125  
126 0 return $self->{DEL_ON_UNTIE} = 1;
127 }
128  
129 1 1;
130 __END__
↑ Summary