| 1 | package Net::Clacks::ClacksCache; | ||||||||||||||||||||||||||||||||
| 2 | #---AUTOPRAGMASTART--- | ||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use diagnostics; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp qw[carp croak confess cluck longmess shortmess]; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = 38; | |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use autodie qw( close ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Array::Contains; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Encode qw(is_utf8 encode_utf8 decode_utf8); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use builtin qw[true false is_bool]; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | no warnings qw(experimental::builtin); ## no critic (TestingAndDebugging::ProhibitNoWarnings) | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | #---AUTOPRAGMAEND--- | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Net::Clacks::Client; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use YAML::Syck; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub new($proto, %config) { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | my $self = bless \%config, $class; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | # Connect on first use | ||||||||||||||||||||||||||||||||
| 29 | #$self->reconnect(); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 0 | $self->{initfromhandle} = 0; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if(!defined($self->{user})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | 0 | croak("User not defined!"); | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if(!defined($self->{password})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 0 | croak("Password not defined!"); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub newFromHandle($proto, $clacks) { | ||||||||||||||||||||||||||||||
|
Subroutine
newFromHandle: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 0 | $self->{initfromhandle} = 1; | |||||||||||||||||||||||||||||||
| 51 | 0 | $self->{clacks} = $clacks; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | $self->extraInits(); # Hook for application specific inits | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub reconnect($self) { | ||||||||||||||||||||||||||||||
|
Subroutine
reconnect: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return if($self->{initfromhandle}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return if(defined($self->{clacks})); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 0 | my $clacks; | |||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if(defined($self->{host}) && defined($self->{port})) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $self->{"host"} and defined $self->{"port"}
MC/DC0%0/2
defined $self->{"host"} and defined $self->{"port"}
defined $self->{"host"}
defined $self->{"port"}
Truth table0%0/3
A and B
A= defined $self->{"host"}B= defined $self->{"port"}
| |||||||||||||||||||||||||||||||||
| 64 | $clacks = Net::Clacks::Client->new($self->{host}, $self->{port}, | ||||||||||||||||||||||||||||||||
| 65 | $self->{user}, $self->{password}, | ||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $self->{APPNAME} . '/' . $VERSION, 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | or croak("Can't connect to Clacks server"); | ||||||||||||||||||||||||||||||||
| 68 | } elsif(defined($self->{socketpath})) { | ||||||||||||||||||||||||||||||||
| 69 | $clacks = Net::Clacks::Client->newSocket($self->{socketpath}, | ||||||||||||||||||||||||||||||||
| 70 | $self->{user}, $self->{password}, | ||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->{APPNAME} . '/' . $VERSION, 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | or croak("Can't connect to Clacks server"); | ||||||||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||||||
| 74 | 0 | croak("No valid connection configured. Don't know where to connect to!"); | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | 0 | $self->{clacks} = $clacks; | |||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | $self->{clacks}->disablePing(); # Webclient doesn't know when it is called again | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | $self->set("VERSION::" . $self->{APPNAME}, $VERSION); | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | $self->{clacks}->activate_memcached_compat; | |||||||||||||||||||||||||||||||
| 83 | 0 | $self->{clacks}->disablePing(); | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 0 | $self->extraInits(); # Hook for application specific inits | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | return; | |||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub extraInits($self) { | ||||||||||||||||||||||||||||||
|
Subroutine
extraInits: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 91 | # Hook for application specific inits | ||||||||||||||||||||||||||||||||
| 92 | 0 | return; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub extraDestroys($self) { | ||||||||||||||||||||||||||||||
|
Subroutine
extraDestroys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 96 | # Hook for application specific destroys | ||||||||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub fastdisconnect($self) { | ||||||||||||||||||||||||||||||
|
Subroutine
fastdisconnect: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return if(!defined($self->{clacks})); # never connected, nothing to do | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 102 | 0 | eval { ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) | |||||||||||||||||||||||||||||||
| 103 | 0 | $self->{clacks}->fastdisconnect(); | |||||||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 0 | return; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub disconnect($self) { | ||||||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return if(!defined($self->{clacks})); # never connected, nothing to do | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 0 | eval { ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) | |||||||||||||||||||||||||||||||
| 112 | 0 | $self->{clacks}->disconnect(); | |||||||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 0 | return; | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub DESTROY($self) { | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 119 | # During Perl's global destruction phase, package symbol tables are torn | ||||||||||||||||||||||||||||||||
| 120 | # down in arbitrary order. By the time DESTROY runs here the inner | ||||||||||||||||||||||||||||||||
| 121 | # Net::Clacks::Client (and IO::Socket::SSL, IO::Select, etc.) may already | ||||||||||||||||||||||||||||||||
| 122 | # be unavailable. Skip cleanup entirely in that phase — the kernel closes | ||||||||||||||||||||||||||||||||
| 123 | # any leftover FD on process exit and the server detects EOF. | ||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return if(${^GLOBAL_PHASE} eq 'DESTRUCT'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | # Outside global destruction, do a *fast* close (no flush, no QUIT, no | ||||||||||||||||||||||||||||||||
| 127 | # sleeps). DESTROY can run at moments where the graceful path is | ||||||||||||||||||||||||||||||||
| 128 | # inappropriate (worker child unwinding after fork, exception | ||||||||||||||||||||||||||||||||
| 129 | # propagation, local-block exit). Callers who want a graceful protocol- | ||||||||||||||||||||||||||||||||
| 130 | # level close should call $cache->disconnect() explicitly first. | ||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if(defined($self->{clacks})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 0 | eval { ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) | |||||||||||||||||||||||||||||||
| 133 | 0 | $self->{clacks}->fastdisconnect(); | |||||||||||||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | # Wrap extraDestroys too — a subclass override might throw during | ||||||||||||||||||||||||||||||||
| 138 | # teardown, and we don't want that to escape DESTROY (Perl turns | ||||||||||||||||||||||||||||||||
| 139 | # propagated exceptions out of DESTROY into "(in cleanup)" warnings). | ||||||||||||||||||||||||||||||||
| 140 | 0 | eval { ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) | |||||||||||||||||||||||||||||||
| 141 | 0 | $self->extraDestroys(); | |||||||||||||||||||||||||||||||
| 142 | }; | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 0 | return; | |||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub get($self, $key) { | ||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 148 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 0 | $key = $self->sanitize_key($key); | |||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 0 | my $value = $self->{clacks}->retrieve($key); | |||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | return if(!defined($value)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if($value =~ /^PAGECAMELCLACKSYAMLB64\:(.+)/o) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 156 | 0 | $value = decode_base64($1); | |||||||||||||||||||||||||||||||
| 157 | 0 | $value = Load($value); | |||||||||||||||||||||||||||||||
| 158 | 0 | $value = $self->deref($value); | |||||||||||||||||||||||||||||||
| 159 | } elsif($value =~ /^PAGECAMELCLACKSB64\:(.+)/o) { | ||||||||||||||||||||||||||||||||
| 160 | 0 | $value = decode_base64($1); | |||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | 0 | return $value; | |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub set($self, $key, $data) { ## no critic (NamingConventions::ProhibitAmbiguousNames) | ||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 166 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 0 | $key = $self->sanitize_key($key); | |||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if(ref $data ne '') { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 171 | #$data = 'PAGECAMELCLACKSYAMLB64: ' . encode_base64(Dump($data), ''); | ||||||||||||||||||||||||||||||||
| 172 | 0 | $data = Dump($data); | |||||||||||||||||||||||||||||||
| 173 | 0 | $data = 'PAGECAMELCLACKSYAMLB64: ' . encode_base64($data, ''); | |||||||||||||||||||||||||||||||
| 174 | } elsif($data =~ /^PAGECAMELCLACKSB64/o) { | ||||||||||||||||||||||||||||||||
| 175 | # Already encoded? Clacks injection alert? Just don't store the thing... | ||||||||||||||||||||||||||||||||
| 176 | 0 | return false; | |||||||||||||||||||||||||||||||
| 177 | ▶ | } elsif($data =~ /\n/o || $data =~ /\r/o) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$data =~ /\n/ou or $data =~ /\r/ou
MC/DC0%0/2
$data =~ /\n/ou or $data =~ /\r/ou
$data =~ /\n/ou
$data =~ /\r/ou
Truth table0%0/3
A or B
A= $data =~ /\n/ouB= $data =~ /\r/ou
| |||||||||||||||||||||||||||||||||
| 178 | 0 | $data = 'PAGECAMELCLACKSB64:' . encode_base64($data, ''); | |||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | 0 | $self->{clacks}->store($key, $data); | |||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 0 | return true; | |||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub delete($self, $key) { ## no critic(BuiltinHomonyms) | ||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 187 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | 0 | $key = $self->sanitize_key($key); | |||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 0 | $self->{clacks}->remove($key); | |||||||||||||||||||||||||||||||
| 192 | 0 | return true; | |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub incr($self, $key, $stepsize = '') { | ||||||||||||||||||||||||||||||
|
Subroutine
incr: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 196 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 0 | $key = $self->sanitize_key($key); | |||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if(!defined($stepsize) || $stepsize eq '') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $stepsize or $stepsize eq ""
MC/DC0%0/2
not defined $stepsize or $stepsize eq ""
not defined $stepsize
$stepsize eq ""
Truth table0%0/3
not(A) or B
A= not defined $stepsizeB= $stepsize eq ""
| |||||||||||||||||||||||||||||||||
| 201 | 0 | $self->{clacks}->increment($key); | |||||||||||||||||||||||||||||||
| 202 | } else { | ||||||||||||||||||||||||||||||||
| 203 | 0 | $self->{clacks}->increment($key, $stepsize); | |||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | 0 | return true; | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub decr($self, $key, $stepsize = '') { | ||||||||||||||||||||||||||||||
|
Subroutine
decr: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 209 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | 0 | $key = $self->sanitize_key($key); | |||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if(!defined($stepsize) || $stepsize eq '') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $stepsize or $stepsize eq ""
MC/DC0%0/2
not defined $stepsize or $stepsize eq ""
not defined $stepsize
$stepsize eq ""
Truth table0%0/3
not(A) or B
A= not defined $stepsizeB= $stepsize eq ""
| |||||||||||||||||||||||||||||||||
| 214 | 0 | $self->{clacks}->decrement($key); | |||||||||||||||||||||||||||||||
| 215 | } else { | ||||||||||||||||||||||||||||||||
| 216 | 0 | $self->{clacks}->decrement($key, $stepsize); | |||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | 0 | return true; | |||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub clacks_set($self, $key, $data) { | ||||||||||||||||||||||||||||||
|
Subroutine
clacks_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 222 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | 0 | $key = $self->sanitize_key($key); | |||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 0 | $self->{clacks}->set($key, $data); | |||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 0 | return true; | |||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub clacks_notify($self, $key) { | ||||||||||||||||||||||||||||||
|
Subroutine
clacks_notify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 232 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | 0 | $key = $self->sanitize_key($key); | |||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | 0 | $self->{clacks}->notify($key); | |||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 0 | return true; | |||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | sub clacks_keylist($self) { | ||||||||||||||||||||||||||||||
|
Subroutine
clacks_keylist: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 242 | 0 | $self->reconnect(); # Make sure we are connected | |||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 0 | return $self->{clacks}->keylist(); | |||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub sanitize_key($self, $key) { | ||||||||||||||||||||||||||||||
|
Subroutine
sanitize_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 249 | # Certain chars are not allowed in keys for protocol reason. | ||||||||||||||||||||||||||||||||
| 250 | # We handle this by substituting them with a tripple underline | ||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | 0 | $key =~ s/\ /___/go; | |||||||||||||||||||||||||||||||
| 253 | 0 | $key =~ s/\=/___/go; | |||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | 0 | return $key; | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub deref($self, $val) { | ||||||||||||||||||||||||||||||
|
Subroutine
deref: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | return if(!defined($val)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | while(ref($val) eq "SCALAR" || ref($val) eq "REF") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $val eq "SCALAR" or ref $val eq "REF"
MC/DC0%0/2
ref $val eq "SCALAR" or ref $val eq "REF"
ref $val eq "SCALAR"
ref $val eq "REF"
Truth table0%0/3
A or B
A= ref $val eq "SCALAR"B= ref $val eq "REF"
| |||||||||||||||||||||||||||||||||
| 262 | 0 | $val = ${$val}; | |||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | last if(!defined($val)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | 0 | return $val; | |||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||
| 269 | 1 | 1; | |||||||||||||||||||||||||||||||
| 270 | __END__ | ||||||||||||||||||||||||||||||||