| 1 | package Linux::Event::WebSocket::Client; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use URI (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Linux::Event::HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Linux::Event::WebSocket::Client::Connection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Linux::Event::WebSocket::Client::_HTTPConnection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Linux::Event::WebSocket::_Handshake; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Linux::Event::WebSocket::_State; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | my $DEFAULT_MAX_MESSAGE_SIZE = 16 * 1024 * 1024; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | sub _load_connection_class ($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_connection_class: called CC=6 SCAR=23.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | croak 'new(): connection_class must be a package name' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $class or ref $class or not $class =~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/u
not defined $class or ref $class
MC/DC0%0/3
not defined $class or ref $class or not $class =~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/u
not defined $class
ref $class
not $class =~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $classB= ref $classC= not $class =~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | if !defined($class) || ref($class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | || $class !~ /\A[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | if (!$class->can('send_text')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | (my $file = "$class.pm") =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | require $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | croak 'new(): connection_class must inherit Linux::Event::WebSocket::Client::Connection' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | if !$class->isa('Linux::Event::WebSocket::Client::Connection'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | return $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 35 | ▶ | sub _take_callback ($name, $option) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_take_callback: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 35 | ▶ | return undef if !exists $option->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 24 | my $callback = delete $option->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 24 | ▶ | croak "new(): $name must be a coderef" if ref($callback) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 24 | return $callback; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 7 | ▶ | sub _subprotocols ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_subprotocols: called CC=6 SCAR=20.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | ▶ | croak 'new(): subprotocols must be an array reference' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | if ref($value) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | my @copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | for my $token (@$value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | croak 'new(): each subprotocol must be a WebSocket token' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $token or ref $token or not $token =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u
not defined $token or ref $token
MC/DC0%0/3
not defined $token or ref $token or not $token =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u
not defined $token
ref $token
not $token =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $tokenB= ref $tokenC= not $token =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | if !defined($token) || ref($token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | || $token !~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | push @copy, "$token"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | return \@copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | ▶ | sub _headers ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_headers: called CC=10 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | ▶ | croak 'new(): headers must be an array reference' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | if ref($value) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | my %reserved = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | host connection upgrade sec-websocket-key sec-websocket-version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | sec-websocket-protocol sec-websocket-extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | my @copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 7 | for my $pair (@$value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | croak 'new(): each header must be a [name, value] pair' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $pair ne "ARRAY" or @$pair != 2
MC/DC0%0/2
ref $pair ne "ARRAY" or @$pair != 2
ref $pair ne "ARRAY"
@$pair != 2
Truth table0%0/3
A or B
A= ref $pair ne "ARRAY"B= @$pair != 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | if ref($pair) ne 'ARRAY' || @$pair != 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my ($name, $header_value) = @$pair; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | croak 'new(): header name and value must be scalars' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not defined $name or ref $name or not defined $header_value or ref $header_value
not defined $name or ref $name or not defined $header_value
not defined $name or ref $name
MC/DC0%0/4
not defined $name or ref $name or not defined $header_value or ref $header_value
not defined $name
ref $name
not defined $header_value
ref $header_value
Truth table0%0/5
not(A) or B or not(C) or D
A= not defined $nameB= ref $nameC= not defined $header_valueD= ref $header_value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | if !defined($name) || ref($name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | || !defined($header_value) || ref($header_value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | croak "new(): WebSocket handshake owns header $name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if $reserved{lc $name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | push @copy, [ "$name", "$header_value" ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | return \@copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | ▶ | sub _nonnegative_number ($where, $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nonnegative_number: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | ▶ | croak "$where must be a non-negative number" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $value or ref $value or not "$value" =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
not defined $value or ref $value
MC/DC0%0/3
not defined $value or ref $value or not "$value" =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
not defined $value
ref $value
not "$value" =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not "$value" =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | if !defined($value) || ref($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | || "$value" !~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | return 0 + $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | ▶ | sub _positive_integer ($where, $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_positive_integer: called CC=5 SCAR=21.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | ▶ | croak "$where must be a positive integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/u or $value < 1
not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/u
not defined $value or ref $value
MC/DC0%0/4
not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/u or $value < 1
not defined $value
ref $value
not "$value" =~ /\A[0-9]+\z/u
$value < 1
Truth table20%1/5
not(A) or B or not(C) or D
A= not defined $valueB= ref $valueC= not "$value" =~ /\A[0-9]+\z/uD= $value < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | if !defined($value) || ref($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | || "$value" !~ /\A[0-9]+\z/ || $value < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | return 0 + $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | ▶ | sub new ($class, %option) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=19 SCAR=33.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | my $loop = delete $option{loop} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 7 | ▶ | // croak 'new(): loop is required'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $option{"loop"} // croak("new(): loop is required")
MC/DC0%0/2
delete $option{"loop"} // croak("new(): loop is required")
delete $option{"loop"}
croak("new(): loop is required")
Truth table33%1/3
A // B
A= delete $option{"loop"}B= croak("new(): loop is required")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | ▶ | croak 'new(): loop must implement add() and watch_fd()' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
builtin::blessed($loop) and $loop->can("add") and $loop->can("watch_fd")
builtin::blessed($loop) and $loop->can("add")
MC/DC0%0/3
builtin::blessed($loop) and $loop->can("add") and $loop->can("watch_fd")
builtin::blessed($loop)
$loop->can("add")
$loop->can("watch_fd")
Truth table25%1/4
A and B and C
A= builtin::blessed($loop)B= $loop->can("add")C= $loop->can("watch_fd")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | if !blessed($loop) || !$loop->can('add') || !$loop->can('watch_fd'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | my $connection_class = _load_connection_class( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | delete($option{connection_class}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | ▶ | // 'Linux::Event::WebSocket::Client::Connection', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $option{"connection_class"} // "Linux::Event::WebSocket::Client::Connection"
MC/DC0%0/1
delete $option{"connection_class"} // "Linux::Event::WebSocket::Client::Connection"
delete $option{"connection_class"}
Truth table50%1/2
A
A= delete $option{"connection_class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | my %callbacks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 7 | for my $name (qw(on_open on_message on_close on_error on_drain)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 35 | my $callback = _take_callback($name, \%option); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 35 | (my $short = $name) =~ s/\Aon_//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 35 | ▶ | $callbacks{$short} = $callback if $callback; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | my $subprotocols = _subprotocols( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | exists($option{subprotocols}) ? delete($option{subprotocols}) : [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | my $headers = _headers( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | ▶ | exists($option{headers}) ? delete($option{headers}) : [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 7 | my $origin = delete $option{origin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | ▶ | croak 'new(): origin must be a scalar' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $origin and ref $origin
MC/DC0%0/2
defined $origin and ref $origin
defined $origin
ref $origin
Truth table33%1/3
A and B
A= defined $originB= ref $origin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | if defined($origin) && ref($origin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 7 | ▶ | my $tls = exists($option{tls}) ? delete($option{tls}) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | ▶ | croak 'new(): tls must be a hash reference' if ref($tls) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | my $connect_timeout = delete $option{connect_timeout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | ▶ | $connect_timeout = _nonnegative_number( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'new(): connect_timeout', $connect_timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ) if defined $connect_timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | my $close_timeout = _nonnegative_number( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 'new(): close_timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | ▶ | exists($option{close_timeout}) ? delete($option{close_timeout}) : 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | my $max_message_size = _positive_integer( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 'new(): max_message_size', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | exists($option{max_message_size}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ? delete($option{max_message_size}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | ▶ | : $DEFAULT_MAX_MESSAGE_SIZE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | my $data = delete $option{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | ▶ | croak 'new(): unknown option(s): ' . join(', ', sort keys %option) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | if %option; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | ▶ | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | loop => $loop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | connection_class => $connection_class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | callbacks => \%callbacks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | subprotocols => $subprotocols, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | origin => defined($origin) ? "$origin" : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | tls => { %$tls }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | connect_timeout => $connect_timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | close_timeout => $close_timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | max_message_size => $max_message_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | connection => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | url => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | ▶ | sub _destination ($url) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_destination: called CC=20 SCAR=36.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | ▶ | croak 'connect(): URL must be a non-empty scalar' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $url or ref $url or $url eq ""
not defined $url or ref $url
MC/DC0%0/3
not defined $url or ref $url or $url eq ""
not defined $url
ref $url
$url eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $urlB= ref $urlC= $url eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | if !defined($url) || ref($url) || $url eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 7 | my ($scheme) = "$url" =~ /\A([A-Za-z][A-Za-z0-9+.-]*):/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | ▶ | $scheme = lc($scheme // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$scheme // ""
MC/DC0%0/1
$scheme // ""
$scheme
Truth table50%1/2
A
A= $scheme
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 7 | ▶ | croak 'connect(): URL scheme must be ws or wss' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$scheme ne "ws" and $scheme ne "wss"
MC/DC0%0/2
$scheme ne "ws" and $scheme ne "wss"
$scheme ne "ws"
$scheme ne "wss"
Truth table66%2/3
A and B
A= $scheme ne "ws"B= $scheme ne "wss"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | if $scheme ne 'ws' && $scheme ne 'wss'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 7 | my $http_url = "$url"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 7 | ▶ | my $http_scheme = $scheme eq 'wss' ? 'https' : 'http'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 7 | $http_url =~ s/\A[A-Za-z][A-Za-z0-9+.-]*:/$http_scheme:/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 7 | my $uri = URI->new($http_url); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | my $host = $uri->host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 7 | ▶ | croak 'connect(): URL must contain a host' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $host or $host eq ""
MC/DC0%0/2
not defined $host or $host eq ""
not defined $host
$host eq ""
Truth table33%1/3
not(A) or B
A= not defined $hostB= $host eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | if !defined($host) || $host eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 7 | ▶ | croak 'connect(): URL userinfo is not supported' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $uri->userinfo and length $uri->userinfo
MC/DC0%0/2
defined $uri->userinfo and length $uri->userinfo
defined $uri->userinfo
length $uri->userinfo
Truth table33%1/3
A and B
A= defined $uri->userinfoB= length $uri->userinfo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | if defined($uri->userinfo) && length($uri->userinfo); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | my $port = $uri->port; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | ▶ | croak 'connect(): URL port must be between 1 and 65535' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $port && $port =~ /\A[0-9]+\z/u or $port < 1 or $port > 65535
not defined $port && $port =~ /\A[0-9]+\z/u or $port < 1
defined $port && $port =~ /\A[0-9]+\z/u
MC/DC0%0/4
not defined $port && $port =~ /\A[0-9]+\z/u or $port < 1 or $port > 65535
defined $port
$port =~ /\A[0-9]+\z/u
$port < 1
$port > 65535
Truth table20%1/5
not(A && B) or C or D
A= defined $portB= $port =~ /\A[0-9]+\z/uC= $port < 1D= $port > 65535
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | if !defined($port) || $port !~ /\A[0-9]+\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | || $port < 1 || $port > 65_535; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 7 | ▶ | my $default_port = $scheme eq 'wss' ? 443 : 80; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 7 | ▶ | my $authority_host = $host =~ /:/ ? "[$host]" : $host; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 7 | my $host_header = $authority_host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 7 | ▶ | $host_header .= ":$port" if $port != $default_port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | ▶ | scheme => $scheme, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | secure => $scheme eq 'wss' ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | host => $host, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | port => 0 + $port, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | host_header => $host_header, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub _report_error ($state, $connection, $error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_error: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $message = "$error"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $message =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if (my $callback = $state->{callbacks}{error}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $callback->($connection, $message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 7 | ▶ | sub connect ($self, $url) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | croak 'connect(): Client already has an active connection' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 7 | ▶ | if $self->{connection} && !$self->{connection}->is_closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"connection"} and not $self->{"connection"}->is_closed
MC/DC0%0/2
$self->{"connection"} and not $self->{"connection"}->is_closed
$self->{"connection"}
not $self->{"connection"}->is_closed
Truth table33%1/3
A and not(B)
A= $self->{"connection"}B= not $self->{"connection"}->is_closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | my $destination = _destination($url); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | my ($handshake, $request) = Linux::Event::WebSocket::_Handshake->client_request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | origin => $self->{origin}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | subprotocols => $self->{subprotocols}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | headers => $self->{headers}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | host_header => $destination->{host_header}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | my $state = Linux::Event::WebSocket::_State->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | endpoint_type => 'client', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | callbacks => $self->{callbacks}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | subprotocols => $self->{subprotocols}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | data => $self->{data}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | handshake => $handshake, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | request => $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | secure => $destination->{secure}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | url => "$url", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | close_timeout => $self->{close_timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | max_message_size => $self->{max_message_size}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | my %connect = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | loop => $self->{loop}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | host => $destination->{host}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | port => $destination->{port}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | data => $state, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | $connect{timeout} = $self->{connect_timeout} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | ▶ | if defined $self->{connect_timeout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | ▶ | if ($destination->{secure}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | require Linux::Event::TLS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | $connect{transport} = Linux::Event::TLS->client( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | server_name => $destination->{host}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | alpn => ['http/1.1'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | %{$self->{tls}}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | my $connection = Linux::Event::WebSocket::Client::_HTTPConnection->connect( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | %connect, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 7 | $self->{connection} = $connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 7 | $self->{url} = "$url"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | $connection->request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | upgrade_to => $self->{connection_class}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | ▶ | on_response => sub ($transaction, $response) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 7 | $state->{response} = $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 7 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 7 | Linux::Event::WebSocket::_Handshake->validate_client_response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | $handshake, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | $response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 7 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $transaction->cancel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | _report_error($state, $connection, $error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 7 | ▶ | on_upgrade => sub ($transaction, $response, $upgraded) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 7 | $state->{response} = $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | $upgraded->_ensure_websocket_open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | on_error => sub ($transaction, $error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | _report_error($state, $connection, $error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 7 | return $connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub loop ($self) { $self->{loop} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | sub data ($self) { $self->{data} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub connection_class ($self) { $self->{connection_class} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection_class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ▶ | sub connection ($self) { $self->{connection} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub url ($self) { $self->{url} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub is_open ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_open: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | my $connection = $self->{connection} or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | return 0 if !$connection->isa('Linux::Event::WebSocket::Connection'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | return $connection->is_open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | sub send_text ($self, @argument) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_text: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | my $connection = $self->{connection} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | or croak 'send_text(): Client is not connected'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | croak 'send_text(): WebSocket handshake is not complete' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | if !$connection->isa('Linux::Event::WebSocket::Connection'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return $connection->send_text(@argument); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub send_binary ($self, @argument) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_binary: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | my $connection = $self->{connection} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | or croak 'send_binary(): Client is not connected'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | croak 'send_binary(): WebSocket handshake is not complete' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | if !$connection->isa('Linux::Event::WebSocket::Connection'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | return $connection->send_binary(@argument); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub ping ($self, @argument) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ping: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | my $connection = $self->{connection} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | or croak 'ping(): Client is not connected'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | croak 'ping(): WebSocket handshake is not complete' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | if !$connection->isa('Linux::Event::WebSocket::Connection'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | return $connection->ping(@argument); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub close ($self, %option) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | my $connection = $self->{connection} or return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ($connection->isa('Linux::Event::WebSocket::Connection')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $connection->close(%option); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } elsif (!$connection->is_closed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $connection->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||