| 1 | package Net::Async::Kubernetes::PortForwardSession; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Duplex websocket session for pod port-forward, exec and attach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 54 | our $VERSION = '0.012'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 54 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 54 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 54 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 24 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 24 | ▶ | croak "ws_client required" unless $args{ws_client}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 24 | ▶ | if (defined $args{ports}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | croak "ports must be a non-empty array reference" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 20 | ▶ | unless ref($args{ports}) eq 'ARRAY' && @{$args{ports}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args{"ports"} eq "ARRAY" and @{$args{"ports"};}
MC/DC0%0/2
ref $args{"ports"} eq "ARRAY" and @{$args{"ports"};}
ref $args{"ports"} eq "ARRAY"
@{$args{"ports"};}
Truth table33%1/3
A and B
A= ref $args{"ports"} eq "ARRAY"B= @{$args{"ports"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | $args{ports} = [@{$args{ports}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 20 | for my $port (@{$args{ports}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 26 | ▶ | $args{_port_index}{$port} //= $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"_port_index"}{$port} //= $i
MC/DC0%0/2
$args{"_port_index"}{$port} //= $i
$args{"_port_index"}{$port}
$i
Truth table33%1/3
A //= B
A= $args{"_port_index"}{$port}B= $i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 26 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 24 | return bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 44 | ▶ | sub ws_client { $_[0]->{ws_client} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ws_client: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 40 | ▶ | sub is_port_forward { $_[0]->{ports} ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_port_forward: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | sub ports { $_[0]->{ports} ? [@{$_[0]->{ports}}] : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ports: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # The events one incoming frame of a port-forward session stands for, after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # the two-byte port preamble every channel starts with is checked and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # stripped: ['data', $port, $bytes], ['port_error', $port, $message] or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # ['error', $message] (what Net::Async::Kubernetes hands to on_data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # on_port_error and on_error). A channel whose preamble was wrong delivers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # nothing further. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 38 | ▶ | sub _port_events { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_port_events: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 38 | my ($self, $channel, $payload) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 38 | my @ports = @{$self->{ports}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 38 | ▶ | return ['error', 'port-forward frame on channel ' . $channel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | . ' but ' . scalar(@ports) . ' port(s) requested use channels 0 to ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | . (2 * @ports - 1)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | if $channel >= 2 * @ports; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 37 | my $port = $ports[int($channel / 2)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 37 | my $is_err = $channel % 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 37 | ▶ | my $what = 'channel ' . $channel . ' (' . ($is_err ? 'error' : 'data') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | . ' of port ' . $port . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 37 | my $state = $self->{_channel_state}{$channel}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 37 | ▶ | unless ($state) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 22 | my $problem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 22 | ▶ | if (length($payload) != 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | $problem = length($payload) > 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ? 'first frame carries data after the port number' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | : 'first frame is not a 2-byte port number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | $problem .= ' (' . length($payload) . ' bytes)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } elsif ((my $got = unpack('v', $payload)) != $port) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | $problem = 'port preamble says ' . $got; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 22 | ▶ | $self->{_channel_state}{$channel} = defined $problem ? 'broken' : 'open'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 22 | ▶ | return defined $problem ? (['error', $what . ': ' . $problem]) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 15 | ▶ | return if $state eq 'broken'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 14 | ▶ | return unless length $payload; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 14 | ▶ | return $is_err ? (['port_error', $port, $payload]) : (['data', $port, $payload]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 14 | ▶ | sub write_port { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_port: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 14 | my ($self, $port, $payload) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 14 | ▶ | croak "write_port is only for port-forward sessions" unless $self->{ports}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 13 | ▶ | croak "port required for write_port" unless defined $port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | my $i = $self->{_port_index}{$port}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 12 | ▶ | croak "port '$port' is not forwarded by this session" unless defined $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 11 | return $self->write_channel(2 * $i, $payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | ▶ | sub write_channel { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_channel: called CC=7 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | my ($self, $channel, $payload) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 15 | ▶ | croak "channel required for write_channel" unless defined $channel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 15 | ▶ | croak "invalid channel '$channel' for write_channel" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$channel =~ /^\d+$/ and $channel >= 0 and $channel <= 255
$channel =~ /^\d+$/ and $channel >= 0
MC/DC0%0/3
$channel =~ /^\d+$/ and $channel >= 0 and $channel <= 255
$channel =~ /^\d+$/
$channel >= 0
$channel <= 255
Truth table25%1/4
A and B and C
A= $channel =~ /^\d+$/B= $channel >= 0C= $channel <= 255
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | unless $channel =~ /^\d+$/ && $channel >= 0 && $channel <= 255; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 15 | ▶ | $payload = '' unless defined $payload; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 15 | ▶ | croak "payload must be a plain string for write_channel" if ref($payload); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 15 | return $self->ws_client->send_binary_frame(chr($channel) . $payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | ▶ | sub write_stdin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_stdin: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | my ($self, $payload) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | croak "write_stdin is not available on a port-forward session (use write_port)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | ▶ | if $self->{ports}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return $self->write_channel(0, $payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 54 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 54 | *write = \&write_channel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 54 | *stdin = \&write_stdin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | ▶ | sub resize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resize: called CC=10 SCAR=23.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 5 | ▶ | croak "resize is not available on a port-forward session" if $self->{ports}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | my $width = exists($args{width}) ? $args{width} : $args{cols}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | my $height = exists($args{height}) ? $args{height} : $args{rows}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | ▶ | croak "width required for resize" unless defined $width; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | croak "height required for resize" unless defined $height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | croak "invalid width '$width' for resize" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$width =~ /^\d+$/ and $width > 0
MC/DC50%1/2
$width =~ /^\d+$/ and $width > 0
$width =~ /^\d+$/
$width > 0
Truth table66%2/3
A and B
A= $width =~ /^\d+$/B= $width > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | unless $width =~ /^\d+$/ && $width > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | croak "invalid height '$height' for resize" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$height =~ /^\d+$/ and $height > 0
MC/DC0%0/2
$height =~ /^\d+$/ and $height > 0
$height =~ /^\d+$/
$height > 0
Truth table33%1/3
A and B
A= $height =~ /^\d+$/B= $height > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | unless $height =~ /^\d+$/ && $height > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $payload = sprintf('{"Width":%d,"Height":%d}', $width, $height); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | return $self->write_channel(4, $payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=9 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | my $code = $args{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | ▶ | my $payload = exists $args{payload} ? $args{payload} : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | ▶ | croak "payload must be a plain string for close" if ref($payload); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 9 | ▶ | croak "invalid websocket close code '$code'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $code and !($code =~ /^\d+$/) || $code < 1000 || $code > 4999
not $code =~ /^\d+$/ or $code < 1000 or $code > 4999
not $code =~ /^\d+$/ or $code < 1000
MC/DC0%0/4
defined $code and !($code =~ /^\d+$/) || $code < 1000 || $code > 4999
defined $code
not $code =~ /^\d+$/
$code < 1000
$code > 4999
Truth table20%1/5
A and not(B) or C or D
A= defined $codeB= not $code =~ /^\d+$/C= $code < 1000D= $code > 4999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | if defined($code) && ($code !~ /^\d+$/ || $code < 1000 || $code > 4999); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 9 | ▶ | my $close_payload = defined($code) ? pack('n', $code) . $payload : $payload; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 9 | my $ret = $self->ws_client->send_close_frame($close_payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | ▶ | $self->ws_client->close_when_empty if $self->ws_client->can('close_when_empty'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 54 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||