| 1 | package AnyEvent::RipeRedis; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use 5.008000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | our $VERSION = '0.48'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use AnyEvent::RipeRedis::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use Scalar::Util qw( looks_like_number weaken ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use Digest::SHA qw( sha1_hex ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | my %ERROR_CODES; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | %ERROR_CODES = %AnyEvent::RipeRedis::Error::ERROR_CODES; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | our @EXPORT_OK = keys %ERROR_CODES; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | our %EXPORT_TAGS = ( err_codes => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Default values | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 13 | D_HOST => 'localhost', | |||||||||||||||||||||||||||||||||||||||||
| 29 | D_PORT => 6379, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | D_DB_INDEX => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | %ERROR_CODES, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Operation status | ||||||||||||||||||||||||||||||||||||||||||
| 35 | S_NEED_DO => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | S_IN_PROGRESS => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | S_DONE => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # String terminator | ||||||||||||||||||||||||||||||||||||||||||
| 40 | EOL => "\r\n", | ||||||||||||||||||||||||||||||||||||||||||
| 41 | EOL_LENGTH => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | my %SUB_CMDS = ( | |||||||||||||||||||||||||||||||||||||||||
| 45 | subscribe => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | psubscribe => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 13 | my %SUBUNSUB_CMDS = ( | |||||||||||||||||||||||||||||||||||||||||
| 50 | %SUB_CMDS, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | unsubscribe => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | punsubscribe => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 13 | my %MESSAGE_TYPES = ( | |||||||||||||||||||||||||||||||||||||||||
| 56 | message => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | pmessage => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 13 | my %NEED_PREPROCESS = ( | |||||||||||||||||||||||||||||||||||||||||
| 61 | multi => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | exec => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | discard => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | eval_cached => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | %SUBUNSUB_CMDS, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 13 | my %NEED_POSTPROCESS = ( | |||||||||||||||||||||||||||||||||||||||||
| 69 | info => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | cluster_info => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | select => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | quit => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 13 | my %ERR_PREFS_MAP = ( | |||||||||||||||||||||||||||||||||||||||||
| 76 | LOADING => E_LOADING_DATASET, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | NOSCRIPT => E_NO_SCRIPT, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | BUSY => E_BUSY, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | MASTERDOWN => E_MASTER_DOWN, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | MISCONF => E_MISCONF, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | READONLY => E_READONLY, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | OOM => E_OOM, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | EXECABORT => E_EXEC_ABORT, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | NOAUTH => E_NO_AUTH, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | WRONGTYPE => E_WRONG_TYPE, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | NOREPLICAS => E_NO_REPLICAS, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | BUSYKEY => E_BUSY_KEY, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | CROSSSLOT => E_CROSS_SLOT, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | TRYAGAIN => E_TRY_AGAIN, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ASK => E_ASK, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | MOVED => E_MOVED, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | CLUSTERDOWN => E_CLUSTER_DOWN, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | NOTBUSY => E_NOT_BUSY, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 13 | my %EVAL_CACHE; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 13 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 13 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 13 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 13 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 13 | ▶ | $self->{host} = $params{host} || D_HOST; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'host'} || 'localhost'
MC/DC0%0/1
$params{'host'} || 'localhost'
$params{'host'}
Truth table50%1/2
A
A= $params{'host'}
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 13 | ▶ | $self->{port} = $params{port} || D_PORT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'port'} || 6379
MC/DC0%0/1
$params{'port'} || 6379
$params{'port'}
Truth table50%1/2
A
A= $params{'port'}
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 13 | $self->{password} = $params{password}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | $self->{database} | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 13 | ▶ | = defined $params{database} ? $params{database} : D_DB_INDEX; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 13 | ▶ | $self->{utf8} = exists $params{utf8} ? $params{utf8} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 13 | $self->{lazy} = $params{lazy}; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 13 | ▶ | $self->{reconnect} = exists $params{reconnect} ? $params{reconnect} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 13 | ▶ | $self->{handle_params} = $params{handle_params} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'handle_params'} || {}
MC/DC0%0/1
$params{'handle_params'} || {}
$params{'handle_params'}
Truth table50%1/2
A
A= $params{'handle_params'}
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 13 | $self->{on_connect} = $params{on_connect}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | $self->{on_disconnect} = $params{on_disconnect}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 13 | $self->connection_timeout( $params{connection_timeout} ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 11 | $self->read_timeout( $params{read_timeout} ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | $self->reconnect_interval( $params{reconnect_interval} ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | $self->on_error( $params{on_error} ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | $self->_reset_internals; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | $self->{_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | $self->{_temp_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | $self->{_processing_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 7 | $self->{_channels} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | $self->{_channel_cnt} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 7 | $self->{_pchannel_cnt} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 7 | ▶ | unless ( $self->{lazy} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $cmd_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $cmd = $self->_prepare( $cmd_name, [@_] ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->_execute($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $self->_disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 12 | ▶ | sub on_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_error: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 9 | my $on_error = shift; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 9 | ▶ | if ( defined $on_error ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | $self->{on_error} = $on_error; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | $self->{on_error} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | warn $err->message . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 12 | return $self->{on_error}; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # Generate accessors | ||||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 13 | ▶ | no strict qw( refs ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 13 | foreach my $name ( qw( host port database ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 180 | 39 | ▶ | *{$name} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 39 | } | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 13 | foreach my $name ( qw( connection_timeout read_timeout | |||||||||||||||||||||||||||||||||||||||||
| 187 | reconnect_interval ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 39 | ▶ | *{$name} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 54 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 45 | my $seconds = shift; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 45 | ▶ | if ( defined $seconds | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $seconds and !&looks_like_number($seconds) || $seconds < 0
not &looks_like_number($seconds) or $seconds < 0
MC/DC100%3/3
defined $seconds and !&looks_like_number($seconds) || $seconds < 0
defined $seconds
not &looks_like_number($seconds)
$seconds < 0
Truth table100%4/4
A and not(B) or C
A= defined $secondsB= not &looks_like_number($seconds)C= $seconds < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | && ( !looks_like_number($seconds) || $seconds < 0 ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 12 | croak qq{"$name" must be a positive number}; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 33 | $self->{$name} = $seconds; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 42 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 39 | }; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 13 | foreach my $name ( qw( utf8 reconnect on_connect on_disconnect ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 208 | 52 | ▶ | *{$name} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 20 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | $self->{$name} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 20 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 52 | }; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 7 | ▶ | sub _connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | $self->{_handle} = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | %{ $self->{handle_params} }, | |||||||||||||||||||||||||||||||||||||||||
| 225 | 7 | connect => [ $self->{host}, $self->{port} ], | |||||||||||||||||||||||||||||||||||||||||
| 226 | on_prepare => $self->_create_on_prepare, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | on_connect => $self->_create_on_connect, | ||||||||||||||||||||||||||||||||||||||||||
| 228 | on_connect_error => $self->_create_on_connect_error, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | on_rtimeout => $self->_create_on_rtimeout, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | on_eof => $self->_create_on_eof, | ||||||||||||||||||||||||||||||||||||||||||
| 231 | on_error => $self->_create_on_handle_error, | ||||||||||||||||||||||||||||||||||||||||||
| 232 | on_read => $self->_create_on_read, | ||||||||||||||||||||||||||||||||||||||||||
| 233 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | ▶ | sub _create_on_prepare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_prepare: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 7 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | ▶ | if ( defined $self->{connection_timeout} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | return $self->{connection_timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | ▶ | sub _create_on_connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_connect: called CC=1 SCAR=5.2
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $self->{_connected} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | unless ( defined $self->{password} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $self->{_auth_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if ( $self->{database} == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $self->{_db_selection_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( $self->{_auth_state} == S_NEED_DO ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $self->_auth; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | elsif ( $self->{_db_selection_state} == S_NEED_DO ) { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $self->_select_database; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $self->{_ready} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $self->_process_input_queue; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ( defined $self->{on_connect} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $self->{on_connect}->(); | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 7 | ▶ | sub _create_on_connect_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_connect_error: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 7 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $err_msg = pop; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 293 | "Can't connect to $self->{host}:$self->{port}: $err_msg", | ||||||||||||||||||||||||||||||||||||||||||
| 294 | E_CANT_CONN | ||||||||||||||||||||||||||||||||||||||||||
| 295 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | ▶ | sub _create_on_rtimeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_rtimeout: called CC=1 SCAR=2.9
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 7 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ( @{ $self->{_processing_queue} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $err = _new_error( 'Read timed out.', E_READ_TIMEDOUT ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | $self->{_handle}->rtimeout(undef); | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 7 | ▶ | sub _create_on_eof { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_eof: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 7 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $err = _new_error( 'Connection closed by remote host.', | |||||||||||||||||||||||||||||||||||||||||
| 323 | E_CONN_CLOSED_BY_REMOTE_HOST ); | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 325 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 7 | ▶ | sub _create_on_handle_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_handle_error: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 7 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $err_msg = pop; | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $err = _new_error( $err_msg, E_IO ); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 7 | ▶ | sub _create_on_read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_read: called CC=1 SCAR=6.2
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 7 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 7 | my $str_len; | |||||||||||||||||||||||||||||||||||||||||
| 347 | my @bufs; | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 7 | my $bufs_num = 0; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $handle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | MAIN: while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return if $handle->destroyed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $reply; | |||||||||||||||||||||||||||||||||||||||||
| 357 | my $err_code; | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ( defined $str_len ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ( length( $handle->{rbuf} ) < $str_len + EOL_LENGTH ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $reply = substr( $handle->{rbuf}, 0, $str_len, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | substr( $handle->{rbuf}, 0, EOL_LENGTH, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if ( $self->{utf8} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | utf8::decode($reply); | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | undef $str_len; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my $eol_pos = index( $handle->{rbuf}, EOL ); | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ( $eol_pos < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $reply = substr( $handle->{rbuf}, 0, $eol_pos, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $type = substr( $reply, 0, 1, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | substr( $handle->{rbuf}, 0, EOL_LENGTH, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ( $type ne '+' && $type ne ':' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type ne "+" and $type ne ":"
MC/DC0%0/2
$type ne "+" and $type ne ":"
$type ne "+"
$type ne ":"
Truth table0%0/3
A and B
A= $type ne "+"B= $type ne ":"
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ( $type eq '$' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ( $reply >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $str_len = $reply; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | undef $reply; | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | elsif ( $type eq '*' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ( $reply > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | push( @bufs, | |||||||||||||||||||||||||||||||||||||||||
| 395 | { reply => [], | ||||||||||||||||||||||||||||||||||||||||||
| 396 | err_code => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 397 | chunks_cnt => $reply, | ||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $bufs_num++; | |||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | elsif ( $reply == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $reply = []; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | undef $reply; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | elsif ( $type eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $err_code = E_OPRN_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ( $reply =~ m/^([A-Z]{3,}) / ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if ( exists $ERR_PREFS_MAP{$1} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $err_code = $ERR_PREFS_MAP{$1}; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $err = _new_error( 'Unexpected reply received.', | |||||||||||||||||||||||||||||||||||||||||
| 421 | E_UNEXPECTED_DATA ); | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | while ( $bufs_num > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | my $curr_buf = $bufs[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if ( defined $err_code ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | unless ( ref($reply) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $reply = _new_error( $reply, $err_code ); | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $curr_buf->{err_code} = E_OPRN_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | push( @{ $curr_buf->{reply} }, $reply ); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if ( --$curr_buf->{chunks_cnt} > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | next MAIN; | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $reply = $curr_buf->{reply}; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $err_code = $curr_buf->{err_code}; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | pop @bufs; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $bufs_num--; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $self->_process_reply( $reply, $err_code ); | |||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 9 | ▶ | sub _prepare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare: called CC=6 SCAR=20.7
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 9 | my $cmd_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 9 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 9 | my $cbs; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 9 | ▶ | if ( ref( $args->[-1] ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $cbs = pop @{$args}; | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 9 | $cbs = {}; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 9 | ▶ | if ( ref( $args->[-1] ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | if ( exists $SUB_CMDS{$cmd_name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $cbs->{on_message} = pop @{$args}; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $cbs->{on_reply} = pop @{$args}; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | my @kwds | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 9 | ▶ | = $cmd_name eq 'eval_cached' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | ? ('evalsha') | ||||||||||||||||||||||||||||||||||||||||||
| 479 | : split( m/_/, lc($cmd_name) ); | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | my $cmd = { | ||||||||||||||||||||||||||||||||||||||||||
| 482 | name => $cmd_name, | ||||||||||||||||||||||||||||||||||||||||||
| 483 | kwds => \@kwds, | ||||||||||||||||||||||||||||||||||||||||||
| 484 | args => $args, | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 9 | %{$cbs}, | |||||||||||||||||||||||||||||||||||||||||
| 486 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 9 | ▶ | unless ( defined $cmd->{on_reply} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 9 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | ▶ | $cmd->{on_reply} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | my $err = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | ▶ | if ( defined $err ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 1 | $self->{on_error}->($err); | |||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 9 | return $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 9 | ▶ | sub _execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute: called CC=24 SCAR=52.6
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 9 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 9 | ▶ | if ( $self->{_multi_mode} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"_multi_mode"} and exists $SUBUNSUB_CMDS{$cmd->{"name"}} || exists $NEED_POSTPROCESS{$cmd->{"name"}}
exists $SUBUNSUB_CMDS{$cmd->{"name"}} or exists $NEED_POSTPROCESS{$cmd->{"name"}}
MC/DC33%1/3
$self->{"_multi_mode"} and exists $SUBUNSUB_CMDS{$cmd->{"name"}} || exists $NEED_POSTPROCESS{$cmd->{"name"}}
$self->{"_multi_mode"}
exists $SUBUNSUB_CMDS{$cmd->{"name"}}
exists $NEED_POSTPROCESS{$cmd->{"name"}}
Truth table75%3/4
A and B or C
A= $self->{"_multi_mode"}B= exists $SUBUNSUB_CMDS{$cmd->{"name"}}C= exists $NEED_POSTPROCESS{$cmd->{"name"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | && ( exists $SUBUNSUB_CMDS{ $cmd->{name} } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | || exists $NEED_POSTPROCESS{ $cmd->{name} } ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 511 | { | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 7 | croak qq{Command "$cmd->{name}" not allowed after "multi" command.} | |||||||||||||||||||||||||||||||||||||||||
| 513 | . ' First, the transaction must be finalized.'; | ||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 2 | ▶ | if ( exists $NEED_PREPROCESS{ $cmd->{name} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 2 | ▶ | if ( $cmd->{name} eq 'multi' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | $self->{_multi_mode} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | ▶ | elsif ( $cmd->{name} eq 'exec' | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$cmd->{"name"} eq "exec" or $cmd->{"name"} eq "discard"
MC/DC0%0/2
$cmd->{"name"} eq "exec" or $cmd->{"name"} eq "discard"
$cmd->{"name"} eq "exec"
$cmd->{"name"} eq "discard"
Truth table33%1/3
A or B
A= $cmd->{"name"} eq "exec"B= $cmd->{"name"} eq "discard"
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | || $cmd->{name} eq 'discard' ) | ||||||||||||||||||||||||||||||||||||||||||
| 522 | { | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | $self->{_multi_mode} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | elsif ( $cmd->{name} eq 'eval_cached' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my $script = $cmd->{args}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | unless ( exists $EVAL_CACHE{$script} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | $EVAL_CACHE{$script} = sha1_hex($script); | |||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $cmd->{args}[0] = $EVAL_CACHE{$script}; | |||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $cmd->{script} = $script; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | else { # subscribe, unsubscribe, psubscribe, punsubscribe | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | ▶ | if ( exists $SUB_CMDS{ $cmd->{name} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $SUB_CMDS{$cmd->{"name"}} and not defined $cmd->{"on_message"}
MC/DC0%0/2
exists $SUB_CMDS{$cmd->{"name"}} and not defined $cmd->{"on_message"}
exists $SUB_CMDS{$cmd->{"name"}}
not defined $cmd->{"on_message"}
Truth table33%1/3
A and not(B)
A= exists $SUB_CMDS{$cmd->{"name"}}B= not defined $cmd->{"on_message"}
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | && !defined $cmd->{on_message} ) | ||||||||||||||||||||||||||||||||||||||||||
| 536 | { | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | croak '"on_message" callback must be specified'; | |||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | if ( @{ $cmd->{args} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $cmd->{reply_cnt} = scalar @{ $cmd->{args} }; | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 1 | ▶ | unless ( $self->{_ready} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | ▶ | if ( defined $self->{_handle} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 1 | ▶ | if ( $self->{_connected} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | if ( $self->{_auth_state} == S_DONE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | if ( $self->{_db_selection_state} == S_NEED_DO ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $self->_select_database; | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 554 | elsif ( $self->{_auth_state} == S_NEED_DO ) { | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $self->_auth; | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | elsif ( $self->{lazy} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | undef $self->{lazy}; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | elsif ( $self->{reconnect} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if ( defined $self->{reconnect_interval} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"reconnect_interval"} and $self->{"reconnect_interval"} > 0
MC/DC0%0/2
defined $self->{"reconnect_interval"} and $self->{"reconnect_interval"} > 0
defined $self->{"reconnect_interval"}
$self->{"reconnect_interval"} > 0
Truth table0%0/3
A and B
A= defined $self->{"reconnect_interval"}B= $self->{"reconnect_interval"} > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | && $self->{reconnect_interval} > 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 566 | { | ||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | unless ( defined $self->{_reconnect_timer} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | $self->{_reconnect_timer} = AE::timer( | ||||||||||||||||||||||||||||||||||||||||||
| 571 | $self->{reconnect_interval}, 0, | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | undef $self->{_reconnect_timer}; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | AE::postpone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my $err = _new_error( qq{Operation "$cmd->{name}" aborted:} | |||||||||||||||||||||||||||||||||||||||||
| 586 | . ' No connection to the server.', E_NO_CONN ); | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | $cmd->{on_reply}->( undef, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | push( @{ $self->{_input_queue} }, $cmd ); | |||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | $self->_push_write($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | sub _push_write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_push_write: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my $cmd_str = ''; | |||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | my @tokens = ( @{ $cmd->{kwds} }, @{ $cmd->{args} } ); | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | foreach my $token (@tokens) { | |||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | unless ( defined $token ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | $token = ''; | |||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | elsif ( $self->{utf8} ) { | |||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | utf8::encode($token); | |||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $cmd_str .= '$' . length($token) . EOL . $token . EOL; | |||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | $cmd_str = '*' . scalar(@tokens) . EOL . $cmd_str; | |||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | my $handle = $self->{_handle}; | |||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | if ( defined $self->{read_timeout} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"read_timeout"} and not @{$self->{"_processing_queue"};}
MC/DC0%0/2
defined $self->{"read_timeout"} and not @{$self->{"_processing_queue"};}
defined $self->{"read_timeout"}
not @{$self->{"_processing_queue"};}
Truth table0%0/3
A and not(B)
A= defined $self->{"read_timeout"}B= not @{$self->{"_processing_queue"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | && !@{ $self->{_processing_queue} } ) | |||||||||||||||||||||||||||||||||||||||||
| 624 | { | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $handle->rtimeout_reset; | |||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $handle->rtimeout( $self->{read_timeout} ); | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | push( @{ $self->{_processing_queue} }, $cmd ); | |||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | $handle->push_write($cmd_str); | |||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | sub _auth { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_auth: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | $self->{_auth_state} = S_IN_PROGRESS; | |||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | $self->_push_write( | ||||||||||||||||||||||||||||||||||||||||||
| 642 | { name => 'auth', | ||||||||||||||||||||||||||||||||||||||||||
| 643 | kwds => ['auth'], | ||||||||||||||||||||||||||||||||||||||||||
| 644 | args => [ $self->{password} ], | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | on_reply => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | my $err = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | if ( defined $err | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $err and $err->message ne "ERR Client sent AUTH, but no password is set"
MC/DC0%0/2
defined $err and $err->message ne "ERR Client sent AUTH, but no password is set"
defined $err
$err->message ne "ERR Client sent AUTH, but no password is set"
Truth table0%0/3
A and B
A= defined $errB= $err->message ne "ERR Client sent AUTH, but no password is set"
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | && $err->message ne 'ERR Client sent AUTH, but no password is set' ) | ||||||||||||||||||||||||||||||||||||||||||
| 651 | { | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | $self->{_auth_state} = S_NEED_DO; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | $self->_abort($err); | |||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | $self->{_auth_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | if ( $self->{_db_selection_state} == S_NEED_DO ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | $self->_select_database; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | $self->{_ready} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $self->_process_input_queue; | |||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | sub _select_database { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_select_database: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $self->{_db_selection_state} = S_IN_PROGRESS; | |||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | $self->_push_write( | ||||||||||||||||||||||||||||||||||||||||||
| 681 | { name => 'select', | ||||||||||||||||||||||||||||||||||||||||||
| 682 | kwds => ['select'], | ||||||||||||||||||||||||||||||||||||||||||
| 683 | args => [ $self->{database} ], | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | on_reply => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my $err = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if ( defined $err ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | $self->{_db_selection_state} = S_NEED_DO; | |||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | $self->_abort($err); | |||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | $self->{_db_selection_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | $self->{_ready} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | $self->_process_input_queue; | |||||||||||||||||||||||||||||||||||||||||
| 699 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | sub _process_input_queue { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_input_queue: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $self->{_temp_queue} = $self->{_input_queue}; | |||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | $self->{_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | while ( my $cmd = shift @{ $self->{_temp_queue} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | $self->_push_write($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | sub _process_reply { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_reply: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $reply = shift; | |||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | my $err_code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | if ( defined $err_code ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | $self->_process_error( $reply, $err_code ); | |||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | ▶ | elsif ( $self->{_channel_cnt} + $self->{_pchannel_cnt} > 0 | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->{"_channel_cnt"} + $self->{"_pchannel_cnt"} > 0 and ref $reply and exists $MESSAGE_TYPES{$reply->[0]}
$self->{"_channel_cnt"} + $self->{"_pchannel_cnt"} > 0 and ref $reply
MC/DC0%0/3
$self->{"_channel_cnt"} + $self->{"_pchannel_cnt"} > 0 and ref $reply and exists $MESSAGE_TYPES{$reply->[0]}
$self->{"_channel_cnt"} + $self->{"_pchannel_cnt"} > 0
ref $reply
exists $MESSAGE_TYPES{$reply->[0]}
Truth table0%0/4
A and B and C
A= $self->{"_channel_cnt"} + $self->{"_pchannel_cnt"} > 0B= ref $replyC= exists $MESSAGE_TYPES{$reply->[0]}
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | && ref($reply) && exists $MESSAGE_TYPES{ $reply->[0] } ) | ||||||||||||||||||||||||||||||||||||||||||
| 729 | { | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | $self->_process_message($reply); | |||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||
| 732 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | $self->_process_success($reply); | |||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | ▶ | sub _process_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_error: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | my $reply = shift; | |||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | my $err_code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | my $cmd = shift @{ $self->{_processing_queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | unless ( defined $cmd ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 748 | q{Don't know how process error message. Processing queue is empty.}, | ||||||||||||||||||||||||||||||||||||||||||
| 749 | E_UNEXPECTED_DATA | ||||||||||||||||||||||||||||||||||||||||||
| 750 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | if ( $err_code == E_NO_AUTH ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | my $err = _new_error( $reply, $err_code ); | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | ▶ | if ( $cmd->{name} eq 'eval_cached' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cmd->{"name"} eq "eval_cached" and $err_code == 11
MC/DC0%0/2
$cmd->{"name"} eq "eval_cached" and $err_code == 11
$cmd->{"name"} eq "eval_cached"
$err_code == 11
Truth table0%0/3
A and B
A= $cmd->{"name"} eq "eval_cached"B= $err_code == 11
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | && $err_code == E_NO_SCRIPT ) | ||||||||||||||||||||||||||||||||||||||||||
| 765 | { | ||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | $cmd->{kwds}[0] = 'eval'; | |||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | $cmd->{args}[0] = $cmd->{script}; | |||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | $self->_push_write($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | if ( ref($reply) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 776 | qq{Operation "$cmd->{name}" completed with errors.}, $err_code ); | ||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | $cmd->{on_reply}->( $reply, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||
| 779 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | my $err = _new_error( $reply, $err_code ); | |||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | $cmd->{on_reply}->( undef, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | sub _process_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_message: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | my $cmd = $self->{_channels}{ $msg->[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | ▶ | unless ( defined $cmd ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 795 | q{Don't know how process published message.} | ||||||||||||||||||||||||||||||||||||||||||
| 796 | . qq{ Unknown channel or pattern "$msg->[1]".}, | ||||||||||||||||||||||||||||||||||||||||||
| 797 | E_UNEXPECTED_DATA | ||||||||||||||||||||||||||||||||||||||||||
| 798 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | $cmd->{on_message}->( | ||||||||||||||||||||||||||||||||||||||||||
| 805 | $msg->[0] eq 'pmessage' | ||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | ? @{$msg}[ 3, 1, 2 ] | |||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | : @{$msg}[ 2, 1 ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | sub _process_success { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_success: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | my $reply = shift; | |||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | my $cmd = $self->{_processing_queue}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | unless ( defined $cmd ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 821 | q{Don't know how process reply. Processing queue is empty.}, | ||||||||||||||||||||||||||||||||||||||||||
| 822 | E_UNEXPECTED_DATA | ||||||||||||||||||||||||||||||||||||||||||
| 823 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | ▶ | if ( exists $SUBUNSUB_CMDS{ $cmd->{name} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | if ( $cmd->{name} eq 'subscribe' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | $self->{_channels}{ $reply->[1] } = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | $self->{_channel_cnt}++; | |||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 834 | elsif ( $cmd->{name} eq 'psubscribe' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | $self->{_channels}{ $reply->[1] } = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | $self->{_pchannel_cnt}++; | |||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | elsif ( $cmd->{name} eq 'unsubscribe' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | ▶ | unless ( defined $cmd->{reply_cnt} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | $cmd->{reply_cnt} = $self->{_channel_cnt}; | |||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | delete $self->{_channels}{ $reply->[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | $self->{_channel_cnt}--; | |||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||
| 846 | else { # punsubscribe | ||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | ▶ | unless ( defined $cmd->{reply_cnt} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | $cmd->{reply_cnt} = $self->{_pchannel_cnt}; | |||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | delete $self->{_channels}{ $reply->[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | $self->{_pchannel_cnt}--; | |||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | $reply = $reply->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | ▶ | if ( !defined $cmd->{reply_cnt} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $cmd->{"reply_cnt"} or --$cmd->{"reply_cnt"} == 0
MC/DC0%0/2
not defined $cmd->{"reply_cnt"} or --$cmd->{"reply_cnt"} == 0
not defined $cmd->{"reply_cnt"}
--$cmd->{"reply_cnt"} == 0
Truth table0%0/3
not(A) or B
A= not defined $cmd->{"reply_cnt"}B= --$cmd->{"reply_cnt"} == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | || --$cmd->{reply_cnt} == 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 860 | { | ||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | shift @{ $self->{_processing_queue} }; | |||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | ▶ | if ( exists $NEED_POSTPROCESS{ $cmd->{name} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | ▶ | if ( $cmd->{name} eq 'info' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$cmd->{"name"} eq "info" or $cmd->{"name"} eq "cluster_info"
MC/DC0%0/2
$cmd->{"name"} eq "info" or $cmd->{"name"} eq "cluster_info"
$cmd->{"name"} eq "info"
$cmd->{"name"} eq "cluster_info"
Truth table0%0/3
A or B
A= $cmd->{"name"} eq "info"B= $cmd->{"name"} eq "cluster_info"
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | || $cmd->{name} eq 'cluster_info' ) | ||||||||||||||||||||||||||||||||||||||||||
| 866 | { | ||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | $reply = _parse_info($reply); | |||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||
| 869 | elsif ( $cmd->{name} eq 'select' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | $self->{database} = $cmd->{args}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||
| 872 | else { # quit | ||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | $self->_disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | $cmd->{on_reply}->($reply); | |||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | ▶ | sub _parse_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 884 | 0 | return { map { split( m/:/, $_, 2 ) } | |||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | grep { m/^[^#]/ } split( EOL, $_[0] ) }; | |||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | 1 | ▶ | sub _disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_disconnect: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 890 | 1 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||
| 892 | 1 | my $was_connected = $self->{_connected}; | |||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | 1 | ▶ | if ( defined $self->{_handle} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 895 | 1 | $self->{_handle}->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||
| 897 | 1 | $self->_reset_internals; | |||||||||||||||||||||||||||||||||||||||||
| 898 | 1 | $self->_abort($err); | |||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | 1 | ▶ | if ( $was_connected && defined $self->{on_disconnect} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$was_connected and defined $self->{"on_disconnect"}
MC/DC0%0/2
$was_connected and defined $self->{"on_disconnect"}
$was_connected
defined $self->{"on_disconnect"}
Truth table33%1/3
A and B
A= $was_connectedB= defined $self->{"on_disconnect"}
| |||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | $self->{on_disconnect}->(); | |||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | 8 | ▶ | sub _reset_internals { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_internals: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 908 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||
| 910 | 8 | $self->{_handle} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 911 | 8 | $self->{_connected} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 912 | 8 | $self->{_auth_state} = S_NEED_DO; | |||||||||||||||||||||||||||||||||||||||||
| 913 | 8 | $self->{_db_selection_state} = S_NEED_DO; | |||||||||||||||||||||||||||||||||||||||||
| 914 | 8 | $self->{_ready} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 915 | 8 | $self->{_multi_mode} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 916 | 8 | $self->{_reconnect_timer} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||
| 918 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||
| 921 | 1 | ▶ | sub _abort { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_abort: called CC=8 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||
| 922 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 923 | 1 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | 1 | my @queued_commands = $self->_queued_commands; | |||||||||||||||||||||||||||||||||||||||||
| 926 | 1 | my %channels = %{ $self->{_channels} }; | |||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | 1 | $self->{_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 929 | 1 | $self->{_temp_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 930 | 1 | $self->{_processing_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 931 | 1 | $self->{_channels} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 932 | 1 | $self->{_channel_cnt} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 933 | 1 | $self->{_pchannel_cnt} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | 1 | ▶ | if ( !defined $err && @queued_commands ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $err and @queued_commands
MC/DC0%0/2
not defined $err and @queued_commands
not defined $err
@queued_commands
Truth table33%1/3
not(A) and B
A= not defined $errB= @queued_commands
| |||||||||||||||||||||||||||||||||||||||||||
| 936 | 1 | $err = _new_error( 'Connection closed by client prematurely.', | |||||||||||||||||||||||||||||||||||||||||
| 937 | E_CONN_CLOSED_BY_CLIENT ); | ||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 1 | ▶ | if ( defined $err ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 941 | 1 | my $err_msg = $err->message; | |||||||||||||||||||||||||||||||||||||||||
| 942 | 1 | my $err_code = $err->code; | |||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | 1 | $self->{on_error}->($err); | |||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||
| 946 | 1 | ▶ | if ( %channels && $err_code != E_CONN_CLOSED_BY_CLIENT ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
%channels and $err_code != 5
MC/DC0%0/2
%channels and $err_code != 5
%channels
$err_code != 5
Truth table33%1/3
A and B
A= %channelsB= $err_code != 5
| |||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | foreach my $name ( keys %channels ) { | |||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 949 | qq{Subscription to channel "$name" lost: $err_msg}, | ||||||||||||||||||||||||||||||||||||||||||
| 950 | $err_code | ||||||||||||||||||||||||||||||||||||||||||
| 951 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | my $cmd = $channels{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | $cmd->{on_reply}->( undef, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||
| 958 | 1 | foreach my $cmd (@queued_commands) { | |||||||||||||||||||||||||||||||||||||||||
| 959 | 1 | my $err = _new_error( qq{Operation "$cmd->{name}" aborted: $err_msg}, | |||||||||||||||||||||||||||||||||||||||||
| 960 | $err_code ); | ||||||||||||||||||||||||||||||||||||||||||
| 961 | 1 | $cmd->{on_reply}->( undef, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||||
| 963 | } | ||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||
| 968 | 8 | ▶ | sub _queued_commands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_queued_commands: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 969 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 972 | 8 | @{ $self->{_processing_queue} }, | |||||||||||||||||||||||||||||||||||||||||
| 973 | 8 | @{ $self->{_temp_queue} }, | |||||||||||||||||||||||||||||||||||||||||
| 974 | 8 | @{ $self->{_input_queue} }, | |||||||||||||||||||||||||||||||||||||||||
| 975 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 976 | } | ||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||
| 978 | 2 | ▶ | sub _new_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 979 | 2 | return AnyEvent::RipeRedis::Error->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 980 | } | ||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||
| 982 | 8 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 983 | 8 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 984 | 8 | my $cmd_name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 985 | 8 | $cmd_name =~ s/^.+:://; | |||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||
| 987 | 9 | ▶ | my $sub = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 988 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||
| 990 | 9 | my $cmd = $self->_prepare( $cmd_name, [@_] ); | |||||||||||||||||||||||||||||||||||||||||
| 991 | 9 | $self->_execute($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||
| 993 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 994 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||
| 996 | 8 | do { | |||||||||||||||||||||||||||||||||||||||||
| 997 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 998 | 8 | *{$cmd_name} = $sub; | |||||||||||||||||||||||||||||||||||||||||
| 999 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||
| 1001 | 8 | goto &{$sub}; | |||||||||||||||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | 13 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1005 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||
| 1007 | 13 | ▶ | if ( defined $self->{_handle} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1008 | 6 | $self->{_handle}->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||
| 1011 | 13 | ▶ | if ( defined $self->{_processing_queue} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1012 | 7 | my @queued_commands = $self->_queued_commands; | |||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||
| 1014 | 7 | foreach my $cmd (@queued_commands) { | |||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | warn qq{Operation "$cmd->{name}" aborted:} | |||||||||||||||||||||||||||||||||||||||||
| 1016 | . " Client object destroyed prematurely.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||
| 1020 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||
| 1023 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1024 | __END__ | ||||||||||||||||||||||||||||||||||||||||||