| 1 | package AnyEvent::Stomper; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.008000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | our $VERSION = '0.36'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use AnyEvent::Stomper::Frame; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use AnyEvent::Stomper::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Scalar::Util qw( looks_like_number weaken ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use List::Util qw( max ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use List::MoreUtils qw( bsearch_index ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | my %ERROR_CODES; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | %ERROR_CODES = %AnyEvent::Stomper::Error::ERROR_CODES; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | our @EXPORT_OK = keys %ERROR_CODES; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | our %EXPORT_TAGS = ( err_codes => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | # Default values | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | D_HOST => 'localhost', | |||||||||||||||||||||||||||||||||||||||||
| 31 | D_PORT => 61613, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | D_HEARTBEAT => [ 0, 0 ], | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | %ERROR_CODES, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Operation status | ||||||||||||||||||||||||||||||||||||||||||
| 37 | S_NEED_DO => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | S_IN_PROGRESS => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | S_DONE => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | EOL => "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 42 | RE_EOL => qr/\r?\n/, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | my %SUBUNSUB_CMDS = ( | |||||||||||||||||||||||||||||||||||||||||
| 46 | SUBSCRIBE => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | UNSUBSCRIBE => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | my %ACK_CMDS = ( | |||||||||||||||||||||||||||||||||||||||||
| 51 | ACK => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | NACK => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | my %NEED_RECEIPT = ( | |||||||||||||||||||||||||||||||||||||||||
| 56 | CONNECT => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | DISCONNECT => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | %SUBUNSUB_CMDS, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | my %ESCAPE_MAP = ( | |||||||||||||||||||||||||||||||||||||||||
| 62 | "\r" => "\\r", | ||||||||||||||||||||||||||||||||||||||||||
| 63 | "\n" => "\\n", | ||||||||||||||||||||||||||||||||||||||||||
| 64 | ':' => "\\c", | ||||||||||||||||||||||||||||||||||||||||||
| 65 | "\\" => "\\\\", | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | my %UNESCAPE_MAP = reverse %ESCAPE_MAP; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | my $RECEIPT_SEQ = 1; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | my $MESSAGE_SEQ = 1; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 15 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 15 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 15 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 15 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 15 | ▶ | $self->{host} = $params{host} || D_HOST; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'host'} || 'localhost'
MC/DC100%1/1
$params{'host'} || 'localhost'
$params{'host'}
Truth table100%2/2
A
A= $params{'host'}
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 15 | ▶ | $self->{port} = $params{port} || D_PORT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'port'} || 61613
MC/DC100%1/1
$params{'port'} || 61613
$params{'port'}
Truth table100%2/2
A
A= $params{'port'}
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | $self->{login} = $params{login}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | $self->{passcode} = $params{passcode}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 15 | $self->{vhost} = $params{vhost}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | $self->{lazy} = $params{lazy}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | ▶ | $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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | ▶ | $self->{default_headers} = $params{default_headers} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{'default_headers'} || {}
MC/DC0%0/1
$params{'default_headers'} || {}
$params{'default_headers'}
Truth table50%1/2
A
A= $params{'default_headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 15 | $self->{on_connect} = $params{on_connect}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 15 | $self->{on_disconnect} = $params{on_disconnect}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 15 | ▶ | if ( defined $params{heartbeat} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | unless ( ref( $params{heartbeat} ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | croak q{"heartbeat" must be specified as array reference}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | foreach my $val ( @{ $params{heartbeat} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | if ( $val =~ /\D/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | croak q{"heartbeat" values must be an integer numbers}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->{heartbeat} = $params{heartbeat}; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 13 | $self->{heartbeat} = D_HEARTBEAT; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 13 | ▶ | if ( defined $params{command_headers} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | unless ( ref( $params{command_headers} ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | croak q{"command_headers" must be specified as hash reference}; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my %command_headers; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | while ( my ( $cmd_name, $headers ) = each %{ $params{command_headers} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $command_headers{ uc($cmd_name) } = $headers; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->{command_headers} = \%command_headers; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 13 | $self->connection_timeout( $params{connection_timeout} ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | $self->reconnect_interval( $params{reconnect_interval} ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 9 | $self->on_error( $params{on_error} ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | $self->_reset_internals; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | $self->{_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | $self->{_temp_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | $self->{_write_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 9 | $self->{_temp_write_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | $self->{_pending_receipts} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | $self->{_subs} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | ▶ | unless ( $self->{lazy} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $cmd_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $cmd = $self->_prepare( $cmd_name, [@_] ); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->_execute($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # Generate methods | ||||||||||||||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | ▶ | no strict qw( refs ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 5 | foreach my $name ( qw( send subscribe unsubscribe ack nack begin commit | |||||||||||||||||||||||||||||||||||||||||
| 153 | abort disconnect ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 45 | ▶ | *{$name} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | my $cmd = $self->_prepare( $name, [@_] ); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | $self->_execute($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 45 | } | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 14 | ▶ | sub on_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_error: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 14 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 11 | my $on_error = shift; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 11 | ▶ | if ( defined $on_error ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 5 | $self->{on_error} = $on_error; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | $self->{on_error} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | warn $err->message . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 14 | return $self->{on_error}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # Generate accessors | ||||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | ▶ | no strict qw( refs ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | foreach my $name ( qw( host port ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 191 | 10 | ▶ | *{$name} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 10 | } | |||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 5 | foreach my $name ( qw( connection_timeout reconnect_interval ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | ▶ | *{$name} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 38 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 38 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 32 | my $seconds = shift; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 32 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | && ( !looks_like_number($seconds) || $seconds < 0 ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 8 | croak qq{"$name" must be a positive number}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 24 | $self->{$name} = $seconds; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 30 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 5 | foreach my $name ( qw( on_connect on_disconnect ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 217 | 10 | ▶ | *{$name} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 10 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | $self->{$name} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 10 | return $self->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub force_disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
force_disconnect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $self->_disconnect(); | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | ▶ | sub _connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | $self->{_handle} = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 5 | %{ $self->{handle_params} }, | |||||||||||||||||||||||||||||||||||||||||
| 242 | 5 | connect => [ $self->{host}, $self->{port} ], | |||||||||||||||||||||||||||||||||||||||||
| 243 | on_prepare => $self->_create_on_prepare, | ||||||||||||||||||||||||||||||||||||||||||
| 244 | on_connect => $self->_create_on_connect, | ||||||||||||||||||||||||||||||||||||||||||
| 245 | on_connect_error => $self->_create_on_connect_error, | ||||||||||||||||||||||||||||||||||||||||||
| 246 | on_wtimeout => $self->_create_on_wtimeout, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | on_rtimeout => $self->_create_on_rtimeout, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | on_eof => $self->_create_on_eof, | ||||||||||||||||||||||||||||||||||||||||||
| 249 | on_error => $self->_create_on_handle_error, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | on_drain => $self->_create_on_drain, | ||||||||||||||||||||||||||||||||||||||||||
| 251 | on_read => $self->_create_on_read, | ||||||||||||||||||||||||||||||||||||||||||
| 252 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | ▶ | sub _create_on_prepare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_prepare: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | ▶ | if ( defined $self->{connection_timeout} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | return $self->{connection_timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | ▶ | sub _create_on_connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_connect: called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $self->{_connected} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $self->_login; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if ( defined $self->{on_connect} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $self->{on_connect}->(); | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | ▶ | sub _create_on_connect_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_connect_error: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $err_msg = pop; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 295 | "Can't connect to $self->{host}:$self->{port}: $err_msg", | ||||||||||||||||||||||||||||||||||||||||||
| 296 | E_CANT_CONN | ||||||||||||||||||||||||||||||||||||||||||
| 297 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | ▶ | sub _create_on_wtimeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_wtimeout: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->{_handle}->push_write(EOL); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 5 | ▶ | sub _create_on_rtimeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_rtimeout: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $err = _new_error( 'Read timed out.', E_READ_TIMEDOUT ); | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 320 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 5 | ▶ | sub _create_on_eof { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_eof: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $err = _new_error( 'Connection closed by remote host.', | |||||||||||||||||||||||||||||||||||||||||
| 330 | E_CONN_CLOSED_BY_REMOTE_HOST ); | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 332 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 5 | ▶ | sub _create_on_handle_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_handle_error: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my $err_msg = pop; | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $err = _new_error( $err_msg, E_IO ); | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 5 | ▶ | sub _create_on_drain { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_drain: called CC=1 SCAR=4.0
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return unless @{ $self->{_write_queue} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $self->{_temp_write_queue} = $self->{_write_queue}; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $self->{_write_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | while ( my $cmd = shift @{ $self->{_temp_write_queue} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $cmd->{on_receipt}->(); | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 5 | ▶ | sub _create_on_read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_on_read: called CC=1 SCAR=5.6
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 5 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 5 | my $cmd_name; | |||||||||||||||||||||||||||||||||||||||||
| 371 | my $headers; | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $handle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $frame; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | return if $handle->destroyed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ( defined $cmd_name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $content_length; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ( defined $headers->{'content-length'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $content_length = $headers->{'content-length'}; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | return if length( $handle->{rbuf} ) < $content_length + 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $content_length = index( $handle->{rbuf}, "\0" ); | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | return if $content_length < 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $body = substr( $handle->{rbuf}, 0, $content_length, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $handle->{rbuf} =~ s/^\0(?:${\(RE_EOL)})*//; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $frame = _new_frame( $cmd_name, $headers, $body ); | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | undef $cmd_name; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | undef $headers; | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $handle->{rbuf} =~ s/^(?:${\(RE_EOL)})+//; | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | return unless $handle->{rbuf} =~ s/^(.+?)(?:${\(RE_EOL)}){2}//s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ( $cmd_name, my @header_strings ) = split( m/${\(RE_EOL)}/, $1 ); | |||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | foreach my $header_str (@header_strings) { | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my ( $name, $value ) = split( /:/, $header_str, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $headers->{ _unescape($name) } = _unescape($value); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $self->_process_frame($frame); | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | ▶ | sub _prepare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare: called CC=9 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | my $cmd_name = uc(shift); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 2 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | ▶ | if ( ref( $args->[-1] ) eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args->[-1] eq "CODE" and scalar @{$args;} % 2 > 0
MC/DC0%0/2
ref $args->[-1] eq "CODE" and scalar @{$args;} % 2 > 0
ref $args->[-1] eq "CODE"
scalar @{$args;} % 2 > 0
Truth table33%1/3
A and B
A= ref $args->[-1] eq "CODE"B= scalar @{$args;} % 2 > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | && scalar @{$args} % 2 > 0 ) | |||||||||||||||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | if ( $cmd_name eq 'SUBSCRIBE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $params{on_message} = pop @{$args}; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $params{on_receipt} = pop @{$args}; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 2 | my %headers = @{$args}; | |||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | foreach my $name ( qw( body on_receipt on_message ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 440 | 6 | ▶ | if ( defined $headers{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $params{$name} = delete $headers{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 2 | ▶ | if ( exists $ACK_CMDS{$cmd_name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | $params{message} = delete $headers{message}; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | %headers = ( | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 2 | ▶ | %{ $self->{default_headers} }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | defined $self->{command_headers}{$cmd_name} | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ? %{ $self->{command_headers}{$cmd_name} } | |||||||||||||||||||||||||||||||||||||||||
| 453 | : (), | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | %headers, | ||||||||||||||||||||||||||||||||||||||||||
| 456 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 2 | my $cmd = { | |||||||||||||||||||||||||||||||||||||||||
| 459 | name => $cmd_name, | ||||||||||||||||||||||||||||||||||||||||||
| 460 | headers => \%headers, | ||||||||||||||||||||||||||||||||||||||||||
| 461 | %params, | ||||||||||||||||||||||||||||||||||||||||||
| 462 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | ▶ | unless ( defined $cmd->{on_receipt} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 2 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | $cmd->{on_receipt} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my $receipt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ( defined $err ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | $self->{on_error}->($err); | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 2 | return $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 2 | ▶ | sub _execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute: called CC=13 SCAR=45.5
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 2 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 2 | ▶ | if ( $cmd->{name} eq 'SUBSCRIBE' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$cmd->{"name"} eq "SUBSCRIBE" and not defined $cmd->{"on_message"}
MC/DC50%1/2
$cmd->{"name"} eq "SUBSCRIBE" and not defined $cmd->{"on_message"}
$cmd->{"name"} eq "SUBSCRIBE"
not defined $cmd->{"on_message"}
Truth table66%2/3
A and not(B)
A= $cmd->{"name"} eq "SUBSCRIBE"B= not defined $cmd->{"on_message"}
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | && !defined $cmd->{on_message} ) | ||||||||||||||||||||||||||||||||||||||||||
| 487 | { | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | croak '"on_message" callback must be specified'; | |||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | ▶ | elsif ( exists $ACK_CMDS{ $cmd->{name} } | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
exists $ACK_CMDS{$cmd->{"name"}} and not defined $cmd->{"message"}
MC/DC0%0/2
exists $ACK_CMDS{$cmd->{"name"}} and not defined $cmd->{"message"}
exists $ACK_CMDS{$cmd->{"name"}}
not defined $cmd->{"message"}
Truth table33%1/3
A and not(B)
A= exists $ACK_CMDS{$cmd->{"name"}}B= not defined $cmd->{"message"}
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | && !defined $cmd->{message} ) | ||||||||||||||||||||||||||||||||||||||||||
| 492 | { | ||||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | croak '"message" parameter must be specified'; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | unless ( $self->{_ready} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if ( defined $self->{_handle} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if ( $self->{_connected} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | if ( $self->{_login_state} == S_NEED_DO ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $self->_login; | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | elsif ( $self->{lazy} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | undef $self->{lazy}; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | && $self->{reconnect_interval} > 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 511 | { | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | unless ( defined $self->{_reconnect_timer} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | $self->{_reconnect_timer} = AE::timer( | ||||||||||||||||||||||||||||||||||||||||||
| 516 | $self->{reconnect_interval}, 0, | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | undef $self->{_reconnect_timer}; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $self->_connect; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | push( @{ $self->{_input_queue} }, $cmd ); | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | $self->_push_write($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | sub _push_write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_push_write: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my $cmd_headers = $cmd->{headers}; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if ( exists $ACK_CMDS{ $cmd->{name} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | unless ( $self->_check_ack( $cmd->{message} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my $err = _new_error( "Unexpected $cmd->{name} sent.", E_OPRN_ERROR ); | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | AE::postpone { $cmd->{on_receipt}->( undef, $err ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $msg_headers = $cmd->{message}->headers; | |||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | if ( $self->{_version} <= 1.1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $cmd_headers->{'message-id'} = $msg_headers->{'message-id'}; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | if ( $self->{_version} > 1.0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $cmd_headers->{subscription} = $msg_headers->{subscription}; | |||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $cmd_headers->{id} = $msg_headers->{ack}; | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | if ( exists $NEED_RECEIPT{ $cmd->{name} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $NEED_RECEIPT{$cmd->{"name"}} or defined $cmd_headers->{"receipt"}
MC/DC0%0/2
exists $NEED_RECEIPT{$cmd->{"name"}} or defined $cmd_headers->{"receipt"}
exists $NEED_RECEIPT{$cmd->{"name"}}
defined $cmd_headers->{"receipt"}
Truth table0%0/3
A or B
A= exists $NEED_RECEIPT{$cmd->{"name"}}B= defined $cmd_headers->{"receipt"}
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | || defined $cmd_headers->{receipt} ) | ||||||||||||||||||||||||||||||||||||||||||
| 568 | { | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | if ( $cmd->{name} eq 'CONNECT' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $self->{_pending_receipts}{CONNECTED} = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | if ( !defined $cmd_headers->{receipt} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $cmd_headers->{"receipt"} or $cmd_headers->{"receipt"} eq "auto"
MC/DC0%0/2
not defined $cmd_headers->{"receipt"} or $cmd_headers->{"receipt"} eq "auto"
not defined $cmd_headers->{"receipt"}
$cmd_headers->{"receipt"} eq "auto"
Truth table0%0/3
not(A) or B
A= not defined $cmd_headers->{"receipt"}B= $cmd_headers->{"receipt"} eq "auto"
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | || $cmd_headers->{receipt} eq 'auto' ) | ||||||||||||||||||||||||||||||||||||||||||
| 575 | { | ||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $cmd_headers->{receipt} = 'R_' . $self->{_session_id} . '.' | |||||||||||||||||||||||||||||||||||||||||
| 577 | . $RECEIPT_SEQ++; | ||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $self->{_pending_receipts}{ $cmd_headers->{receipt} } = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | push( @{ $self->{_write_queue} }, $cmd ); | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my $body = $cmd->{body}; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | unless ( defined $body ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | $body = ''; | |||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | unless ( defined $cmd_headers->{'content-length'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $cmd_headers->{'content-length'} = length($body); | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my $frame_str = $cmd->{name} . EOL; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | while ( my ( $name, $value ) = each %{$cmd_headers} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | unless ( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | $value = ''; | |||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | $frame_str .= _escape($name) . ':' . _escape($value) . EOL; | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | $frame_str .= EOL . "$body\0"; | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $self->{_handle}->push_write($frame_str); | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | sub _login { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_login: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | my ( $cx, $cy ) = @{ $self->{heartbeat} }; | |||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if ( $cy > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | $self->_rtimeout($cy); | |||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | my %cmd_headers = ( | |||||||||||||||||||||||||||||||||||||||||
| 618 | 'accept-version' => '1.0,1.1,1.2', | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 'heart-beat' => join( ',', $cx, $cy ), | ||||||||||||||||||||||||||||||||||||||||||
| 620 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | if ( defined $self->{login} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | $cmd_headers{login} = $self->{login}; | |||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if ( defined $self->{passcode} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $cmd_headers{passcode} = $self->{passcode}; | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | if ( defined $self->{vhost} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | $cmd_headers{host} = $self->{vhost}; | |||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | weaken($self); | |||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | $self->{_login_state} = S_IN_PROGRESS; | |||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | $self->_push_write( | ||||||||||||||||||||||||||||||||||||||||||
| 635 | { name => 'CONNECT', | ||||||||||||||||||||||||||||||||||||||||||
| 636 | headers => \%cmd_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | on_receipt => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | my $receipt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | if ( defined $err ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | $self->{_login_state} = S_NEED_DO; | |||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | $self->_abort($err); | |||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $self->{_login_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | my $receipt_headers = $receipt->headers; | |||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | if ( defined $receipt_headers->{'heart-beat'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | my ( $sx, $sy ) = split( /,/, $receipt_headers->{'heart-beat'} ); | |||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | if ( $sx > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | $self->_rtimeout( max( $cy, $sx ) ); | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | ▶ | if ( $sy > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | $self->_wtimeout( max( $cx, $sy ) ); | |||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | $self->{_ready} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 665 | $self->{_version} | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | ▶ | = version->parse( $receipt_headers->{version} || 1.0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$receipt_headers->{'version'} || 1.0
MC/DC0%0/1
$receipt_headers->{'version'} || 1.0
$receipt_headers->{'version'}
Truth table0%0/2
A
A= $receipt_headers->{'version'}
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | $self->{_session_id} = $receipt_headers->{session} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$receipt_headers->{'session'} || ''
MC/DC0%0/1
$receipt_headers->{'session'} || ''
$receipt_headers->{'session'}
Truth table0%0/2
A
A= $receipt_headers->{'session'}
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | $self->_process_input_queue; | |||||||||||||||||||||||||||||||||||||||||
| 670 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | sub _rtimeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rtimeout: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | my $rtimeout = shift; | |||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | $self->{_handle}->rtimeout_reset; | |||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $self->{_handle}->rtimeout( ( $rtimeout / 1000 ) * 3 ); | |||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | sub _wtimeout { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wtimeout: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | my $wtimeout = shift; | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | $self->{_handle}->wtimeout_reset; | |||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | $self->{_handle}->wtimeout( $wtimeout / ( 1000 * 3 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | sub _process_input_queue { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_input_queue: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | $self->{_temp_input_queue} = $self->{_input_queue}; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | $self->{_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | while ( my $cmd = shift @{ $self->{_temp_input_queue} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | $self->_push_write($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | sub _check_ack { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_ack: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my $msg_headers = $msg->headers; | |||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | my $sub_id = $msg_headers->{subscription} || $msg_headers->{destination}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$msg_headers->{'subscription'} || $msg_headers->{'destination'}
MC/DC0%0/2
$msg_headers->{'subscription'} || $msg_headers->{'destination'}
$msg_headers->{'subscription'}
$msg_headers->{'destination'}
Truth table0%0/3
A || B
A= $msg_headers->{'subscription'}B= $msg_headers->{'destination'}
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | my $sub = $self->{_subs}{$sub_id}; | |||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | my $msg_tag = $msg_headers->{'message-tag'}; | |||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | if ( defined $sub ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | ▶ | if ( defined $sub->{pending_acks} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | if ( ref( $sub->{pending_acks} ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | my $i = bsearch_index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | ▶ | $msg_tag > $_ ? -1 : $msg_tag < $_ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | @{ $sub->{pending_acks} }; | |||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | if ( $i >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | splice( @{ $sub->{pending_acks} }, 0, $i + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||
| 732 | else { # HASH | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | ▶ | return 1 if delete $sub->{pending_acks}{$msg_tag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | sub _process_frame { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_frame: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | my $frame = shift; | |||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | if ( $frame->command eq 'MESSAGE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | $self->_process_message($frame); | |||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||
| 748 | elsif ( $frame->command eq 'RECEIPT' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $self->_process_receipt($frame); | |||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||
| 751 | elsif ( $frame->command eq 'ERROR' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | if ( defined $self->{_pending_receipts}{CONNECTED} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | $frame->headers->{'receipt-id'} = 'CONNECTED'; | |||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | $self->_process_error($frame); | |||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | else { # CONNECTED | ||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | $frame->headers->{'receipt-id'} = 'CONNECTED'; | |||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | $self->_process_receipt($frame); | |||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | sub _process_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_message: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $msg_headers = $msg->headers; | |||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | my $sub_id = $msg_headers->{subscription} || $msg_headers->{destination}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$msg_headers->{'subscription'} || $msg_headers->{'destination'}
MC/DC0%0/2
$msg_headers->{'subscription'} || $msg_headers->{'destination'}
$msg_headers->{'subscription'}
$msg_headers->{'destination'}
Truth table0%0/3
A || B
A= $msg_headers->{'subscription'}B= $msg_headers->{'destination'}
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | my $sub = $self->{_subs}{$sub_id}; | |||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | unless ( defined $sub ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 775 | qq{Don't know how process MESSAGE frame. Unknown subscription "$sub_id"}, | ||||||||||||||||||||||||||||||||||||||||||
| 776 | E_UNEXPECTED_DATA | ||||||||||||||||||||||||||||||||||||||||||
| 777 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | my $msg_tag = $MESSAGE_SEQ++; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $msg_headers->{'message-tag'} = $msg_tag; | |||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | ▶ | if ( defined $sub->{pending_acks} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | if ( ref( $sub->{pending_acks} ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | push( @{ $sub->{pending_acks} }, $msg_tag ); | |||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||
| 790 | else { # HASH | ||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | $sub->{pending_acks}{$msg_tag} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | $sub->{on_message}->($msg); | |||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | ▶ | sub _process_receipt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_receipt: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | my $receipt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | my $receipt_id = $receipt->headers->{'receipt-id'}; | |||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | my $cmd = delete $self->{_pending_receipts}{$receipt_id}; | |||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | unless ( defined $cmd ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | my $err = _new_error( | |||||||||||||||||||||||||||||||||||||||||
| 809 | qq{Unknown RECEIPT frame received: receipt-id=$receipt_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 810 | E_UNEXPECTED_DATA | ||||||||||||||||||||||||||||||||||||||||||
| 811 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | if ( exists $SUBUNSUB_CMDS{ $cmd->{name} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $cmd_headers = $cmd->{headers}; | |||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | my $sub_id = $cmd_headers->{id} || $cmd_headers->{destination}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cmd_headers->{'id'} || $cmd_headers->{'destination'}
MC/DC0%0/2
$cmd_headers->{'id'} || $cmd_headers->{'destination'}
$cmd_headers->{'id'}
$cmd_headers->{'destination'}
Truth table0%0/3
A || B
A= $cmd_headers->{'id'}B= $cmd_headers->{'destination'}
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | if ( $cmd->{name} eq 'SUBSCRIBE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | $self->{_subs}{$sub_id} = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | if ( defined $cmd_headers->{ack} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | ▶ | if ( $cmd_headers->{ack} eq 'client' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | $cmd->{pending_acks} = []; | |||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||
| 828 | elsif ( $cmd_headers->{ack} eq 'client-individual' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | $cmd->{pending_acks} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||
| 833 | else { # UNSUBSCRIBE | ||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | delete $self->{_subs}{$sub_id}; | |||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||
| 837 | elsif ( $cmd->{name} eq 'DISCONNECT' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | $self->_disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | $cmd->{on_receipt}->($receipt); | |||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | ▶ | sub _process_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_error: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | my $err_frame = shift; | |||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | my $err_headers = $err_frame->headers; | |||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | my $err = _new_error( $err_headers->{message}, E_OPRN_ERROR, $err_frame ); | |||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | my $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | ▶ | if ( defined $err_headers->{'receipt-id'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | $cmd = delete $self->{_pending_receipts}{ $err_headers->{'receipt-id'} }; | |||||||||||||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | ▶ | if ( defined $cmd ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | $cmd->{on_receipt}->( undef, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||||||||||||
| 861 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | $self->_disconnect($err); | |||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | ▶ | sub _disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_disconnect: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | my $was_connected = $self->{_connected}; | |||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | ▶ | if ( defined $self->{_handle} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | $self->{_handle}->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | $self->_reset_internals; | |||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | $self->_abort($err); | |||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | ▶ | if ( $was_connected && defined $self->{on_disconnect} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/3
A and B
A= $was_connectedB= defined $self->{"on_disconnect"}
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | 0 | $self->{on_disconnect}->(); | |||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 885 | } | ||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | 9 | ▶ | sub _reset_internals { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_internals: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||
| 890 | 9 | $self->{_handle} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 891 | 9 | $self->{_connected} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 892 | 9 | $self->{_login_state} = S_NEED_DO; | |||||||||||||||||||||||||||||||||||||||||
| 893 | 9 | $self->{_ready} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 894 | 9 | $self->{_version} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 895 | 9 | $self->{_session_id} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 896 | 9 | $self->{_reconnect_timer} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||
| 898 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | ▶ | sub _abort { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_abort: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 902 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | my @queued_commands = $self->_queued_commands; | |||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | my %subs = %{ $self->{_subs} }; | |||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | $self->{_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | $self->{_temp_input_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 910 | 0 | $self->{_write_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | $self->{_temp_write_queue} = []; | |||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | $self->{_pending_receipts} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | $self->{_subs} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | ▶ | if ( !defined $err && @queued_commands ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $err and @queued_commands
MC/DC0%0/2
not defined $err and @queued_commands
not defined $err
@queued_commands
Truth table0%0/3
not(A) and B
A= not defined $errB= @queued_commands
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | $err = _new_error( 'Connection closed by client prematurely.', | |||||||||||||||||||||||||||||||||||||||||
| 917 | E_CONN_CLOSED_BY_CLIENT ); | ||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | ▶ | if ( defined $err ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | my $err_msg = $err->message; | |||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | my $err_code = $err->code; | |||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | my $err_frame = $err->frame; | |||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | $self->{on_error}->($err); | |||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | ▶ | if ( %subs && $err_code != E_CONN_CLOSED_BY_CLIENT ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
%subs and $err_code != 4
MC/DC0%0/2
%subs and $err_code != 4
%subs
$err_code != 4
Truth table0%0/3
A and B
A= %subsB= $err_code != 4
| |||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | foreach my $sub_id ( keys %subs ) { | |||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | my $err = _new_error( qq{Subscription "$sub_id" lost: $err_msg}, | |||||||||||||||||||||||||||||||||||||||||
| 930 | $err_code, $err_frame ); | ||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | my $sub = $subs{$sub_id}; | |||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | $sub->{on_receipt}->( undef, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | foreach my $cmd (@queued_commands) { | |||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | my $err = _new_error( qq{Operation "$cmd->{name}" aborted: $err_msg}, | |||||||||||||||||||||||||||||||||||||||||
| 939 | $err_code, $err_frame ); | ||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | $cmd->{on_receipt}->( undef, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||
| 947 | 9 | ▶ | sub _queued_commands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_queued_commands: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 948 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 951 | 9 | values %{ $self->{_pending_receipts} }, | |||||||||||||||||||||||||||||||||||||||||
| 952 | 9 | @{ $self->{_temp_write_queue} }, | |||||||||||||||||||||||||||||||||||||||||
| 953 | 9 | @{ $self->{_write_queue} }, | |||||||||||||||||||||||||||||||||||||||||
| 954 | 9 | @{ $self->{_temp_input_queue} }, | |||||||||||||||||||||||||||||||||||||||||
| 955 | 9 | @{ $self->{_input_queue} }, | |||||||||||||||||||||||||||||||||||||||||
| 956 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | ▶ | sub _escape { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_escape: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | $str =~ s/([\r\n:\\])/$ESCAPE_MAP{$1}/ge; | |||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||
| 967 | 0 | ▶ | sub _unescape { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unescape: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | $str =~ s/(\\[rnc\\])/$UNESCAPE_MAP{$1}/ge; | |||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | ▶ | sub _new_frame { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_frame: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | return AnyEvent::Stomper::Frame->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | ▶ | sub _new_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | return AnyEvent::Stomper::Error->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||
| 983 | 15 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 984 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||
| 986 | 15 | ▶ | if ( defined $self->{_handle} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 987 | 5 | $self->{_handle}->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 988 | } | ||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||
| 990 | 15 | ▶ | if ( defined $self->{_pending_receipts} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 991 | 9 | my @queued_commands = $self->_queued_commands; | |||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||
| 993 | 9 | foreach my $cmd (@queued_commands) { | |||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | warn qq{Operation "$cmd->{name}" aborted:} | |||||||||||||||||||||||||||||||||||||||||
| 995 | . " Client object destroyed prematurely.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||
| 1002 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1003 | __END__ | ||||||||||||||||||||||||||||||||||||||||||