| 1 | package Web::Session::Redis; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Apache::Session; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Web::Session::Store::Redis; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Web::Session::Generate::SHA256; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Apache::Session::Lock::Null; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Web::Session::Serialize::JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Web::Session::_common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | our $VERSION = '1.0.0'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | our @ISA = qw(Apache::Session); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub populate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
populate: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $self->{object_store} = new Web::Session::Store::Redis $self; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $self->{lock_manager} = new Apache::Session::Lock::Null $self; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $self->{generate} = \&Web::Session::Generate::SHA256::generate; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | $self->{validate} = \&Web::Session::Generate::SHA256::validate; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $self->{serialize} = \&Web::Session::Serialize::JSON::serializeLatin1; | |||||||||||||||||||||||||||||||||||||||||
| 23 | $self->{unserialize} = | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | \&Web::Session::Serialize::JSON::unserializeLatin1; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # Key name sent to Redis, see Store::Redis::keyName() | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | sub _keyName { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keyName: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | return Web::Session::Store::Redis::keyName(@_); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # SCAN patterns for searchOnExpr(). The name of a set is Latin-1 unless it | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # holds characters above U+00FF, so a wildcard may stand for such characters | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # while the literal part is not ASCII: the UTF-8 form is then scanned too | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | sub _exprPatterns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exprPatterns: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | my ( $field, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | my $pattern = _exprPattern( $field, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | my @res = ( _keyName($pattern) ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | if ( $value =~ /\*/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | my $p = $pattern; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | utf8::encode($p); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | push @res, $p unless ( $p eq $res[0] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | return @res; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub unserialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unserialize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $session = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $tmp = { serialized => $session }; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | Web::Session::Serialize::JSON::unserializeLatin1($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $tmp->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # Keys per SCAN call (a hint for Redis) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | our $SCAN_COUNT = 1000; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | # Keys per MGET: a huge index set must not block Redis with one big command | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | our $MGET_BATCH = 500; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # Like $redisObj->mget(@keys), in batches. MGET returns undef for missing | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # keys and keys that aren't strings | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub _mget { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mget: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my ( $redisObj, @keys ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | while (@keys) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | push @res, $redisObj->mget( splice( @keys, 0, $MGET_BATCH ) ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | return @res; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # Members of index sets @$sets, read in one pipeline: { set => [ keys ] }. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # A key that isn't a set is ignored; other Redis errors are raised | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | sub _smembers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_smembers: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | my ( $redisObj, $sets ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | my ( %res, $fatal ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | foreach my $set (@$sets) { | |||||||||||||||||||||||||||||||||||||||||
| 79 | $redisObj->smembers( | ||||||||||||||||||||||||||||||||||||||||||
| 80 | $set, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | my ( $reply, $err ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | $fatal //= $err unless ( $err =~ /WRONGTYPE/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$fatal //= $err
MC/DC0%0/2
$fatal //= $err
$fatal
$err
Truth table66%2/3
A //= B
A= $fatalB= $err
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | $res{$set} = $reply; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | $redisObj->wait_all_responses; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | die $fatal if ($fatal); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # Remove session KEYS[2] from index KEYS[1] only if it doesn't exist, in one | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # step: a concurrent writer may be recreating it | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 7 | our $SREM_ORPHAN = q{if redis.call('exists',KEYS[2])==0 then } | |||||||||||||||||||||||||||||||||||||||||
| 100 | . q{return redis.call('srem',KEYS[1],KEYS[2]) end return 0}; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 7 | our $lua_warned; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | # Remove orphan session $k from index set $set. Without Lua (EVAL forbidden by | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # ACL, proxy...), WATCH the session so that a concurrent writer aborts the | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # removal. $k must have been checked with isLlngKey() | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | ▶ | sub _removeOrphan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_removeOrphan: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | my ( $class, $redisObj, $set, $k ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | ▶ | return if ( eval { $redisObj->eval( $SREM_ORPHAN, 2, $set, $k ); 1 } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | unless ($lua_warned) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | $lua_warned = 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | print STDERR "Redis EVAL failed, orphan index members are removed " | |||||||||||||||||||||||||||||||||||||||||
| 113 | . "without Lua: $@\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | my $err; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | $redisObj->watch($k); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | if ( $redisObj->exists($k) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | $redisObj->unwatch; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | $redisObj->multi; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | $redisObj->srem( $set, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | $redisObj->exec; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | eval { $redisObj->discard }; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | eval { $redisObj->unwatch }; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | print STDERR "Unable to remove '$k' from index $set: $err\n"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub searchOn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchOn: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my ( $class, $args, $selectField, $value, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my %res = (); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ( $class->isIndexed( $args, $selectField ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $redisObj = $class->_getRedis($args); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $index_key = _keyName("${selectField}_$value"); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my @keys = eval { $redisObj->smembers($index_key) }; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | die $@ unless ( $@ =~ /WRONGTYPE/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | @keys = (); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | # Members of another application are neither read nor removed | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | @keys = grep { $_ and $class->isLlngKey( $args, $_ ) } @keys; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ && $class->isLlngKey($args, $_)
MC/DC0%0/2
$_ && $class->isLlngKey($args, $_)
$_
$class->isLlngKey($args, $_)
Truth table0%0/3
A && B
A= $_B= $class->isLlngKey($args, $_)
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my %values; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | @values{@keys} = _mget( $redisObj, @keys ); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | foreach my $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $tmp = $values{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | unless ($tmp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | # Lazy cleanup: remove orphan from index | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $class->_removeOrphan( $redisObj, $index_key, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $tmp = unserialize($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | # The index may be stale or shared with another field | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # ("a_b" + "c" and "a" + "b_c" give the same set name) | ||||||||||||||||||||||||||||||||||||||||||
| 165 | return | ||||||||||||||||||||||||||||||||||||||||||
| 166 | unless ( defined $tmp->{$selectField} | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | and $tmp->{$selectField} eq $value ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tmp->{$selectField} and $tmp->{$selectField} eq $value
MC/DC0%0/2
defined $tmp->{$selectField} and $tmp->{$selectField} eq $value
defined $tmp->{$selectField}
$tmp->{$selectField} eq $value
Truth table0%0/3
A and B
A= defined $tmp->{$selectField}B= $tmp->{$selectField} eq $value
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if (@fields) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $res{$k}->{$_} = $tmp->{$_} foreach (@fields); | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $res{$k} = $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | print STDERR "Error in session $k: $@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | delete $res{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | $class->get_key_from_all_sessions( | ||||||||||||||||||||||||||||||||||||||||||
| 183 | $args, | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||
| 187 | return undef | ||||||||||||||||||||||||||||||||||||||||||
| 188 | unless ( defined $entry->{$selectField} | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | and $entry->{$selectField} eq $value ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $entry->{$selectField} and $entry->{$selectField} eq $value
MC/DC0%0/2
defined $entry->{$selectField} and $entry->{$selectField} eq $value
defined $entry->{$selectField}
$entry->{$selectField} eq $value
Truth table0%0/3
A and B
A= defined $entry->{$selectField}B= $entry->{$selectField} eq $value
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (@fields) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $res{$id}->{$_} = $entry->{$_} foreach (@fields); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $res{$id} = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | # searchOnExpr() patterns: '*' is a wildcard | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub _exprRe { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exprRe: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $value = quotemeta($value); | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $value =~ s/\\\*/\.\*/g; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return qr/^$value$/; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | # Redis glob escape: MATCH patterns of SCAN must find names literally | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 10 | ▶ | sub _globEscape { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_globEscape: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 10 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 10 | $s =~ s/([*?\[\]\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 10 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # SCAN pattern of the index sets for searchOnExpr(): '*' is the only | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # wildcard of the value. The sessions are checked afterwards with _exprRe() | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 9 | ▶ | sub _exprPattern { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exprPattern: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 9 | my ( $field, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 9 | $value =~ s/([?\[\]\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 9 | return _globEscape($field) . "_$value"; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub searchOnExpr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchOnExpr: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my ( $class, $args, $selectField, $value, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my %res; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $re = _exprRe($value); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ( $class->isIndexed( $args, $selectField ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $redisObj = $class->_getRedis($args); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | foreach my $pattern ( _exprPatterns( $selectField, $value ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $cursor = 0; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my ( $new_cursor, $sets ) = | |||||||||||||||||||||||||||||||||||||||||
| 236 | $redisObj->scan( $cursor, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | MATCH => $pattern, | ||||||||||||||||||||||||||||||||||||||||||
| 238 | COUNT => $SCAN_COUNT ); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # The sets of a SCAN page are read together: a few round trips | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # instead of two per set. Members of another application are | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # neither read nor removed | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $members = _smembers( $redisObj, $sets ); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | foreach my $set ( keys %$members ) { | |||||||||||||||||||||||||||||||||||||||||
| 245 | $members->{$set} = | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | [ grep { $_ and $class->isLlngKey( $args, $_ ) } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ && $class->isLlngKey($args, $_)
MC/DC0%0/2
$_ && $class->isLlngKey($args, $_)
$_
$class->isLlngKey($args, $_)
Truth table0%0/3
A && B
A= $_B= $class->isLlngKey($args, $_)
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | @{ $members->{$set} } ]; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my @keys = grep { !$seen{$_}++ } map { @$_ } values %$members; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my %values; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | @values{@keys} = _mget( $redisObj, @keys ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | foreach my $set ( keys %$members ) { | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | foreach my $k ( @{ $members->{$set} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $v = $values{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | unless ($v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | # Lazy cleanup: remove orphan from index | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $class->_removeOrphan( $redisObj, $set, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $tmp = eval { unserialize($v) }; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ( $@ or ref($tmp) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or ref $tmp ne "HASH"
MC/DC0%0/2
$@ or ref $tmp ne "HASH"
$@
ref $tmp ne "HASH"
Truth table0%0/3
A or B
A= $@B= ref $tmp ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | print STDERR "Error in session $k: " | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "not a session\n"
MC/DC0%0/1
$@ || "not a session\n"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | . ( $@ || "not a session\n" ); | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | # The pattern may match sets of another field | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | unless ( defined $tmp->{$selectField} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tmp->{$selectField} and $tmp->{$selectField} =~ /$re/
MC/DC0%0/2
defined $tmp->{$selectField} and $tmp->{$selectField} =~ /$re/
defined $tmp->{$selectField}
$tmp->{$selectField} =~ /$re/
Truth table0%0/3
A and B
A= defined $tmp->{$selectField}B= $tmp->{$selectField} =~ /$re/
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | and $tmp->{$selectField} =~ $re ) | ||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $res{$k} = $class->extractFields( $tmp, @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $cursor = $new_cursor; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } while ( $cursor != 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 282 | $class->get_key_from_all_sessions( | ||||||||||||||||||||||||||||||||||||||||||
| 283 | $args, | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ( $entry, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | return undef unless ( $entry->{$selectField} =~ $re ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $res{$id} = $class->extractFields( $entry, @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub searchLt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchLt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return $class->_searchCompare( '<', @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | sub searchGt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchGt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return $class->_searchCompare( '>', @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | # Trimmed number, or undef | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub _number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_number: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | return undef unless ( defined($v) and !ref($v) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $v and not ref $v
MC/DC0%0/2
defined $v and not ref $v
defined $v
not ref $v
Truth table0%0/3
A and not(B)
A= defined $vB= not ref $v
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $v =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | return $v =~ /^-?[0-9]+(?:\.[0-9]+)?\z/ ? $v : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | # Sessions where $selectField isn't a number (see _number()) are skipped. | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # Indexed field: SCAN walks the keyspace server-side and returns only the | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # index sets of $selectField; only sets holding a matching value are read. | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # Used by purges: Redis errors are reported and the sets ignored | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub _searchCompare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_searchCompare: not called CC=19 SCAR=59.4
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my ( $class, $op, $args, $selectField, $value, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | # LLNG CLI keeps spaces around the value ("--where 'f < 123 '") | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $value = _number($value); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | unless ( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | print STDERR 'search' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | . ( $op eq '<' ? 'Lt' : 'Gt' ) | ||||||||||||||||||||||||||||||||||||||||||
| 325 | . ": value must be a number\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | my $test = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $v = _number(shift); | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return 0 unless ( defined $v ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | return $op eq '<' ? $v < $value : $v > $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my %res; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | unless ( $class->isIndexed( $args, $selectField ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | $class->get_key_from_all_sessions( | ||||||||||||||||||||||||||||||||||||||||||
| 336 | $args, | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my ( $entry, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 339 | $res{$id} = $class->extractFields( $entry, @fields ) | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if ( $test->( $entry->{$selectField} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $redisObj = $class->_getRedis($args); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $prefix = "${selectField}_"; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ( my $pattern = $prefix ) =~ s/([*?\[\]\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $cursor = 0; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my ( $new_cursor, $sets ) = | |||||||||||||||||||||||||||||||||||||||||
| 353 | $redisObj->scan( $cursor, MATCH => "$pattern*" ); | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | # Sets of other fields ("${selectField}_x_1") aren't numbers | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | foreach my $set ( | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | grep { $test->( substr( $_, length($prefix) ) ) } @$sets ) | |||||||||||||||||||||||||||||||||||||||||
| 358 | { | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my @keys = eval { $redisObj->smembers($set) }; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | print STDERR "Error when reading index $set: $@\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | unless ( $@ =~ /WRONGTYPE/ ); | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | foreach my $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | # Members of another application are neither read nor removed | ||||||||||||||||||||||||||||||||||||||||||
| 368 | next | ||||||||||||||||||||||||||||||||||||||||||
| 369 | unless ( $k | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | and !exists $res{$k} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$k and not exists $res{$k} and $class->isLlngKey($args, $k)
$k and not exists $res{$k}
MC/DC0%0/3
$k and not exists $res{$k} and $class->isLlngKey($args, $k)
$k
not exists $res{$k}
$class->isLlngKey($args, $k)
Truth table0%0/4
A and not(B) and C
A= $kB= not exists $res{$k}C= $class->isLlngKey($args, $k)
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | and $class->isLlngKey( $args, $k ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $v = eval { $redisObj->get($k) }; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | print STDERR "Error when reading $k: $@\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | unless ( $@ =~ /WRONGTYPE/ ); | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | unless ($v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | # Lazy cleanup: remove orphan from index | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $class->_removeOrphan( $redisObj, $set, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $tmp = eval { unserialize($v) }; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ( $@ or ref($tmp) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or ref $tmp ne "HASH"
MC/DC0%0/2
$@ or ref $tmp ne "HASH"
$@
ref $tmp ne "HASH"
Truth table0%0/3
A or B
A= $@B= ref $tmp ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | print STDERR "Error in session $k: " | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "not a session\n"
MC/DC0%0/1
$@ || "not a session\n"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | . ( $@ || "not a session\n" ); | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | # The index may be stale: check the session itself | ||||||||||||||||||||||||||||||||||||||||||
| 392 | $res{$k} = $class->extractFields( $tmp, @fields ) | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ( $test->( $tmp->{$selectField} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $cursor = $new_cursor; | |||||||||||||||||||||||||||||||||||||||||
| 397 | } while ( $cursor != 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | # Decide if a session must be purged. Like Lemonldap::NG's generic purge, | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # only a missing _utime means "expired": any other missing field is not lower | ||||||||||||||||||||||||||||||||||||||||||
| 403 | # than the threshold (so a session without _lastSeen is not purged by it). | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 13 | ▶ | sub _isDominated { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_isDominated: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 13 | my ( $class, $v, $rule ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | # Empty or data-less sessions should be purged | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 13 | ▶ | return 1 if ( !$v || !%$v || !exists $v->{_session_id} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$v and %$v and exists $v->{"_session_id"}
$v and %$v
MC/DC100%3/3
$v and %$v and exists $v->{"_session_id"}
$v
%$v
exists $v->{"_session_id"}
Truth table100%4/4
A and B and C
A= $vB= %$vC= exists $v->{"_session_id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 10 | ▶ | if ( $rule->{or} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 5 | foreach ( keys %{ $rule->{or} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 411 | 8 | ▶ | if ( !defined( $v->{$_} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | # Session without _utime: treat as expired | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 2 | ▶ | return 1 if $_ eq '_utime'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 6 | ▶ | return 1 if $v->{$_} < $rule->{or}->{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | elsif ( $rule->{and} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 4 | foreach ( keys %{ $rule->{and} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 422 | 8 | ▶ | if ( !defined( $v->{$_} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | # Only a missing _utime counts as lower | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 2 | ▶ | return 0 unless $_ eq '_utime'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 6 | ▶ | return 0 unless $v->{$_} < $rule->{and}->{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 8 | ▶ | sub deleteIfLowerThan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleteIfLowerThan: called CC=5 SCAR=30.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 8 | my ( $class, $args, $rule ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | # Same contract as the SQL backends: an invalid rule deletes nothing | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 8 | ▶ | return wantarray ? ( 0, 0 ) : 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
"Web::Session::_common"->_checkRule($rule) and "Web::Session::_common"->_checkThresholds($rule)
MC/DC0%0/2
"Web::Session::_common"->_checkRule($rule) and "Web::Session::_common"->_checkThresholds($rule)
"Web::Session::_common"->_checkRule($rule)
"Web::Session::_common"->_checkThresholds($rule)
Truth table66%2/3
A and B
A= "Web::Session::_common"->_checkRule($rule)B= "Web::Session::_common"->_checkThresholds($rule)
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | unless ( Web::Session::_common->_checkRule($rule) | ||||||||||||||||||||||||||||||||||||||||||
| 441 | and Web::Session::_common->_checkThresholds($rule) ); | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $deleted = 0; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my $redisObj = $class->_getRedis($args); | |||||||||||||||||||||||||||||||||||||||||
| 444 | my $index = | ||||||||||||||||||||||||||||||||||||||||||
| 445 | ref( $args->{Index} ) | ||||||||||||||||||||||||||||||||||||||||||
| 446 | ? $args->{Index} | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | : [ split /\s+/, $args->{Index} ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | $class->get_key_from_all_sessions( | ||||||||||||||||||||||||||||||||||||||||||
| 450 | $args, | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my ( $v, $k ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | if ( $rule->{not} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | foreach ( keys %{ $rule->{not} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | if (defined( $v->{$_} ) and $v->{$_} eq $rule->{not}->{$_}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $v->{$_} and $v->{$_} eq $rule->{"not"}{$_}
MC/DC0%0/2
defined $v->{$_} and $v->{$_} eq $rule->{"not"}{$_}
defined $v->{$_}
$v->{$_} eq $rule->{"not"}{$_}
Truth table0%0/3
A and B
A= defined $v->{$_}B= $v->{$_} eq $rule->{"not"}{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $dominated = $class->_isDominated( $v, $rule ); | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if ($dominated) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | # Clean up index entries before deleting the session | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my $index_ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | foreach my $i (@$index) { | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $t = $v->{$i}; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | next unless ( defined($t) and length($t) > 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $t and length $t > 0
MC/DC0%0/2
defined $t and length $t > 0
defined $t
length $t > 0
Truth table0%0/3
A and B
A= defined $tB= length $t > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | eval { $redisObj->srem( _keyName("${i}_$t"), $k ) }; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | warn "Failed to remove '$k' from index '${i}_$t': $@"; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $index_ok = 0; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if ($index_ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $redisObj->del($k); | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $deleted++; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | warn "Skipping deletion of session '$k' due to index cleanup failure"; | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 482 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | return ( 1, $deleted ); | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | sub extractFields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extractFields: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | my ( $class, $entry, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if (@fields) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $res->{$_} = $entry->{$_} foreach (@fields); | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $res = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | sub isIndexed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isIndexed: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my ( $class, $args, $field ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 501 | my $indexes = | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | return grep { $_ eq $field } @$indexes; | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 7 | my %keysRe_re; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 6 | ▶ | sub isLlngKey { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isLlngKey: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 6 | my ( $class, $args, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 509 | 6 | ▶ | my $expr = $args->{keysRe} || '^[0-9a-f]{32,}$'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'keysRe'} || '^[0-9a-f]{32,}$'
MC/DC100%1/1
$args->{'keysRe'} || '^[0-9a-f]{32,}$'
$args->{'keysRe'}
Truth table100%2/2
A
A= $args->{'keysRe'}
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | # Compile per expression: a process may use several keysRe | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 6 | ▶ | $keysRe_re{$expr} = qr/$expr/ unless ( exists $keysRe_re{$expr} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 6 | return ( $name =~ $keysRe_re{$expr} ); | |||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | sub get_key_from_all_sessions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_key_from_all_sessions: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my ( $class, $args, $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my %res; | |||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my $redisObj = $class->_getRedis($args); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my $cursor = 0; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my ( $new_cursor, $keys ) = $redisObj->scan($cursor); | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | foreach my $k (@$keys) { | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | # Keep only our keys | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | next unless $class->isLlngKey( $args, $k ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | # Don't scan sets,... | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | next unless $redisObj->type($k) eq 'string'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my $v = $redisObj->get($k); | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | next unless $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my $tmp = unserialize($v); | |||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | if ( ref($data) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $tmp = &$data( $tmp, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | $res{$k} = $tmp if ( defined($tmp) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | elsif ($data) { | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | $data = [$data] unless ( ref($data) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $res{$k}->{$_} = $tmp->{$_} foreach (@$data); | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | $res{$k} = $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | print STDERR "Error in session $k: $@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | # Don't delete, it may own to another app | ||||||||||||||||||||||||||||||||||||||||||
| 551 | #delete $res{$k}; | ||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $cursor = $new_cursor; | |||||||||||||||||||||||||||||||||||||||||
| 555 | } while ( $cursor != 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | sub _getRedis { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getRedis: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my ( $class, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | return Web::Session::Store::Redis->_getRedis($args); | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 565 | __END__ | ||||||||||||||||||||||||||||||||||||||||||