| 1 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ## A hybrid LRU-plain cache helper class. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ## An optimized, pure-Perl LRU implementation with extra performance when | ||||||||||||||||||||||||||||||||||||||||||
| 6 | ## fetching items from the upper-section of the cache. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 8 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | package MCE::Shared::Cache; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | no warnings qw( threads recursion uninitialized numeric ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | our $VERSION = '1.894'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | ## no critic (Subroutines::ProhibitExplicitReturnUndef) | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ## no critic (TestingAndDebugging::ProhibitNoStrict) | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use Scalar::Util qw( dualvar looks_like_number ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use Time::HiRes qw( time ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use MCE::Shared::Base (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | use base 'MCE::Shared::Common'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | _DATA => 0, # unordered data | |||||||||||||||||||||||||||||||||||||||||
| 32 | _KEYS => 1, # LRU queue | ||||||||||||||||||||||||||||||||||||||||||
| 33 | _INDX => 2, # index into _KEYS | ||||||||||||||||||||||||||||||||||||||||||
| 34 | _BEGI => 3, # begin offset value | ||||||||||||||||||||||||||||||||||||||||||
| 35 | _GCNT => 4, # garbage count | ||||||||||||||||||||||||||||||||||||||||||
| 36 | _EXPI => 5, # max age, default disabled | ||||||||||||||||||||||||||||||||||||||||||
| 37 | _SIZE => 6, # max keys, default disabled | ||||||||||||||||||||||||||||||||||||||||||
| 38 | _HREF => 7, # for hash-like dereferencing | ||||||||||||||||||||||||||||||||||||||||||
| 39 | _ITER => 8, # for tied hash support | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | q("") => \&MCE::Shared::Base::_stringify, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | q(0+) => \&MCE::Shared::Base::_numify, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | q(%{}) => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | no overloading; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $_[0]->[_HREF] || do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | # no circular reference to original, therefore no memory leaks | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | tie my %h, __PACKAGE__.'::_href', bless([ @{ $_[0] } ], __PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $_[0]->[_HREF] = \%h; | |||||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | fallback => 1 | |||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ## TIEHASH, STORE, FETCH, DELETE, FIRSTKEY, NEXTKEY, EXISTS, CLEAR, SCALAR | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # TIEHASH ( max_keys => undef, max_age => undef ); # default | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # TIEHASH ( { options }, @pairs ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # TIEHASH ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub TIEHASH { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=9 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | my $opts = ( ref $_[0] eq 'HASH' ) ? shift : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | if ( !defined $opts ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | $opts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | for my $cnt ( 1 .. 2 ) { | |||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | ▶ | if ( @_ && $_[0] =~ /^(max_keys|max_age)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and $_[0] =~ /^(max_keys|max_age)$/
MC/DC50%1/2
@_ and $_[0] =~ /^(max_keys|max_age)$/
@_
$_[0] =~ /^(max_keys|max_age)$/
Truth table66%2/3
A and B
A= @_B= $_[0] =~ /^(max_keys|max_age)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | $opts->{ $1 } = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | my ( $begi, $gcnt ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | my $expi = MCE::Shared::Cache::_secs( $opts->{'max_age' } // undef ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"max_age"} // undef
MC/DC0%0/1
$opts->{"max_age"} // undef
$opts->{"max_age"}
Truth table50%1/2
A
A= $opts->{"max_age"}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | my $size = MCE::Shared::Cache::_size( $opts->{'max_keys'} // undef ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"max_keys"} // undef
MC/DC0%0/1
$opts->{"max_keys"} // undef
$opts->{"max_keys"}
Truth table50%1/2
A
A= $opts->{"max_keys"}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $obj = bless [ {}, [], {}, \$begi, \$gcnt, \$expi, \$size ], $class; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | $obj->mset(@_) if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | $obj; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # STORE ( key, value [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 25 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=19 SCAR=44.5
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 25 | my ( $data, $keys, $indx, $begi, $gcnt, $expi, $size ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 25 | ▶ | my $exptime = ( @_ == 4 ) ? $_[3] : ${ $expi }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 25 | ▶ | if ( !defined $exptime ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 25 | $exptime = -1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } elsif ( !looks_like_number $exptime ) { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $exptime = MCE::Shared::Cache::_secs( $exptime ); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # update existing key | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 25 | ▶ | if ( defined ( my $off = $indx->{ $_[1] } ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $off -= ${ $begi }; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # update expiration | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $keys->[ $off ] = ( $exptime >= 0 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | ? dualvar( time + $exptime, $_[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 109 | : dualvar( -1, $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | # promote key if not last, inlined for performance | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( ! $off ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return $data->{ $_[1] } = $_[2] if @{ $keys } == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | push @{ $keys }, shift @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $indx->{ $_[1] } = ++${ $begi } + @{ $keys } - 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | MCE::Shared::Cache::_gckeys_head( $keys, $begi, $gcnt ) | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( ${ $gcnt } && !defined $keys->[ 0 ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
${$gcnt;} and not defined $keys->[0]
MC/DC0%0/2
${$gcnt;} and not defined $keys->[0]
${$gcnt;}
not defined $keys->[0]
Truth table0%0/3
A and not(B)
A= ${$gcnt;}B= not defined $keys->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # safety to not overrun | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | $_[0]->purge if ( ${ $begi } > 1e9 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | elsif ( $off != @{ $keys } - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | push @{ $keys }, delete $keys->[ $off ]; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $indx->{ $_[1] } = ${ $begi } + @{ $keys } - 1; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # GC keys if the gcnt:size ratio is greater than 2:3 | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $_[0]->purge if ( ++${ $gcnt } > @{ $keys } * 0.667 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | return $data->{ $_[1] } = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # insert key-value pair | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 25 | $data->{ $_[1] } = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 25 | $indx->{ $_[1] } = ${ $begi } + @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 25 | ▶ | push @{ $keys }, ( $exptime >= 0 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | ? dualvar( time + $exptime, $_[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 141 | : dualvar( -1, $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # evict the least used key, inlined for performance | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 25 | ▶ | if ( defined ${ $size } && @{ $keys } - ${ $gcnt } > ${ $size } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined ${$size;} and @{$keys;} - ${$gcnt;} > ${$size;}
MC/DC50%1/2
defined ${$size;} and @{$keys;} - ${$gcnt;} > ${$size;}
defined ${$size;}
@{$keys;} - ${$gcnt;} > ${$size;}
Truth table66%2/3
A and B
A= defined ${$size;}B= @{$keys;} - ${$gcnt;} > ${$size;}
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | my $key = shift @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | ${ $begi }++, delete($data->{ $key }), delete($indx->{ $key }); | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | MCE::Shared::Cache::_gckeys_head( $keys, $begi, $gcnt ) | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 9 | ▶ | if ( ${ $gcnt } && !defined $keys->[ 0 ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
${$gcnt;} and not defined $keys->[0]
MC/DC50%1/2
${$gcnt;} and not defined $keys->[0]
${$gcnt;}
not defined $keys->[0]
Truth table66%2/3
A and not(B)
A= ${$gcnt;}B= not defined $keys->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # safety to not overrun | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 9 | ▶ | $_[0]->purge if ( ${ $begi } > 1e9 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 25 | $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # FETCH ( key ) | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=11 SCAR=31.0
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | # cache miss | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | return undef if !defined ( my $off = $_[0]->[_INDX]{ $_[1] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | # cache hit | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | my ( $data, $keys, $indx, $begi, $gcnt ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | $off -= ${ $begi }; | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # key expired | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | $_[0]->del( $_[1] ), return undef if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$keys->[$off] >= 0 and $keys->[$off] < &MCE::Shared::Cache::time()
MC/DC0%0/2
$keys->[$off] >= 0 and $keys->[$off] < &MCE::Shared::Cache::time()
$keys->[$off] >= 0
$keys->[$off] < &MCE::Shared::Cache::time()
Truth table33%1/3
A and B
A= $keys->[$off] >= 0B= $keys->[$off] < &MCE::Shared::Cache::time()
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | $keys->[ $off ] >= 0 && $keys->[ $off ] < time | ||||||||||||||||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # promote key if not upper half, inlined for performance | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | ▶ | if ( ! $off ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | return $data->{ $_[1] } if @{ $keys } == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | push @{ $keys }, shift @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | $indx->{ $_[1] } = ++${ $begi } + @{ $keys } - 1; | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | MCE::Shared::Cache::_gckeys_head( $keys, $begi, $gcnt ) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | if ( ${ $gcnt } && !defined $keys->[ 0 ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
${$gcnt;} and not defined $keys->[0]
MC/DC0%0/2
${$gcnt;} and not defined $keys->[0]
${$gcnt;}
not defined $keys->[0]
Truth table33%1/3
A and not(B)
A= ${$gcnt;}B= not defined $keys->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | # safety to not overrun | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | $_[0]->purge if ( ${ $begi } > 1e9 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | elsif ( $off - ${ $gcnt } < ( ( @{ $keys } - ${ $gcnt } ) >> 1 ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | push @{ $keys }, delete $keys->[ $off ]; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $indx->{ $_[1] } = ${ $begi } + @{ $keys } - 1; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # GC keys if the gcnt:size ratio is greater than 2:3 | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | $_[0]->purge if ( ++${ $gcnt } > @{ $keys } * 0.667 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | $data->{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | # DELETE ( key ) | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | sub DELETE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=11 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | my ( $data, $keys, $indx, $begi, $gcnt ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | ▶ | return undef if !defined ( my $off = delete $indx->{ $_[1] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | $off -= ${ $begi }; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | # check the first key | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 3 | ▶ | if ( ! $off ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | ${ $begi }++; shift @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | if ( ${ $gcnt } && !defined $keys->[ 0 ] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
${$gcnt;} and not defined $keys->[0]
MC/DC0%0/2
${$gcnt;} and not defined $keys->[0]
${$gcnt;}
not defined $keys->[0]
Truth table33%1/3
A and not(B)
A= ${$gcnt;}B= not defined $keys->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | MCE::Shared::Cache::_gckeys_head( $keys, $begi, $gcnt ); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | } elsif ( ! @{ $keys } ) { | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ${ $begi } = 0; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | return delete $data->{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # check the last key | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | elsif ( $off == @{ $keys } - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | pop @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | if ( ${ $gcnt } && !defined $keys->[ -1 ] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
${$gcnt;} and not defined $keys->[-1]
MC/DC0%0/2
${$gcnt;} and not defined $keys->[-1]
${$gcnt;}
not defined $keys->[-1]
Truth table33%1/3
A and not(B)
A= ${$gcnt;}B= not defined $keys->[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | MCE::Shared::Cache::_gckeys_tail( $keys, $gcnt ); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | } elsif ( ! @{ $keys } ) { | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ${ $begi } = 0; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | return delete $data->{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | # must be a key somewhere in-between | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | $keys->[ $off ] = undef; # tombstone | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | # GC keys if the gcnt:size ratio is greater than 2:3 | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | ▶ | $_[0]->purge if ( ++${ $gcnt } > @{ $keys } * 0.667 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | delete $data->{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # FIRSTKEY ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub FIRSTKEY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->[_ITER] = [ $self->keys ]; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $self->NEXTKEY; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | # NEXTKEY ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub NEXTKEY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | shift @{ $_[0]->[_ITER] }; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # EXISTS ( key ) | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | ▶ | sub EXISTS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | my ( $self, $key ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | ▶ | return '' if !defined ( my $off = $self->[_INDX]{ $key } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $off -= ${ $self->[_BEGI] }; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | $self->del( $key ), return '' if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->[1][$off] >= 0 and $self->[1][$off] < &MCE::Shared::Cache::time()
MC/DC0%0/2
$self->[1][$off] >= 0 and $self->[1][$off] < &MCE::Shared::Cache::time()
$self->[1][$off] >= 0
$self->[1][$off] < &MCE::Shared::Cache::time()
Truth table33%1/3
A and B
A= $self->[1][$off] >= 0B= $self->[1][$off] < &MCE::Shared::Cache::time()
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | $self->[_KEYS][ $off ] >= 0 && | ||||||||||||||||||||||||||||||||||||||||||
| 268 | $self->[_KEYS][ $off ] < time | ||||||||||||||||||||||||||||||||||||||||||
| 269 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | # CLEAR ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | ▶ | sub CLEAR { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLEAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | my ( $data, $keys, $indx, $begi, $gcnt ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | %{ $data } = @{ $keys } = %{ $indx } = (); | |||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | ${ $begi } = ${ $gcnt } = 0; | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | delete $_[0]->[_ITER]; | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | # SCALAR ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub SCALAR { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SCALAR: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | $_[0]->_prune_head; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | scalar keys %{ $_[0]->[_DATA] }; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 296 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 297 | ## Internal routines for preserving dualvar KEYS data during freeze-thaw ops. | ||||||||||||||||||||||||||||||||||||||||||
| 298 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 299 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | ## Storable freeze-thaw | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | sub STORABLE_freeze { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ( $self, $cloning ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | return if $cloning; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my @TIME; $self->purge; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | for my $key ( @{ $self->[_KEYS] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | push @TIME, 0 + $key; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | return '', [ @{ $self }, \@TIME ]; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | sub STORABLE_thaw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ( $self, $cloning, $serialized, $ret ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | return if $cloning; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $TIME = pop @{ $ret }; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | @{ $self } = @{ $ret }; | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my ( $i, $keys ) = ( 0, $self->[_KEYS] ); | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | for my $time ( @{ $TIME } ) { | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $keys->[ $i ] = dualvar( $time, $keys->[ $i ] ); | |||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | ## Sereal freeze-thaw | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | sub FREEZE { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FREEZE: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my @TIME; $self->purge; | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | for my $key ( @{ $self->[_KEYS] } ) { | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | push @TIME, 0 + $key; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | return [ @{ $self }, \@TIME ]; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub THAW { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
THAW: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my ( $class, $serializer, $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $TIME = pop @{ $data }; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $self = $class->new; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | @{ $self } = @{ $data }; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my ( $i, $keys ) = ( 0, $self->[_KEYS] ); | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | for my $time ( @{ $TIME } ) { | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $keys->[ $i ] = dualvar( $time, $keys->[ $i ] ); | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 364 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 365 | ## _gckeys_head, _gckeys_tail, _inskey, _prune_head, _secs, _size | ||||||||||||||||||||||||||||||||||||||||||
| 366 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 367 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | # GC start of list | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | ▶ | sub _gckeys_head { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gckeys_head: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | my ( $keys, $begi, $gcnt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | ▶ | $i++ until ( defined $keys->[ $i ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ${ $begi } += $i, ${ $gcnt } -= $i; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | splice @{ $keys }, 0, $i; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | # GC end of list | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | sub _gckeys_tail { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gckeys_tail: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my ( $keys, $gcnt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $i = $#{ $keys } - 1; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | $i-- until ( defined $keys->[ $i ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ${ $gcnt } -= $#{ $keys } - $i; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | splice @{ $keys }, $i + 1; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | # insert or promote key | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | sub _inskey { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inskey: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my ( $data, $keys, $indx, $begi, $gcnt, $expi, $size ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | my $exptime = ( @_ == 3 ) ? $_[2] : ${ $expi }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ( !defined $exptime ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $exptime = -1; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } elsif ( !looks_like_number $exptime ) { | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $exptime = MCE::Shared::Cache::_secs( $exptime ); | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | # update existing key | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if ( defined ( my $off = $indx->{ $_[1] } ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $off -= ${ $begi }; | |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | # unset value if expired | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | $data->{ $_[1] } = undef | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$keys->[$off] >= 0 and $keys->[$off] < &MCE::Shared::Cache::time()
MC/DC0%0/2
$keys->[$off] >= 0 and $keys->[$off] < &MCE::Shared::Cache::time()
$keys->[$off] >= 0
$keys->[$off] < &MCE::Shared::Cache::time()
Truth table0%0/3
A and B
A= $keys->[$off] >= 0B= $keys->[$off] < &MCE::Shared::Cache::time()
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | if ( $keys->[ $off ] >= 0 && $keys->[ $off ] < time ); | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | # update expiration | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | $keys->[ $off ] = ( $exptime >= 0 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | ? dualvar( time + $exptime, $_[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 418 | : dualvar( -1, $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | # promote key if not last, inlined for performance | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if ( ! $off ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | return if @{ $keys } == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | push @{ $keys }, shift @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $indx->{ $_[1] } = ++${ $begi } + @{ $keys } - 1; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | MCE::Shared::Cache::_gckeys_head( $keys, $begi, $gcnt ) | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if ( ${ $gcnt } && !defined $keys->[ 0 ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
${$gcnt;} and not defined $keys->[0]
MC/DC0%0/2
${$gcnt;} and not defined $keys->[0]
${$gcnt;}
not defined $keys->[0]
Truth table0%0/3
A and not(B)
A= ${$gcnt;}B= not defined $keys->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | # safety to not overrun | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | $_[0]->purge if ( ${ $begi } > 1e9 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | elsif ( $off != @{ $keys } - 1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | push @{ $keys }, delete $keys->[ $off ]; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $indx->{ $_[1] } = ${ $begi } + @{ $keys } - 1; | |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | # GC keys if the gcnt:size ratio is greater than 2:3 | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | $_[0]->purge if ( ++${ $gcnt } > @{ $keys } * 0.667 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | # insert key | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $indx->{ $_[1] } = ${ $begi } + @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | push @{ $keys }, ( $exptime >= 0 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | ? dualvar( time + $exptime, $_[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 449 | : dualvar( -1, $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | # evict the least used key, inlined for performance | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if ( defined ${ $size } && @{ $keys } - ${ $gcnt } > ${ $size } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined ${$size;} and @{$keys;} - ${$gcnt;} > ${$size;}
MC/DC0%0/2
defined ${$size;} and @{$keys;} - ${$gcnt;} > ${$size;}
defined ${$size;}
@{$keys;} - ${$gcnt;} > ${$size;}
Truth table0%0/3
A and B
A= defined ${$size;}B= @{$keys;} - ${$gcnt;} > ${$size;}
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $key = shift @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ${ $begi }++, delete($data->{ $key }), delete($indx->{ $key }); | |||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | MCE::Shared::Cache::_gckeys_head( $keys, $begi, $gcnt ) | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | if ( ${ $gcnt } && !defined $keys->[ 0 ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
${$gcnt;} and not defined $keys->[0]
MC/DC0%0/2
${$gcnt;} and not defined $keys->[0]
${$gcnt;}
not defined $keys->[0]
Truth table0%0/3
A and not(B)
A= ${$gcnt;}B= not defined $keys->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | # safety to not overrun | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | $_[0]->purge if ( ${ $begi } > 1e9 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | # prune start of list | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 19 | ▶ | sub _prune_head { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prune_head: called CC=6 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 19 | my ( $data, $keys, $indx, $begi, $gcnt ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 19 | my ( $i, $time ) = ( 0, time ); | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 19 | for my $k ( @{ $keys } ) { | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | $i++, ${ $gcnt }--, next unless ( defined $k ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 13 | ▶ | last if ( $keys->[ $i ] < 0 || $keys->[ $i ] > $time ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$keys->[$i] < 0 or $keys->[$i] > $time
MC/DC0%0/2
$keys->[$i] < 0 or $keys->[$i] > $time
$keys->[$i] < 0
$keys->[$i] > $time
Truth table33%1/3
A or B
A= $keys->[$i] < 0B= $keys->[$i] > $time
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | delete $data->{ $k }; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | delete $indx->{ $k }; | |||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | ${ $begi } += $i, splice @{ $keys }, 0, $i if $i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 19 | return; | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | # compute seconds | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | { | ||||||||||||||||||||||||||||||||||||||||||
| 490 | # seconds, minutes, hours, days, weeks | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 4 | my %secs = ( '' => 1, s => 1, m => 60, h => 3600, d => 86400, w => 604800 ); | |||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 2 | ▶ | sub _secs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_secs: called CC=7 SCAR=34.7
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 2 | my ( $secs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 2 | ▶ | return undef if ( !defined $secs || $secs eq 'never' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $secs or $secs eq "never"
MC/DC0%0/2
not defined $secs or $secs eq "never"
not defined $secs
$secs eq "never"
Truth table33%1/3
not(A) or B
A= not defined $secsB= $secs eq "never"
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | return 0 if ( !$secs || $secs eq 'now' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $secs or $secs eq "now"
MC/DC0%0/2
not $secs or $secs eq "now"
not $secs
$secs eq "now"
Truth table0%0/3
not(A) or B
A= not $secsB= $secs eq "now"
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | return 0.0001 if ( $secs < 0.0001 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | $secs = $1 * $secs{ lc($2) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | if ( $secs =~ /^(\d*\.?\d*)\s*([smhdw]?)/i ); | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $secs; | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | # compute size | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | { | ||||||||||||||||||||||||||||||||||||||||||
| 510 | # kibiBytes (KiB), mebiBytes (MiB) | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 4 | my %size = ( '' => 1, k => 1024, m => 1048576 ); | |||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | # Digital Information Sizes Calculator | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # https://dr-lex.be/info-stuff/bytecalc.html | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 4 | ▶ | sub _size { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_size: called CC=6 SCAR=19.3
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 4 | my ( $size ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 4 | ▶ | return undef if ( !defined $size || $size eq 'unlimited' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $size or $size eq "unlimited"
MC/DC0%0/2
not defined $size or $size eq "unlimited"
not defined $size
$size eq "unlimited"
Truth table33%1/3
not(A) or B
A= not defined $sizeB= $size eq "unlimited"
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 4 | ▶ | return 0 if ( !$size || $size < 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $size or $size < 0
MC/DC50%1/2
not $size or $size < 0
not $size
$size < 0
Truth table66%2/3
not(A) or B
A= not $sizeB= $size < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 3 | ▶ | $size = $1 * $size{ lc($2) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | if ( $size =~ /^(\d*\.?\d*)\s*([km]?)/i ); | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 3 | $size = int( $size + 0.5 ); | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 530 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 531 | ## _find, iterator, keys, pairs, values | ||||||||||||||||||||||||||||||||||||||||||
| 532 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 533 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | # _find ( { getkeys => 1 }, "query string" ) | ||||||||||||||||||||||||||||||||||||||||||
| 536 | # _find ( { getvals => 1 }, "query string" ) | ||||||||||||||||||||||||||||||||||||||||||
| 537 | # _find ( "query string" ) # pairs | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 4 | ▶ | sub _find { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find: not called CC=2 SCAR=15.1
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | my $params = ref($_[0]) eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $query = shift; | |||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | MCE::Shared::Base::_find_hash( $self->[_DATA], $params, $query, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | # iterator ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 548 | # iterator ( "query string" ) | ||||||||||||||||||||||||||||||||||||||||||
| 549 | # iterator ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | sub iterator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | my ( $self, @keys ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $data = $self->[_DATA]; | |||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | if ( ! @keys ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | @keys = $self->keys; | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | ▶ | elsif ( @keys == 1 && $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@keys == 1 and $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@keys == 1 and $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@keys == 1
$keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table0%0/3
A and B
A= @keys == 1B= $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | @keys = $self->keys($keys[0]); | |||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $self->_prune_head; | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | return unless @keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | my $key = shift @keys; | |||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | return ( $key => $data->{ $key } ); | |||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | # keys ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 573 | # keys ( "query string" ) | ||||||||||||||||||||||||||||||||||||||||||
| 574 | # keys ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 11 | ▶ | sub keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys: called CC=6 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 578 | 11 | $self->_prune_head; | |||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 11 | ▶ | if ( @_ == 1 && $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@_ == 1
$_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table33%1/3
A and B
A= @_ == 1B= $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $self->_find( { getkeys => 1 }, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | elsif ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 8 | my $data = $self->[_DATA]; | |||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | @_ ? map { exists $data->{ $_ } ? $_ : undef } @_ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | : $self->_keys; | ||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 3 | scalar CORE::keys %{ $self->[_DATA] }; | |||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | # _keys ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 8 | ▶ | sub _keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 32 | ▶ | map { ''. $_ } ${ $self->[_GCNT] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | ? grep defined($_), reverse @{ $self->[_KEYS] } | |||||||||||||||||||||||||||||||||||||||||
| 600 | 8 | : reverse @{ $self->[_KEYS] }; | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | # pairs ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 604 | # pairs ( "query string" ) | ||||||||||||||||||||||||||||||||||||||||||
| 605 | # pairs ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | sub pairs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pairs: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | $self->_prune_head; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | if ( @_ == 1 && $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@_ == 1
$_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table0%0/3
A and B
A= @_ == 1B= $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | $self->_find( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | elsif ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my $data = $self->[_DATA]; | |||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | map { $_ => $data->{ $_ } } ( @_ ? @_ : $self->_keys ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | scalar CORE::keys %{ $self->[_DATA] }; | |||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | # values ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 624 | # values ( "query string" ) | ||||||||||||||||||||||||||||||||||||||||||
| 625 | # values ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | 2 | ▶ | sub values { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=5 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 629 | 2 | $self->_prune_head; | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 2 | ▶ | if ( @_ == 1 && $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@_ == 1
$_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table33%1/3
A and B
A= @_ == 1B= $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | $self->_find( { getvals => 1 }, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | elsif ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | @{ $self->[_DATA] }{ ( @_ ? @_ : $self->_keys ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||
| 637 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 2 | scalar CORE::keys %{ $self->[_DATA] }; | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 643 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 644 | ## assign, max_age, max_keys, mdel, mexists, mget, mset, peek, purge | ||||||||||||||||||||||||||||||||||||||||||
| 645 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 646 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | # assign ( key, value [, key, value, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | sub assign { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assign: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | $_[0]->clear; shift()->mset(@_); | |||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | # max_age ( [ secs ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | sub max_age { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_age: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my ( $self, $secs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | my $expi = $self->[_EXPI]; | |||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | if ( @_ == 2 && defined $secs ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
@_ == 2 and defined $secs
MC/DC0%0/2
@_ == 2 and defined $secs
@_ == 2
defined $secs
Truth table0%0/3
A and B
A= @_ == 2B= defined $secs
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | ${ $expi } = MCE::Shared::Cache::_secs( $secs ); | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | elsif ( @_ == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ${ $expi } = undef; | |||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | if ( defined wantarray ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | ▶ | defined ${ $expi } ? ${ $expi } > 0 ? ${ $expi } : 'now' : 'never'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | # max_keys ( [ size ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 5 | ▶ | sub max_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_keys: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 5 | my ( $self, $size ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | 5 | ▶ | if ( @_ == 2 && defined $size ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
@_ == 2 and defined $size
MC/DC50%1/2
@_ == 2 and defined $size
@_ == 2
defined $size
Truth table66%2/3
A and B
A= @_ == 2B= defined $size
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 2 | $size = MCE::Shared::Cache::_size( $size ); | |||||||||||||||||||||||||||||||||||||||||
| 679 | 2 | $self->purge; | |||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | 2 | my ( $data, $keys, $indx, $begi ) = @{ $self }; | |||||||||||||||||||||||||||||||||||||||||
| 682 | 2 | my $count = CORE::keys( %{ $data } ) - $size; | |||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | # evict the least used keys | ||||||||||||||||||||||||||||||||||||||||||
| 685 | 2 | ▶ | while ( $count-- > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 3 | my $key = shift @{ $keys }; | |||||||||||||||||||||||||||||||||||||||||
| 687 | 3 | ${ $begi }++, delete($data->{ $key }), delete($indx->{ $key }); | |||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | # safety to not overrun | ||||||||||||||||||||||||||||||||||||||||||
| 690 | 3 | ▶ | $self->purge if ( ${ $begi } > 1e9 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | 2 | ${ $self->[_SIZE] } = $size; | |||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||
| 695 | elsif ( @_ == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | ${ $self->[_SIZE] } = undef; | |||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | 5 | ▶ | if ( defined wantarray ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | 3 | ▶ | defined ${ $self->[_SIZE] } ? ${ $self->[_SIZE] } : 'unlimited'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | # mdel ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | sub mdel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mdel: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | $cnt++, $self->del( $key ) if $self->exists( $key ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | $cnt; | |||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | # mexists ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | ▶ | sub mexists { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mexists: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | return '' unless $self->exists( shift ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||
| 730 | # mget ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | sub mget { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mget: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | @_ ? map { $self->get( $_ ) } @_ : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | # mset ( key, value [, key, value, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | 1 | ▶ | sub mset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mset: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 1 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 10 | $self->set( splice( @_, 0, 2 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | 1 | ▶ | defined wantarray ? $self->SCALAR : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||
| 750 | # peek ( key ) | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | sub peek { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peek: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | $_[0]->[_DATA]{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||
| 756 | # purge ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | 2 | ▶ | sub purge { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
purge: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | 2 | my ( $data, $keys, $indx, $begi, $gcnt ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 760 | 2 | my $i; $i = ${ $begi } = ${ $gcnt } = 0; | |||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | # purge in-place for minimum memory consumption | ||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | 2 | my $time = time; | |||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 2 | for my $k ( @{ $keys } ) { | |||||||||||||||||||||||||||||||||||||||||
| 767 | 7 | ▶ | delete($data->{ $k }), delete($indx->{ $k }), next | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $k and $k >= 0 and $k < $time
defined $k and $k >= 0
MC/DC0%0/3
defined $k and $k >= 0 and $k < $time
defined $k
$k >= 0
$k < $time
Truth table25%1/4
A and B and C
A= defined $kB= $k >= 0C= $k < $time
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | if ( defined $k && $k >= 0 && $k < $time ); | ||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | 7 | ▶ | $keys->[ $i ] = $k, $indx->{ $k } = $i++ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | if ( defined $k ); | ||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 2 | splice @{ $keys }, $i; | |||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||
| 776 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 780 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 781 | ## Sugar API, mostly resembles https://redis.io/commands#string primitives. | ||||||||||||||||||||||||||||||||||||||||||
| 782 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 783 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | # append ( key, string [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | sub append { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[3] ? $_[3] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | length( $_[0]->[_DATA]{ $_[1] } .= $_[2] // '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[2] // ""
MC/DC0%0/1
$_[2] // ""
$_[2]
Truth table0%0/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | # decr ( key [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | sub decr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[2] ? $_[2] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | --$_[0]->[_DATA]{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | # decrby ( key, number [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | sub decrby { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decrby: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[3] ? $_[3] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | $_[0]->[_DATA]{ $_[1] } -= $_[2] || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[2] || 0
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table0%0/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | # incr ( key [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | ▶ | sub incr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
incr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[2] ? $_[2] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ++$_[0]->[_DATA]{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | # incrby ( key, number [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | ▶ | sub incrby { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
incrby: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[3] ? $_[3] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | $_[0]->[_DATA]{ $_[1] } += $_[2] || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[2] || 0
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table0%0/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||
| 820 | # getdecr ( key [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | sub getdecr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getdecr: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[2] ? $_[2] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | $_[0]->[_DATA]{ $_[1] }-- // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[0][0]{$_[1]}-- // 0
MC/DC0%0/1
$_[0][0]{$_[1]}-- // 0
$_[0][0]{$_[1]}--
Truth table0%0/2
A
A= $_[0][0]{$_[1]}--
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | # getincr ( key [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | ▶ | sub getincr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getincr: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[2] ? $_[2] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | ▶ | $_[0]->[_DATA]{ $_[1] }++ // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[0][0]{$_[1]}++ // 0
MC/DC0%0/1
$_[0][0]{$_[1]}++ // 0
$_[0][0]{$_[1]}++
Truth table0%0/2
A
A= $_[0][0]{$_[1]}++
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | # getset ( key, value [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | ▶ | sub getset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[3] ? $_[3] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | my $old = $_[0]->[_DATA]{ $_[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | $_[0]->[_DATA]{ $_[1] } = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | $old; | |||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | # setnx ( key, value [, expires_in ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | ▶ | sub setnx { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setnx: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | ▶ | return 0 if ( exists $_[0]->[_DATA]{ $_[1] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | $_[0]->_inskey( $_[1], defined $_[3] ? $_[3] : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | $_[0]->[_DATA]{ $_[1] } = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | # len ( key ) | ||||||||||||||||||||||||||||||||||||||||||
| 857 | # len ( ) | ||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||
| 859 | 6 | ▶ | sub len { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
len: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | 6 | $_[0]->_prune_head; | |||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | ( defined $_[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 863 | ? length $_[0]->get( $_[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 864 | 6 | ▶ | : scalar CORE::keys %{ $_[0]->[_DATA] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||
| 867 | { | ||||||||||||||||||||||||||||||||||||||||||
| 868 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | 4 | *{ __PACKAGE__.'::new' } = \&TIEHASH; | |||||||||||||||||||||||||||||||||||||||||
| 871 | 4 | *{ __PACKAGE__.'::set' } = \&STORE; | |||||||||||||||||||||||||||||||||||||||||
| 872 | 4 | *{ __PACKAGE__.'::get' } = \&FETCH; | |||||||||||||||||||||||||||||||||||||||||
| 873 | 4 | *{ __PACKAGE__.'::delete' } = \&DELETE; | |||||||||||||||||||||||||||||||||||||||||
| 874 | 4 | *{ __PACKAGE__.'::exists' } = \&EXISTS; | |||||||||||||||||||||||||||||||||||||||||
| 875 | 4 | *{ __PACKAGE__.'::clear' } = \&CLEAR; | |||||||||||||||||||||||||||||||||||||||||
| 876 | 4 | *{ __PACKAGE__.'::del' } = \&delete; | |||||||||||||||||||||||||||||||||||||||||
| 877 | 4 | *{ __PACKAGE__.'::remove' } = \&delete; | |||||||||||||||||||||||||||||||||||||||||
| 878 | 4 | *{ __PACKAGE__.'::merge' } = \&mset; | |||||||||||||||||||||||||||||||||||||||||
| 879 | 4 | *{ __PACKAGE__.'::vals' } = \&values; | |||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||
| 882 | # For on-demand hash-like dereferencing. | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | package # hide from rpm | ||||||||||||||||||||||||||||||||||||||||||
| 885 | MCE::Shared::Cache::_href; | ||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | ▶ | sub TIEHASH { $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | __END__ | ||||||||||||||||||||||||||||||||||||||||||