Medley/Cache.pm

filter: Statementstmt 80.2% 1071 / 1335 Branchbran 41.1% 292 / 710 Conditioncond 30.3% 20 / 66 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 95.7% 179 / 187 Podpod n/a totaltotal 66.7% 1562 / 2342 CC 399 SCAR 34.8
CC
399
Cov
66%
set
204.0
delete
146.5
get
146.5
CRAP 32.6
« Medley/Logger.pm ↑ Summary Medley/Spawn.pm »
1 package Util::Medley::Cache;
2 2 $Util::Medley::Cache::VERSION = '0.047';
3 2 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use CHI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Path 'remove_tree';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Data::Printer alias => 'pdump';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Kavorka qw(-all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 with 'Util::Medley::Roles::Attributes::Logger';
13  
14 ########################################################
15  
16 =head1 NAME
17  
18 Util::Medley::Cache - Simple caching mechanism.
19  
20 =head1 VERSION
21  
22 version 0.047
23  
24 =cut
25  
26 ########################################################
27  
28 =head1 SYNOPSIS
29  
30 #
31 # positional
32 #
33 $self->set('unittest', 'test1', {foo => bar});
34
35 my $data = $self->get('unitest', 'test1');
36
37 my @keys = $self->getKeys('unittest');
38  
39 $self->delete('unittest', 'test1');
40
41 #
42 # named pair
43 #
44 $self->set(ns => 'unittest',
45 key => 'test1',
46 data => { foo => 'bar' });
47  
48 my $data = $self->get(ns => 'unittest',
49 key => 'test1');
50  
51 my @keys = $self->getKeys(ns => 'unittest');
52  
53 $self->delete(ns => 'unittest',
54 key => 'test1');
55  
56 =cut
57  
58 ########################################################
59  
60 =head1 DESCRIPTION
61  
62 This class provides a thin wrapper around CHI. The caching has 2 levels:
63
64 =over
65  
66 =item * level 1 (memory)
67  
68 =item * level 2 (disk)
69  
70 =back
71  
72 When fetching from the cache, level 1 (L1) is always checked first. If the
73 requested object is not found, it searches the level 2 (L2) cache.
74  
75 The cached data can be an object, reference, or string.
76  
77 All methods confess on error.
78  
79 =cut
80  
81 ########################################################
82  
83 =head1 ATTRIBUTES
84  
85 =head2 rootDir (optional)
86  
87 Location of the L2 file cache.
88  
89 =over
90  
91 =item default
92  
93 $HOME/.util-medley/cache
94  
95 =back
96  
97 =cut
98  
99 2 has rootDir => (
100 is => 'ro',
101 isa => 'Str',
102 lazy => 1,
103 builder => '_buildRootDir'
104 );
105  
106 =head2 enabled (optional)
107  
108 Toggles caching on or off.
109  
110 =over
111  
112 =item default
113  
114 1
115  
116 =back
117  
118 =cut
119  
120 2 has enabled => (
121 is => 'rw',
122 isa => 'Bool',
123 lazy => 1,
124 builder => '_buildEnabled',
125 );
126  
127 =head2 expireSecs (optional)
128  
129 Sets the cache expiration.
130  
131 =over
132  
133 =item default
134  
135 0 (never)
136  
137 =back
138  
139 =cut
140  
141 2 has expireSecs => (
142  
143 # zero = never
144 is => 'rw',
145 isa => 'Int',
146 default => 0,
147 );
148  
149 =head2 ns (optional)
150  
151 Sets the cache namespace.
152  
153 =cut
154  
155 2 has ns => (
156 is => 'rw',
157 isa => 'Str',
158 );
159  
160 =head2 l1Enabled (optional)
161  
162 Toggles the L1 cache on or off.
163  
164 =over
165  
166 =item default
167  
168 1
169  
170 =item env var
171  
172 To disable L1 cache, set MEDLEY_CACHE_L1_DISABLED=1.
173  
174 =back
175  
176 =cut
177  
178 2 has l1Enabled => (
179 is => 'rw',
180 isa => 'Bool',
181 lazy => 1,
182 builder => '_buildL1Enabled',
183 );
184  
185 =head2 l2Enabled (optional)
186  
187 Toggles the L2 cache on or off.
188  
189 =over
190  
191 =item default
192  
193 1
194  
195 =item env var
196  
197 To disable L2 cache, set MEDLEY_CACHE_L2_DISABLED=1.
198  
199 =back
200  
201 =cut
202  
203 2 has l2Enabled => (
204 is => 'rw',
205 isa => 'Bool',
206 lazy => 1,
207 builder => '_buildL2Enabled',
208 );
209  
210 ##########################################################
211  
212 has _chiObjects => (
213 is => 'rw',
214 isa => 'HashRef',
215 32 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
216 2 );
217  
218 has _l1Cache => (
219 is => 'rw',
220 isa => 'HashRef',
221 32 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
222 2 );
223  
224 ##########################################################
225  
226 =head1 METHODS
227  
228 =head2 clear
229  
230 Clears all cache for a given namespace.
231  
232 =over
233  
234 =item usage:
235  
236 clear([$ns])
237
238 clear([ns => $ns])
239  
240 =item args:
241  
242 =over
243  
244 =item ns [Str]
245  
246 The cache namespace.
247  
248 =back
249  
250 =back
251  
252 =cut
253  
254 2 ▶multi method clear (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine clear: called CC=16 SCAR=30.8
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 2 0 2
@_ ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 2 2
if ($slice_length % 2 != 0) 0 2 2
if ($i <= $#_) 1 2 3
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 1 1
exists $_{'ns'} ? : 1 1 2
unless ($____nobble_checks) 0 2 2
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
255  
256 2 ▶ $self->_l1Clear(@_) if $self->l1Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l1Enabled 2 0 2
257 2 ▶ $self->_l2Clear(@_) if $self->l2Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l2Enabled 2 0 2
258  
259 2 return 1;
260 }
261  
262 2 ▶multi method clear (Str $ns?) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine clear: not called CC=10 SCAR=41.9
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ > 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
263  
264 0 my %a;
265 0 ▶ $a{ns} = $ns if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
266
267 0 return $self->clear(%a);
268 }
269  
270 =head2 delete
271  
272 Deletes a cache object.
273  
274 =over
275  
276 =item usage:
277  
278 delete($key, [$ns])
279
280 delete(key => $key, [ns => $ns])
281  
282 =item args:
283  
284 =over
285  
286 =item key [Str]
287  
288 Unique identifier of the cache object.
289  
290 =item ns [Str]
291  
292 The cache namespace.
293  
294 =back
295  
296 =back
297  
298 =cut
299  
300 multi method delete (Str :$key!,
301 2 ▶ Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine delete: called CC=20 SCAR=35.8
Branch: 15 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 5 0 5
@_ ? : 5 0 5
unless ($____nobble_checks) 0 5 5
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 5 5
if ($slice_length % 2 != 0) 0 5 5
if ($i <= $#_) 7 5 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 7 7
exists $_{'key'} ? : 5 0 5
unless ($____nobble_checks) 0 5 5
if (exists $_{"key"}) 0 0 0
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'ns'} ? : 2 3 5
unless ($____nobble_checks) 0 5 5
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
500
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
302  
303 5 ▶ $self->_l1Delete(@_) if $self->l1Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l1Enabled 5 0 5
304 4 ▶ $self->_l2Delete(@_) if $self->l1Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l1Enabled 4 0 4
305  
306 4 return 1;
307 }
308  
309 multi method delete (Str $key,
310 2 ▶ Str $ns?) {
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine delete: not called CC=15 SCAR=49.9
Branch: 13 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ < 1 0 0 0
if @_ > 2 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 1 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 1) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
311  
312 0 my %a;
313 0 $a{key} = $key;
314 0 ▶ $a{ns} = $ns if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
315  
316 0 return $self->delete(%a);
317 }
318  
319 =head2 destroy
320  
321 Deletes L1 cache and removes L2 from disk completely.
322  
323 =over
324  
325 =item usage:
326  
327 destroy([$ns])
328
329 destroy([ns => $ns])
330
331 =item args:
332  
333 =over
334  
335 =item ns [Str]
336  
337 The cache namespace.
338  
339 =back
340  
341 =back
342  
343 =cut
344  
345 2 ▶multi method destroy (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine destroy: called CC=16 SCAR=31.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 12 0 12
@_ ? : 12 0 12
unless ($____nobble_checks) 0 12 12
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 12 12
if ($slice_length % 2 != 0) 0 12 12
if ($i <= $#_) 12 12 24
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 12 12
exists $_{'ns'} ? : 12 0 12
unless ($____nobble_checks) 0 12 12
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1200
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
346
347 12 ▶ $self->_l1Destroy(@_) if $self->l1Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l1Enabled 12 0 12
348 12 ▶ $self->_l2Destroy(@_) if $self->l1Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l1Enabled 12 0 12
349  
350 12 return 1;
351 }
352  
353 2 ▶multi method destroy (Str $ns?) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine destroy: not called CC=10 SCAR=41.9
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ > 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
354  
355 0 my %a;
356 0 ▶ $a{ns} = $ns if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
357
358 0 return $self->destroy(%a);
359 }
360  
361 =head2 get
362  
363 Gets a unique cache object. Returns undef if not found.
364  
365 =over
366  
367 =item usage:
368  
369 get($key, [$ns])
370
371 get(key => $key, [ns => $ns])
372
373 =item args:
374  
375 =over
376  
377 =item key [Str]
378  
379 Unique identifier of the cache object.
380  
381 =item ns [Str]
382  
383 The cache namespace.
384  
385 =back
386  
387 =back
388  
389 =cut
390  
391 multi method get (Str :$key!,
392 2 ▶ Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine get: called CC=23 SCAR=37.0
Branch: 15 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 6 0 6
@_ ? : 6 0 6
unless ($____nobble_checks) 0 6 6
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 6 6
if ($slice_length % 2 != 0) 0 6 6
if ($i <= $#_) 8 6 14
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 8 8
exists $_{'key'} ? : 6 0 6
unless ($____nobble_checks) 0 6 6
if (exists $_{"key"}) 0 0 0
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'ns'} ? : 2 4 6
unless ($____nobble_checks) 0 6 6
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
600
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
393  
394 6 ▶ $ns = $self->_getNamespace($ns) if !$ns;
Branch: 1 branch
BranchTrueFalseTotal
unless $ns 4 2 6
395
396 5 ▶ if ( $self->l1Enabled ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->l1Enabled) 5 0 5
397 5 my $data = $self->_l1Get(@_);
398 5 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 5 5
399 0 $self->Logger->verbose( "L1 cache hit - get ('$ns', '$key')");
400 0 return $data;
401 }
402 }
403  
404 5 ▶ if ( $self->l2Enabled ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->l2Enabled) 5 0 5
405 5 my $data = $self->_l2Get(@_);
406 5 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 3 2 5
407 3 $self->Logger->verbose( "L2 cache hit - get ('$ns', '$key')");
408 3 $self->_l1Set(@_, data => $data);
409 3 return $data;
410 }
411 }
412 }
413  
414 2 ▶multi method get (Str $key, Str $ns?) {
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine get: not called CC=15 SCAR=49.9
Branch: 13 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ < 1 0 0 0
if @_ > 2 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 1 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 1) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
415  
416 0 my %a;
417 0 $a{key} = $key;
418 0 ▶ $a{ns} = $ns if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
419
420 0 return $self->get(%a);
421 }
422  
423 =head2 getKeys
424  
425 Returns a list of cache keys.
426  
427 =over
428  
429 =item usage:
430  
431 getKeys([$ns])
432
433 getKeys([ns => $ns])
434
435 =item args:
436  
437 =over
438  
439 =item ns [Str]
440  
441 The cache namespace.
442  
443 =back
444  
445 =back
446  
447 =cut
448  
449 2 ▶multi method getKeys (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine getKeys: called CC=16 SCAR=31.9
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 8 0 8
@_ ? : 8 0 8
unless ($____nobble_checks) 0 8 8
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 8 8
if ($slice_length % 2 != 0) 0 8 8
if ($i <= $#_) 4 8 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 4 4
exists $_{'ns'} ? : 4 4 8
unless ($____nobble_checks) 0 8 8
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
800
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
450  
451 8 ▶ if ( $self->l2Enabled ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->l2Enabled) 8 0 8
452 8 return $self->_l2GetKeys(@_);
453 }
454  
455 0 ▶ if ( $self->l1Enabled ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->l1Enabled) 0 0 0
456 0 return $self->_l1GetKeys(@_);
457 }
458 }
459  
460 2 ▶multi method getKeys (Str $ns?) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine getKeys: not called CC=10 SCAR=41.9
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ > 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
461  
462 0 my %a;
463 0 ▶ $a{ns} = $ns if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
464
465 0 return $self->getKeys(ns => $ns);
466 }
467  
468 =head2 getNamespaceDir
469  
470 Gets the L2 cache dir.
471  
472 =over
473  
474 =item usage:
475  
476 getNamespaceDir([$ns])
477
478 getNamespaceDir([ns => $ns])
479
480 =item args:
481  
482 =over
483  
484 =item ns [Str]
485  
486 The cache namespace.
487  
488 =back
489  
490 =back
491  
492 =cut
493  
494 2 ▶multi method getNamespaceDir (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine getNamespaceDir: called CC=14 SCAR=29.3
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 12 0 12
@_ ? : 12 0 12
unless ($____nobble_checks) 0 12 12
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 12 12
if ($slice_length % 2 != 0) 0 12 12
if ($i <= $#_) 12 12 24
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 12 12
exists $_{'ns'} ? : 12 0 12
unless ($____nobble_checks) 0 12 12
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1200
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
495  
496 12 $ns = $self->_getNamespace($ns);
497  
498 12 return sprintf "%s/%s", $self->rootDir, $ns;
499 }
500  
501 2 ▶multi method getNamespaceDir (Str $ns?) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine getNamespaceDir: not called CC=10 SCAR=41.9
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ > 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
502  
503 0 my %a;
504 0 ▶ $a{ns} = $ns if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
505
506 0 return $self->getNamespaceDir(%a);
507 }
508  
509 =head2 set
510  
511 Commits the data object to the cache.
512  
513 =over
514  
515 =item usage:
516  
517 set($key, $data, [$ns])
518
519 set(key => $key, data => $data, [ns => $ns])
520
521 =item args:
522  
523 =over
524  
525 =item key [Str]
526  
527 Unique identifier of the cache object.
528  
529 =item data [Object|Ref|Str]
530  
531 An object, reference, or string.
532  
533 =item ns [Str]
534  
535 The cache namespace.
536  
537 =back
538  
539 =back
540  
541 =cut
542  
543 multi method set (Str :$key!,
544 Any :$data!,
545 2 ▶ Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine set: called CC=24 SCAR=39.1
Branch: 18 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 38 0 38
@_ ? : 38 0 38
unless ($____nobble_checks) 0 38 38
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 38 38
if ($slice_length % 2 != 0) 0 38 38
if ($i <= $#_) 113 38 151
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 113 113
exists $_{'key'} ? : 38 0 38
unless ($____nobble_checks) 0 38 38
if (exists $_{"key"}) 0 0 0
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'data'} ? : 38 0 38
unless ($____nobble_checks) 0 38 38
if (exists $_{"data"}) 0 0 0
exists $_{'ns'} ? : 37 1 38
unless ($____nobble_checks) 0 38 38
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
3800
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
546  
547 38 ▶ $ns = $self->_getNamespace($ns) if !$ns;
Branch: 1 branch
BranchTrueFalseTotal
unless $ns 1 37 38
548 38 $self->Logger->verbose("cache set ('$ns', '$key')");
549
550 38 ▶ $self->_l1Set(@_) if $self->l1Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l1Enabled 38 0 38
551 38 ▶ $self->_l2Set(@_) if $self->l2Enabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->l2Enabled 38 0 38
552  
553 38 return 1;
554 }
555  
556 multi method set (Str $key,
557 Any $data,
558 2 ▶ Str $ns?) {
Subroutine BEGIN: called CC=1 SCAR=4.3
Subroutine BEGIN: called CC=1 SCAR=4.3
Subroutine BEGIN: called CC=1 SCAR=4.3
Subroutine BEGIN: called CC=1 SCAR=4.3
Subroutine set: not called CC=18 SCAR=53.2
Branch: 16 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 1 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 1) 0 0 0
$#_ >= 2 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 2) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
559
560 0 my %a;
561 0 $a{key} = $key;
562 0 $a{data} = $data;
563 0 ▶ $a{ns} = $ns if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
564
565 0 return $self->set(%a);
566 }
567
568 ############################################################
569  
570 2 ▶method _getChiObject (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine _getChiObject: called CC=12 SCAR=25.3
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 56 0 56
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 56 56
if ($slice_length % 2 != 0) 0 56 56
if ($i <= $#_) 56 56 112
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 56 56
exists $_{'ns'} ? : 56 0 56
if (exists $_{"ns"}) 56 0 56
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 56 56
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
5600
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
571  
572 56 $ns = $self->_getNamespace($ns);
573  
574 56 my $href = $self->_chiObjects;
575  
576 56 ▶ if ( exists $href->{$ns} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $href->{$ns}) 37 19 56
577 37 return $href->{$ns};
578 }
579  
580 19 my %params = (
581 driver => 'File',
582 root_dir => $self->rootDir,
583 namespace => $ns,
584 );
585  
586 19 my $chi = CHI->new(%params);
587 19 $href->{$ns} = $chi;
588 19 $self->_chiObjects($href);
589  
590 19 return $chi;
591 }
592  
593 2 ▶method _buildL1Enabled {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _buildL1Enabled: called CC=4 SCAR=14.5
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 26 0 26
594  
595 26 ▶ if ( $self->enabled ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->enabled) 26 0 26
596 26 ▶ if ( !$ENV{MEDLEY_CACHE_L1_DISABLED} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"MEDLEY_CACHE_L1_DISABLED"}) 26 0 26
597 26 return 1;
598 }
599 }
600  
601 0 return 0;
602 }
603  
604 2 ▶method _buildL2Enabled {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _buildL2Enabled: called CC=4 SCAR=14.5
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 19 0 19
605  
606 19 ▶ if ( $self->enabled ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->enabled) 19 0 19
607 19 ▶ if ( !$ENV{MEDLEY_CACHE_L2_DISABLED} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"MEDLEY_CACHE_L2_DISABLED"}) 19 0 19
608 19 return 1;
609 }
610 }
611  
612 0 return 0;
613 }
614  
615 2 ▶method _buildRootDir {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _buildRootDir: called CC=3 SCAR=11.3
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 29 0 29
616  
617 29 ▶ if ( defined $ENV{HOME} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"HOME"}) 29 0 29
618 29 return "$ENV{HOME}/.chi";
619 }
620  
621 0 confess "unable to determine HOME env var";
622 }
623  
624 2 ▶method _buildEnabled {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _buildEnabled: called CC=3 SCAR=11.3
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 29 0 29
625  
626 29 ▶ if ( $ENV{MEDLEY_CACHE_DISABLED} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MEDLEY_CACHE_DISABLED"}) 0 29 29
627 0 return 0;
628 }
629  
630 29 return 1;
631 }
632  
633 method _l1Get (Str :$ns,
634 2 ▶ Str :$key!) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l1Get: called CC=15 SCAR=27.9
Branch: 11 branches
BranchTrueFalseTotal
@_ ? : 5 0 5
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 5 5
if ($slice_length % 2 != 0) 0 5 5
if ($i <= $#_) 7 5 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 7 7
exists $_{'ns'} ? : 2 3 5
if (exists $_{"ns"}) 2 3 5
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 2 2
exists $_{'key'} ? : 5 0 5
if (exists $_{"key"}) 5 0 5
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 5 5
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
500
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
635  
636 5 $ns = $self->_getNamespace($ns);
637  
638 5 $self->_l1Expire(@_);
639  
640 5 my $l1 = $self->_l1Cache;
641 5 ▶ if ( $l1->{$ns}->{$key}->{data} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l1->{$ns}{$key}{"data"}) 0 5 5
642 0 return $l1->{$ns}->{$key}->{data};
643 }
644  
645 5 return;
646 }
647  
648 method _l1Expire (Str :$ns,
649 2 ▶ Str :$key!) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l1Expire: called CC=17 SCAR=30.6
Branch: 11 branches
BranchTrueFalseTotal
@_ ? : 5 0 5
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 5 5
if ($slice_length % 2 != 0) 0 5 5
if ($i <= $#_) 7 5 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 7 7
exists $_{'ns'} ? : 2 3 5
if (exists $_{"ns"}) 2 3 5
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 2 2
exists $_{'key'} ? : 5 0 5
if (exists $_{"key"}) 5 0 5
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 5 5
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
500
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
650  
651 5 $ns = $self->_getNamespace($ns);
652  
653 5 my $l1 = $self->_l1Cache;
654  
655 5 ▶ if ( $l1->{$ns}->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l1->{$ns}{$key}) 0 5 5
656 0 my $href = $l1->{$ns}->{$key};
657  
658 0 ▶ if ( $href->{expire_epoch} ) { # zero or undef = never
Branch: 1 branch
BranchTrueFalseTotal
if ($href->{'expire_epoch'}) { } 0 0 0
659  
660 0 ▶ if ( time() > $href->{expire_epoch} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time > $href->{"expire_epoch"}) 0 0 0
661 0 $self->_l1Delete(@_);
662 }
663 }
664 else {
665 # zero or undef = never
666 }
667 }
668  
669 5 return;
670 }
671  
672 method _l1Delete (Str :$ns,
673 2 ▶ Str :$key!) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l1Delete: called CC=15 SCAR=27.9
Branch: 11 branches
BranchTrueFalseTotal
@_ ? : 5 0 5
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 5 5
if ($slice_length % 2 != 0) 0 5 5
if ($i <= $#_) 7 5 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 7 7
exists $_{'ns'} ? : 2 3 5
if (exists $_{"ns"}) 2 3 5
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 2 2
exists $_{'key'} ? : 5 0 5
if (exists $_{"key"}) 5 0 5
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 5 5
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
500
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
674  
675 5 $ns = $self->_getNamespace($ns);
676  
677 4 my $l1 = $self->_l1Cache;
678 4 ▶ if ( $l1->{$ns}->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l1->{$ns}{$key}) 0 4 4
679 0 delete $l1->{$ns}->{$key};
680 }
681  
682 4 return;
683 }
684  
685 2 ▶method _l1Destroy (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine _l1Destroy: called CC=11 SCAR=24.7
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 12 0 12
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 12 12
if ($slice_length % 2 != 0) 0 12 12
if ($i <= $#_) 12 12 24
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 12 12
exists $_{'ns'} ? : 12 0 12
if (exists $_{"ns"}) 12 0 12
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 12 12
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1200
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
686  
687 12 $self->_l1Clear(@_);
688 }
689  
690 2 ▶method _l2Destroy (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine _l2Destroy: called CC=12 SCAR=25.8
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 12 0 12
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 12 12
if ($slice_length % 2 != 0) 0 12 12
if ($i <= $#_) 12 12 24
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 12 12
exists $_{'ns'} ? : 12 0 12
if (exists $_{"ns"}) 12 0 12
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 12 12
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1200
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
691  
692 12 $ns = $self->_getNamespace($ns);
693  
694 12 my $href = $self->_chiObjects;
695 12 ▶ if ($href->{$ns}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($href->{$ns}) 0 12 12
696 0 delete $href->{$ns};
697 }
698  
699 12 remove_tree($self->getNamespaceDir(ns => $ns));
700 }
701  
702 2 ▶method _l1Clear (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l1Clear: called CC=11 SCAR=24.3
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 14 0 14
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 14 14
if ($slice_length % 2 != 0) 0 14 14
if ($i <= $#_) 13 14 27
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 13 13
exists $_{'ns'} ? : 13 1 14
if (exists $_{"ns"}) 13 1 14
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 13 13
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
1400
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
703  
704 14 $ns = $self->_getNamespace($ns);
705  
706 14 my $l1 = $self->_l1Cache;
707 14 $l1->{$ns} = {};
708 }
709  
710 2 ▶method _l2Clear (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l2Clear: called CC=11 SCAR=24.3
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 2 0 2
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 2 2
if ($slice_length % 2 != 0) 0 2 2
if ($i <= $#_) 1 2 3
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 1 1
exists $_{'ns'} ? : 1 1 2
if (exists $_{"ns"}) 1 1 2
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 1 1
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
200
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
711  
712 2 $ns = $self->_getNamespace($ns);
713  
714 2 my $chi = $self->_getChiObject( ns => $ns );
715 2 $chi->clear;
716 }
717  
718 method _l1Set (Str :$ns,
719 Str :$key!,
720 2 ▶ Any :$data!) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l1Set: called CC=17 SCAR=29.2
Branch: 13 branches
BranchTrueFalseTotal
@_ ? : 41 0 41
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 41 41
if ($slice_length % 2 != 0) 0 41 41
if ($i <= $#_) 120 41 161
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 120 120
exists $_{'ns'} ? : 38 3 41
if (exists $_{"ns"}) 38 3 41
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 38 38
exists $_{'key'} ? : 41 0 41
if (exists $_{"key"}) 41 0 41
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 41 41
exists $_{'data'} ? : 41 0 41
if (exists $_{"data"}) 41 0 41
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
4100
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
721
722 41 $ns = $self->_getNamespace($ns);
723  
724 41 my $node = {
725 data => $data,
726 expire_epoch => 0,
727 };
728  
729 41 ▶ if ( $self->expireSecs ) { # defined and greater than zero
Branch: 1 branch
BranchTrueFalseTotal
if ($self->expireSecs) 0 41 41
730 0 $node->{expire_epoch} = time + int( $self->expireSecs );
731 }
732  
733 41 my $l1 = $self->_l1Cache;
734 41 $l1->{$ns}->{$key} = $node;
735  
736 41 return;
737 }
738  
739 2 ▶method _l1GetKeys (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine _l1GetKeys: not called CC=13 SCAR=44.7
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'ns'} ? : 0 0 0
if (exists $_{"ns"}) 0 0 0
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
740  
741 0 $ns = $self->_getNamespace($ns);
742  
743 0 my $l1 = $self->_l1Cache;
744 0 ▶ if ( $l1 and $l1->{$ns} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l1 and $l1->{$ns}) 0 0 0
Condition0%0/3
$l1 and $l1->{$ns}
!ll&&!rl&&r
000
MC/DC0%0/2
$l1 and $l1->{$ns}
$l1 $l1->{$ns}
Truth table0%0/3
A and B
A= $l1B= $l1->{$ns}
ABresult
0X0
100
111
745 0 return keys %{ $l1->{$ns} };
746 }
747 }
748  
749 2 ▶method _getExpireSecsForChi {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _getExpireSecsForChi: called CC=3 SCAR=11.3
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 38 0 38
750  
751 38 ▶ if ( $self->expireSecs ) { # defined and > 0
Branch: 1 branch
BranchTrueFalseTotal
if ($self->expireSecs) 0 38 38
752 0 return $self->expireSecs;
753 }
754  
755 38 return 'never';
756 }
757  
758 method _l2Set (Str :$ns,
759 Str :$key!,
760 2 ▶ Any :$data!) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l2Set: called CC=16 SCAR=28.4
Branch: 13 branches
BranchTrueFalseTotal
@_ ? : 38 0 38
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 38 38
if ($slice_length % 2 != 0) 0 38 38
if ($i <= $#_) 113 38 151
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 113 113
exists $_{'ns'} ? : 37 1 38
if (exists $_{"ns"}) 37 1 38
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 37 37
exists $_{'key'} ? : 38 0 38
if (exists $_{"key"}) 38 0 38
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 38 38
exists $_{'data'} ? : 38 0 38
if (exists $_{"data"}) 38 0 38
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
3800
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
761  
762 38 $ns = $self->_getNamespace($ns);
763  
764 38 my $chi = $self->_getChiObject( ns => $ns );
765  
766 38 return $chi->set( $key, $data, $self->_getExpireSecsForChi );
767 }
768  
769 method _l2Delete (Str :$ns,
770 2 ▶ Str :$key) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l2Delete: called CC=14 SCAR=26.9
Branch: 11 branches
BranchTrueFalseTotal
@_ ? : 4 0 4
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 4 4
if ($slice_length % 2 != 0) 0 4 4
if ($i <= $#_) 6 4 10
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 6 6
exists $_{'ns'} ? : 2 2 4
if (exists $_{"ns"}) 2 2 4
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 2 2
exists $_{'key'} ? : 4 0 4
if (exists $_{"key"}) 4 0 4
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 4 4
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
400
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
771  
772 4 $ns = $self->_getNamespace($ns);
773  
774 4 my $chi = $self->_getChiObject( ns => $ns );
775 4 $chi->expire($key);
776  
777 4 return;
778 }
779  
780 method _l2Get (Str :$ns,
781 2 ▶ Str :$key) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l2Get: called CC=14 SCAR=27.0
Branch: 11 branches
BranchTrueFalseTotal
@_ ? : 5 0 5
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 5 5
if ($slice_length % 2 != 0) 0 5 5
if ($i <= $#_) 7 5 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 7 7
exists $_{'ns'} ? : 2 3 5
if (exists $_{"ns"}) 2 3 5
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 2 2
exists $_{'key'} ? : 5 0 5
if (exists $_{"key"}) 5 0 5
Type::Tiny::XS::Str($key) or _failed_check(9, "Str", $key, "exception_class", "Error::TypeTiny::Assertion") 0 5 5
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
500
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
782  
783 5 $ns = $self->_getNamespace($ns);
784  
785 5 my $chi = $self->_getChiObject( ns => $ns );
786 5 return $chi->get($key);
787 }
788  
789 2 ▶method _l2GetKeys (Str :$ns) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _l2GetKeys: called CC=12 SCAR=25.3
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 8 0 8
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 8 8
if ($slice_length % 2 != 0) 0 8 8
if ($i <= $#_) 4 8 12
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 4 4
exists $_{'ns'} ? : 4 4 8
if (exists $_{"ns"}) 4 4 8
Type::Tiny::XS::Str($ns) or _failed_check(9, "Str", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 4 4
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
800
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
790  
791 8 $ns = $self->_getNamespace($ns);
792  
793 7 my @keys;
794  
795 7 my $chi = $self->_getChiObject( ns => $ns );
796 7 ▶ if ($chi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chi) 7 0 7
797 7 @keys = $chi->get_keys;
798 }
799  
800 7 return @keys;
801 }
802  
803 2 ▶method _getNamespace (Str|Undef $ns) {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine _getNamespace: called CC=8 SCAR=21.0
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 212 0 212
if @_ != 1 0 212 212
$#_ >= 0 ? : 212 0 212
if ($#_ >= 0) 212 0 212
Type::Tiny::XS::AUTO::TC1($ns) or _failed_check(45, "Str|Undef", $ns, "exception_class", "Error::TypeTiny::Assertion") 0 212 212
804  
805 212 ▶ if ( !$ns ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ns) 29 183 212
806 29 ▶ if ( !$self->ns ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ns) 3 26 29
807 3 confess "must provide namespace";
808 }
809  
810 26 return $self->ns;
811 }
812  
813 183 return $ns;
814 }
815  
816 2 1;
« Medley/Logger.pm ↑ Summary Medley/Spawn.pm »