| 1 | package EntityModel::StorageClass::KVStore; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 1 | $EntityModel::StorageClass::KVStore::VERSION = '0.102'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use List::UtilsBy qw(extract_by); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =pod | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Layers: | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | LRU cache - exists if we know the answer, undef means "ain't there" | ||||||||||||||||||||||||||||
| 15 | Memcached | ||||||||||||||||||||||||||||
| 16 | PostgreSQL select | ||||||||||||||||||||||||||||
| 17 | PostgreSQL insert | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub new { bless { underlayer => [] }, shift } | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub lookup { | ||||||||||||||||||||||||||
|
Subroutine
lookup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 26 | 0 | $self->{underlayer}[-1]->retrieve(%args); | |||||||||||||||||||||||||||
| 27 | 0 | $self; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head2 add_layer | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Adds a new layer to KV storage. Links it to the current layers | ||||||||||||||||||||||||||||
| 33 | as appropriate. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Takes a single parameter: | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =item * $layer - the new layer to add | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =back | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Returns $self. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub add_layer { | ||||||||||||||||||||||||||
|
Subroutine
add_layer: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 0 | my $layer = shift; | |||||||||||||||||||||||||||
| 50 | 0 | my $prev = $self->{underlayer}[-1]; | |||||||||||||||||||||||||||
| 51 | 0 | push @{ $self->{underlayer} }, $layer; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | $layer->underlayer($prev) if $prev; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $self | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head2 remove_layer | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Removes an existing layer to KV storage. Unlinks the other layers | ||||||||||||||||||||||||||||
| 59 | as appropriate. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Takes a single parameter: | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =over 4 | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item * $layer - the new layer to add | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =back | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Returns $self. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub remove_layer { | ||||||||||||||||||||||||||
|
Subroutine
remove_layer: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 0 | my $layer = shift; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # First, remove it from the stack | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my ($l) = extract_by { $_ eq $layer } @{$self->{underlayer}}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return $self unless $l; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Then update any layers so we don't have dangling references | ||||||||||||||||||||||||||||
| 82 | 0 | foreach my $ul (@{$self->{underlayer}}) { | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $ul->underlayer($l->underlayer) if $ul->underlayer && $ul->underlayer eq $l; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ul->underlayer and $ul->underlayer eq $l
MC/DC0%0/2
$ul->underlayer and $ul->underlayer eq $l
$ul->underlayer
$ul->underlayer eq $l
Truth table0%0/3
A and B
A= $ul->underlayerB= $ul->underlayer eq $l
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | $self | ||||||||||||||||||||||||||||
| 86 | 0 | } | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub shutdown { | ||||||||||||||||||||||||||
|
Subroutine
shutdown: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 91 | 0 | my @pending; | |||||||||||||||||||||||||||
| 92 | 0 | foreach my $l (@{$self->{underlayer}}) { | |||||||||||||||||||||||||||
| 93 | 0 | push @pending, my $f = Future->new; | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | $l->shutdown(on_success => sub { $f->done }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | # I think we need to hold onto this...? | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $self->{pending_shutdown} = Future->wait_all(@pending)->on_ready(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 98 | 0 | delete $self->{pending_shutdown}; | |||||||||||||||||||||||||||
| 99 | 0 | $args{on_success}->() | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | }) if $args{on_success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $self->{underlayer} = []; | |||||||||||||||||||||||||||
| 102 | 0 | $self | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||