EntityModel/StorageClass/KVStore/Layer.pm

filter: Statementstmt 25.0% 9 / 36 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 18.1% 2 / 11 Podpod 42.8% 3 / 7 totaltotal 23.3% 14 / 60 CC 5 SCAR 13.9
CC
5
Cov
21%
underlayer
6.0
retrieve
6.0
retrieval_fallback
6.0
CRAP 4.0
« EntityModel/Query/Insert.pm ↑ Summary EntityModel/StorageClass/KVStore/Layer/LRU.pm »
1 package EntityModel::StorageClass::KVStore::Layer;
2 {
3 5 $EntityModel::StorageClass::KVStore::Layer::VERSION = '0.102';
4 }
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
9 0 ▶sub lookup { () }
Subroutine lookup: not called CC=1 SCAR=6.9
Pod undocumented
10  
11 =head2 underlayer
12  
13 Accessor for the next storage layer down.
14  
15 =cut
16  
17 0 ▶sub underlayer {
Subroutine underlayer: not called CC=2 SCAR=17.9
Pod documented
18 0 my $self = shift;
19 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
20 0 $self->{underlayer} = shift;
21 0 return $self
22 }
23 return $self->{underlayer}
24 0 }
25  
26 =head2 key_mangle
27  
28 Applies any modifications necessary to convert the query into a key suitable
29 for this caching layer.
30  
31 Takes the following parameters:
32  
33 =over 4
34  
35 =item * $query - the value to mangle
36  
37 =back
38  
39 Returns the modified result (actual modification performed is implementation-dependent).
40  
41 =cut
42  
43 0 ▶sub key_mangle { $_[1] }
Subroutine key_mangle: not called CC=1 SCAR=6.9
Pod documented
44  
45 =head2 retrieve
46  
47 Attempts to retrieve the given value from storage.
48  
49 Takes the following parameters:
50  
51 =over 4
52  
53 =item * query - the query we're trying to find
54  
55 =item * on_success - what to do when we win
56  
57 =item * on_failure - how to deal with defeat
58  
59 =back
60  
61 Returns $self.
62  
63 =cut
64  
65 0 ▶sub retrieve {
Subroutine retrieve: not called CC=2 SCAR=17.9
Pod documented
66 0 my $self = shift;
67 0 my %args = @_;
68 0 my $k = $args{query};
69  
70 # We'll get an empty list back if we don't have the value
71 0 return $args{on_success}->($_) for $self->lookup($k);
72  
73 0 $self->retrieval_fallback(%args);
74 }
75  
76 0 ▶sub retrieval_fallback {
Subroutine retrieval_fallback: not called CC=2 SCAR=17.9
Pod undocumented
77 0 my $self = shift;
78 0 my %args = @_;
79 0 ▶ die "Without an underlayer I must concede defeat" unless my $underlayer = $self->underlayer;
Branch: 1 branch
BranchTrueFalseTotal
unless my $underlayer = $self->underlayer 0 0 0
80  
81 0 my $k = $args{query};
82 # Delegate to the next layer down
83 $underlayer->retrieve(
84 query => $k,
85 0 ▶ on_success => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 my $v = shift;
87 0 $self->store($k => $v);
88 0 $args{on_success}->($v);
89 },
90 0 ▶ on_failure => sub { die "AIEE" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 );
92 0 $self
93 }
94  
95 0 ▶sub shutdown {
Subroutine shutdown: not called CC=2 SCAR=17.9
Pod undocumented
96 0 my $self = shift;
97 0 my %args = @_;
98 0 ▶ $args{on_success}->() if $args{on_success};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"on_success"} 0 0 0
99 0 $self;
100 }
101  
102 5 1;
103  
« EntityModel/Query/Insert.pm ↑ Summary EntityModel/StorageClass/KVStore/Layer/LRU.pm »