Promise/IO.pm

filter: Statementstmt 53.5% 285 / 532 Branchbran 28.6% 119 / 416 Conditioncond 19.9% 48 / 241 MC/DCmcdc 5.9% 8 / 134 Subroutinesub 71.4% 35 / 49 Podpod 85.7% 24 / 28 totaltotal 37.0% 519 / 1400 CC 304 SCAR 56.0
CC
304
Cov
38%
connect
1332.0
connect_ssl_over_proxy
756.0
make_select_timeout
306.0
CRAP 271.6
« Promise/Entity.pm ↑ Summary Promise/Message.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/IO.pm
3 ## Version v0.1.1
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/05/02
7 ## Modified 2025/10/12
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTTP::Promise::IO;
15 BEGIN
16 10 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 warnings::register_categories( 'HTTP::Promise' );
20 10 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 10 ▶ use vars qw( $CRLF $IS_WIN32 $INIT_PARAMS $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 10 ▶ use Errno qw( EAGAIN ECONNRESET EINPROGRESS EINTR EWOULDBLOCK ECONNABORTED EISCONN );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 10 ▶ use Fcntl qw( F_GETFL F_SETFL O_NONBLOCK O_RDONLY O_RDWR SEEK_SET SEEK_END );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 10 ▶ use Socket qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
25 PF_INET SOCK_STREAM
26 IPPROTO_TCP
27 TCP_NODELAY
28 pack_sockaddr_in
29 INADDR_ANY
30 10 );
31 10 ▶ use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 10 ▶ use constant ERROR_EINTR => ( abs( Errno::EINTR ) * -1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 10 our $CRLF = "\015\012";
34 10 our $IS_WIN32 = ( $^O eq 'MSWin32' );
35 # This is for connect() so it knows
36 10 our $INIT_PARAMS = [qw( buffer debug inactivity_timeout last_delimiter max_read_buffer ssl_opts stop_if timeout )];
37 10 our $VERSION = 'v0.1.1';
38 };
39  
40 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 sub init
44 25 ▶{
Subroutine init: called CC=9 SCAR=25.0
Pod documented
45 25 my $self = shift( @_ );
46 25 ▶ return( $self->error( "No filehandle was provided." ) ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 25 25
47 25 my $fh = shift( @_ );
48 25 ▶ return( $self->error( "Filehandle provided (", overload::StrVal( $fh ), ") is not a proper filehandle." ) ) if( !$self->_is_glob( $fh ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_glob($fh) 0 25 25
49 # This needs to be set to empty string and not undef to make chaining work with Module::Generic::Scalar
50 25 $self->{buffer} = '';
51 25 $self->{inactivity_timeout} = 600;
52 25 $self->{last_delimiter} = '';
53 25 $self->{max_read_buffer} = 0;
54 25 $self->{ssl_opts} = {};
55 25 ▶ $self->{stop_if} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=0.0
56 25 $self->{timeout} = 5;
57 25 $self->{_init_strict_use_sub} = 1;
58 25 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 25 0 25
59 # Ensure O_NONBLOCK is set so that calls to select in can_read() would not report ok
60 # although no data is available. See select in perlfunc for more details.
61 25 my $dummy = '';
62 25 ▶ if( $self->_can( $fh => 'fcntl' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($fh, 'fcntl')) { } 25 0 25
63 {
64 25 my $flags = $fh->fcntl( F_GETFL, $dummy );
65 25 ▶ return( $self->error({ code => 500, message => "Unable to get flags from filehandle '$fh': $!" }) ) if( !defined( $flags ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 0 25 25
66 25 my $rv = $fh->fcntl( F_SETFL, ( $flags | O_NONBLOCK ) );
67 25 ▶ return( $self->error({ code => 500, message => "Unable to set flags to filehandle '$fh': $!" }) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 25 25
68 }
69 else
70 {
71 0 my $flags = fcntl( $fh, F_GETFL, $dummy );
72 0 ▶ return( $self->error({ code => 500, message => "Unable to get flags from filehandle '$fh': $!" }) ) if( !defined( $flags ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 0 0 0
73 0 my $rv = fcntl( $fh, F_SETFL, ( $flags | O_NONBLOCK ) );
74 0 ▶ return( $self->error({ code => 500, message => "Unable to set flags to filehandle '$fh': $!" }) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
75 }
76 25 $self->{_fh} = $fh;
77 25 return( $self );
78 }
79  
80 269 ▶sub buffer { return( shift->_set_get_scalar_as_object( 'buffer', @_ ) ); }
Subroutine buffer: called CC=1 SCAR=0.0
Pod documented
81  
82 sub can_read
83 130 ▶{
Subroutine can_read: called CC=20 SCAR=46.5
Pod documented
84 130 my $self = shift( @_ );
85 130 my $fh = $self->filehandle;
86 130 my $opts = $self->_get_args_as_hash( @_ );
87 130 ▶ return(1) unless( defined( fileno( $fh ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined fileno $fh 0 130 130
88 130 ▶ return(1) if( $fh->isa( 'IO::Socket::SSL' ) && $fh->pending );
Branch: 1 branch
BranchTrueFalseTotal
if $fh->isa("IO::Socket::SSL") and $fh->pending 0 130 130
Condition33%1/3
$fh->isa("IO::Socket::SSL") and $fh->pending
!ll&&!rl&&r
13000
MC/DC0%0/2
$fh->isa("IO::Socket::SSL") and $fh->pending
$fh->isa("IO::Socket::SSL") $fh->pending
Truth table33%1/3
A and B
A= $fh->isa("IO::Socket::SSL")B= $fh->pending
ABresult
0X0
100
111
89 130 ▶ return(1) if( $fh->isa( 'Net::SSL' ) && $fh->can('pending') && $fh->pending );
Branch: 1 branch
BranchTrueFalseTotal
if $fh->isa("Net::SSL") and $fh->can("pending") and $fh->pending 0 130 130
Condition33%2/6
$fh->isa("Net::SSL") and $fh->can("pending") and $fh->pending
!ll&&!rl&&r
13000
$fh->isa("Net::SSL") and $fh->can("pending")
!ll&&!rl&&r
13000
MC/DC0%0/3
$fh->isa("Net::SSL") and $fh->can("pending") and $fh->pending
$fh->isa("Net::SSL") $fh->can("pending") $fh->pending
Truth table25%1/4
A and B and C
A= $fh->isa("Net::SSL")B= $fh->can("pending")C= $fh->pending
ABCresult
0XX0
10X0
1100
1111
90
91 # If this is an in-memory scalar filehandle
92 # check that it is opened so we can read from it
93 130 ▶ if( fileno( $fh ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (fileno $fh == -1) 12 118 130
94 {
95 12 ▶ if( $self->_can( $fh => 'can_read' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($fh, 'can_read')) { } 12 0 12
96 {
97 12 return( $fh->can_read );
98 }
99 else
100 {
101 0 my( $dummy, $flags );
102 0 ▶ if( $self->_can( $fh => 'fcntl' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can($fh, 'fcntl')) { } 0 0 0
103 {
104 0 $flags = $fh->fcntl( F_GETFL, $dummy );
105 }
106 else
107 {
108 0 $flags = fcntl( $fh, F_GETFL, $dummy );
109 }
110 0 ▶ return( $self->error({ code => 500, message => "Unable to get flags from filehandle '$fh': $!" }) ) if( !defined( $flags ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 0 0 0
111 0 ▶ return( ( $flags == O_RDONLY ) || ( $flags & ( O_RDONLY | O_RDWR ) ) );
Condition0%0/3
$flags == 0 || $flags & 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$flags == 0 || $flags & 2
$flags == 0 $flags & 2
Truth table0%0/3
A || B
A= $flags == 0B= $flags & 2
ABresult
1X1
011
000
112 }
113 }
114  
115 # With no timeout, wait forever. An explicit timeout of 0 can be used to just check
116 # if the socket is readable without waiting.
117 118 ▶ my $timeout = $opts->{timeout} ? $opts->{timeout} : $self->timeout;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'timeout'} ? : 0 118 118
118  
119 118 my $fbits = '';
120 118 vec( $fbits, fileno( $fh ), 1 ) = 1;
121 SELECT:
122 {
123 118 my $before;
124 118 ▶ $before = time() if( $timeout );
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 118 0 118
125 118 my $nfound = select( $fbits, undef, undef, $timeout );
126 118 ▶ if( $nfound < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($nfound < 0) 0 118 118
127 {
128 0 ▶ if( $!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK} )
Branch: 1 branch
BranchTrueFalseTotal
if ($!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}) 0 0 0
Condition0%0/6
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
$!{"EINTR"} or $!{"EAGAIN"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"} $!{"EAGAIN"} $!{"EWOULDBLOCK"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
ABCresult
1XX1
01X1
0011
0000
129 {
130 # don't really think EAGAIN/EWOULDBLOCK can happen here
131 0 ▶ if( $timeout )
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) 0 0 0
132 {
133 0 $timeout -= time() - $before;
134 0 ▶ $timeout = 0 if( $timeout < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $timeout < 0 0 0 0
135 }
136 0 redo( SELECT );
137 }
138 0 return( $self->error({ code => 500, message => "select failed: $!" }) );
139 }
140 118 return( $nfound > 0 );
141 }
142 }
143  
144 sub close
145 0 ▶{
Subroutine close: not called CC=2 SCAR=17.9
Pod documented
146 0 my $self = shift( @_ );
147 0 my $fh = $self->filehandle;
148 0 ▶ $fh->close if( $self->_can( $fh, 'close' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_can($fh, "close") 0 0 0
149 0 $self->filehandle( undef );
150 0 $self->DESTROY;
151 }
152  
153 sub connect
154 0 ▶{
Subroutine connect: not called CC=36 SCAR=71.9
Pod documented
155 0 my $self = shift( @_ );
156 0 my $opts = $self->_get_args_as_hash( @_ );
157 0 ▶ my $host = $opts->{host} || return( $self->error( "No host to connect to was provided." ) );
Condition0%0/2
$opts->{'host'} || (return $self->error('No host to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'host'} || (return $self->error('No host to connect to was provided.'))
$opts->{'host'}
Truth table0%0/2
A
A= $opts->{'host'}
Aresult
11
00
158 0 ▶ my $port = $opts->{port} || return( $self->error( "No port to connect to was provided." ) );
Condition0%0/2
$opts->{'port'} || (return $self->error('No port to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'port'} || (return $self->error('No port to connect to was provided.'))
$opts->{'port'}
Truth table0%0/2
A
A= $opts->{'port'}
Aresult
11
00
159 0 ▶ return( $self->error( "Port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $port =~ /^\d+$/ 0 0 0
160 0 ▶ return( $self->error( "No timeout was provided to connect." ) ) if( !exists( $opts->{timeout} ) || !length( $opts->{timeout} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"timeout"} and length $opts->{"timeout"} 0 0 0
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"timeout"} and length $opts->{"timeout"}
exists $opts->{"timeout"} length $opts->{"timeout"}
Truth table0%0/3
A and B
A= exists $opts->{"timeout"}B= length $opts->{"timeout"}
ABresult
0X0
100
111
161 0 my $sock;
162  
163 0 ▶ my $stop_if = $self->_is_code( $opts->{stop_if} ) ? $opts->{stop_if} : sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_code($opts->{'stop_if'}) ? : 0 0 0
164 0 $opts->{stop_if} = $stop_if;
165 0 my $timeout = $opts->{timeout};
166 0 local $@;
167 my $sock_addr = eval
168 0 {
169 0 ▶ local $SIG{ALRM} = sub{ die( "timeout\n" ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
170 0 ▶ alarm( $timeout ) if( defined( $timeout ) && $timeout > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if defined $timeout and $timeout > 0 0 0 0
Condition0%0/3
defined $timeout and $timeout > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $timeout and $timeout > 0
defined $timeout $timeout > 0
Truth table0%0/3
A and B
A= defined $timeoutB= $timeout > 0
ABresult
0X0
100
111
171 0 ▶ my $ipbin = Socket::inet_aton( $host ) ||
Condition0%0/2
Socket::inet_aton($host) || (return $self->error("Cannot resolve host name: $host (port: $port): $!"))
l!l
00
MC/DC0%0/1
Socket::inet_aton($host) || (return $self->error("Cannot resolve host name: $host (port: $port): $!"))
Socket::inet_aton($host)
Truth table0%0/2
A
A= Socket::inet_aton($host)
Aresult
11
00
172 return( $self->error( "Cannot resolve host name: ${host} (port: ${port}): $!" ) );
173 0 Socket::pack_sockaddr_in( $port, $ipbin );
174 };
175 0 alarm(0);
176 0 ▶ unless( $sock_addr )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock_addr) 0 0 0
177 {
178 0 return( $self->error( "Cannot resolve host name: ${host} (port: ${port}): $!" ) );
179 }
180 0 ▶ return( $self->error( "Failed to resolve host name '$host': timeout" ) ) if( $@ =~ /timeout/i );
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /timeout/i 0 0 0
181
182 0 my( $lport, $laddr );
183 0 ▶ $lport = $opts->{local_port} if( exists( $opts->{local_port} ) && defined( $opts->{local_port} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"local_port"} and defined $opts->{"local_port"} 0 0 0
Condition0%0/3
exists $opts->{"local_port"} and defined $opts->{"local_port"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"local_port"} and defined $opts->{"local_port"}
exists $opts->{"local_port"} defined $opts->{"local_port"}
Truth table0%0/3
A and B
A= exists $opts->{"local_port"}B= defined $opts->{"local_port"}
ABresult
0X0
100
111
184 $laddr = defined( $opts->{local_host} )
185 ? Socket::inet_aton( $opts->{local_host} )
186 0 ▶ : INADDR_ANY;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'local_host'} ? : 0 0 0
187 0 ▶ return( $self->error( "Bad local host provided \"$opts->{local_host}\": $!" ) ) if( !defined( $laddr ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $laddr 0 0 0
188
189 0 ▶ if( defined( $lport ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lport or $laddr ne "\0\0\0\0") 0 0 0
Condition0%0/3
defined $lport or $laddr ne "\0\0\0\0"
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $lport or $laddr ne "\0\0\0\0"
defined $lport $laddr ne "\0\0\0\0"
Truth table0%0/3
A or B
A= defined $lportB= $laddr ne "\0\0\0\0"
ABresult
1X1
011
000
190 ( $laddr ne INADDR_ANY ) )
191 {
192 0 ▶ my $local_sock_addr = Socket::pack_sockaddr_in( ( $lport // 0 ), $laddr ) ||
Condition0%0/4
Socket::pack_sockaddr_in($lport // 0, $laddr) || (return $self->error("Cannot resolve local host: $opts->{'local_host'} (port: $opts->{'local_port'}): $!"))
l!l
00
$lport // 0
l!l
00
MC/DC0%0/1
Socket::pack_sockaddr_in($lport // 0, $laddr) || (return $self->error("Cannot resolve local host: $opts->{'local_host'} (port: $opts->{'local_port'}): $!"))
Socket::pack_sockaddr_in($lport // 0, $laddr)
MC/DC0%0/1
$lport // 0
$lport
Truth table0%0/2
A
A= Socket::pack_sockaddr_in($lport // 0, $laddr)
Aresult
11
00
Truth table0%0/2
A
A= $lport
Aresult
11
00
193 return( $self->error( "Cannot resolve local host: $opts->{local_host} (port: $opts->{local_port}): $!" ) );
194 CORE::bind( $sock, $local_sock_addr ) || do
195 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
bind $sock, $local_sock_addr or do { if ($laddr ne "\0\0\0\0") { return $self->error(qq[Unable to bind to local host "$opts->{"local_host"}": $!]); } else { return $self->error(qq[Unable to bind to local port "$opts->{"local_port"}": $!]); } } 0 0 0
196 0 ▶ if( $laddr ne INADDR_ANY )
Branch: 1 branch
BranchTrueFalseTotal
if ($laddr ne "\000\000\000\000") { } 0 0 0
197 {
198 0 return( $self->error( "Unable to bind to local host \"$opts->{local_host}\": $!" ) );
199 }
200 else
201 {
202 0 return( $self->error( "Unable to bind to local port \"$opts->{local_port}\": $!" ) );
203 }
204 };
205 }
206  
207 RETRY:
208 0 ▶ CORE::socket( $sock, Socket::sockaddr_family( $sock_addr ), SOCK_STREAM, 0 ) ||
Branch: 1 branch
BranchTrueFalseTotal
socket $sock, Socket::sockaddr_family($sock_addr), 1, 0 or return $self->error("Unable to create socket: $!") 0 0 0
209 return( $self->error( "Unable to create socket: $!" ) );
210 0 ▶ $self->_set_sockopts( $sock ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_set_sockopts($sock) or return $self->pass_error 0 0 0
211 0 my $params = {};
212 0 ▶ if( $self->_is_array( $INIT_PARAMS ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($HTTP::Promise::IO::INIT_PARAMS)) 0 0 0
213 {
214 0 for( @$INIT_PARAMS )
215 {
216 0 ▶ $params->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{$_} 0 0 0
217 }
218 }
219 0 ▶ my $new = $self->new( $sock, $params ) || return( $self->pass_error );
Condition0%0/2
$self->new($sock, $params) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new($sock, $params) || (return $self->pass_error)
$self->new($sock, $params)
Truth table0%0/2
A
A= $self->new($sock, $params)
Aresult
11
00
220 0 ▶ if( CORE::connect( $sock, $sock_addr ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::connect $sock, $sock_addr) { } 0 0 0
elsif ($! == 115 or $HTTP::Promise::IO::IS_WIN32 and $! == 11) { } 0 0 0
221 {
222 # connected
223 }
224 ▶ elsif( $! == EINPROGRESS || ( $IS_WIN32 && $! == EWOULDBLOCK ) )
Condition0%0/6
$! == 115 or $HTTP::Promise::IO::IS_WIN32 and $! == 11
l!l&&r!l&&!r
000
$HTTP::Promise::IO::IS_WIN32 and $! == 11
!ll&&!rl&&r
000
MC/DC0%0/3
$! == 115 or $HTTP::Promise::IO::IS_WIN32 and $! == 11
$! == 115 $HTTP::Promise::IO::IS_WIN32 $! == 11
Truth table0%0/4
A or B and C
A= $! == 115B= $HTTP::Promise::IO::IS_WIN32C= $! == 11
ABCresult
1XX1
0111
00X0
0100
225 {
226 0 my $rv = $new->make_select_timeout( write => 1, timeout => $opts->{timeout} );
227 0 ▶ return( $self->error( "Cannot connect to ${host}:${port}: ", $new->error->message ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
228 0 ▶ return( $self->error( "Select timeout on socket." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
229 }
230 # connected
231 else
232 {
233 0 ▶ if( $! == EINTR && !$stop_if->() )
Branch: 1 branch
BranchTrueFalseTotal
if ($! == 4 and not &$stop_if()) 0 0 0
Condition0%0/3
$! == 4 and not &$stop_if()
!ll&&!rl&&r
000
MC/DC0%0/2
$! == 4 and not &$stop_if()
$! == 4 not &$stop_if()
Truth table0%0/3
A and not(B)
A= $! == 4B= not &$stop_if()
ABresult
0X0
100
111
234 {
235 0 CORE::close( $sock );
236 0 goto( RETRY );
237 }
238 0 return( $self->error( "Cannot connect to ${host}:${port}: $!" ) );
239 }
240 0 return( $new );
241 }
242  
243 # connect SSL socket.
244 # You can override this method in your child class, if you want to use Crypt::SSLeay or some other library.
245 # Returns file handle like object
246 sub connect_ssl
247 0 ▶{
Subroutine connect_ssl: not called CC=16 SCAR=56.1
Pod documented
248 0 my $self = shift( @_ );
249 0 my $opts = $self->_get_args_as_hash( @_ );
250 0 ▶ my $host = $opts->{host} || return( $self->error( "No host to connect to was provided." ) );
Condition0%0/2
$opts->{'host'} || (return $self->error('No host to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'host'} || (return $self->error('No host to connect to was provided.'))
$opts->{'host'}
Truth table0%0/2
A
A= $opts->{'host'}
Aresult
11
00
251 0 ▶ my $port = $opts->{port} || return( $self->error( "No port to connect to was provided." ) );
Condition0%0/2
$opts->{'port'} || (return $self->error('No port to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'port'} || (return $self->error('No port to connect to was provided.'))
$opts->{'port'}
Truth table0%0/2
A
A= $opts->{'port'}
Aresult
11
00
252 0 ▶ return( $self->error( "Port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $port =~ /^\d+$/ 0 0 0
253 0 ▶ return( $self->error( "No timeout was provided to connect." ) ) if( !exists( $opts->{timeout} ) || !length( $opts->{timeout} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"timeout"} and length $opts->{"timeout"} 0 0 0
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"timeout"} and length $opts->{"timeout"}
exists $opts->{"timeout"} length $opts->{"timeout"}
Truth table0%0/3
A and B
A= exists $opts->{"timeout"}B= length $opts->{"timeout"}
ABresult
0X0
100
111
254
255 0 ▶ $self->_load_class( 'IO::Socket::SSL' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("IO::Socket::SSL") or return $self->pass_error 0 0 0
256  
257 0 my $params = {};
258 0 ▶ if( $self->_is_array( $INIT_PARAMS ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($HTTP::Promise::IO::INIT_PARAMS)) 0 0 0
259 {
260 0 for( @$INIT_PARAMS )
261 {
262 0 ▶ $params->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{$_} 0 0 0
263 }
264 }
265 0 $params->{host} = $host;
266 0 $params->{port} = $port;
267 0 ▶ my $new = $self->connect( %$params ) ||
Condition0%0/2
$self->connect(%$params) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->connect(%$params) || (return $self->pass_error)
$self->connect(%$params)
Truth table0%0/2
A
A= $self->connect(%$params)
Aresult
11
00
268 return( $self->pass_error );
269 0 my $sock = $new->filehandle;
270  
271 0 ▶ my $timeout = $opts->{timeout} // $self->timeout // 5;
Condition0%0/5
($opts->{"timeout"} // $self->timeout) // 5
l!l
00
$opts->{"timeout"} // $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
($opts->{"timeout"} // $self->timeout) // 5
$opts->{"timeout"} $self->timeout
Truth table0%0/3
A // B
A= $opts->{"timeout"}B= $self->timeout
ABresult
1X1
011
000
272 # my $timeout = ( $opts->{timeout} - time() );
273 # return( $self->error( "Cannot create SSL connection: timeout" ) ) if( $timeout <= 0 );
274  
275 0 my $ssl_opts = $new->_ssl_opts;
276 0 ▶ if( !IO::Socket::SSL->start_SSL(
Branch: 3 branches
BranchTrueFalseTotal
unless ("IO::Socket::SSL"->start_SSL($sock, "PeerHost", $host, "PeerPort", $port, "Timeout", $timeout, defined $opts->{"local_host"} ? ("LocalHost", $opts->{"local_host"}) : (), defined $opts->{"local_port"} ? ("LocalPort", $opts->{"local_port"}) : (), %$ssl_opts)) 0 0 0
defined $opts->{'local_host'} ? : 0 0 0
defined $opts->{'local_port'} ? : 0 0 0
277 $sock,
278 PeerHost => $host,
279 PeerPort => $port,
280 Timeout => $timeout,
281 ( defined( $opts->{local_host} ) ? ( LocalHost => $opts->{local_host} ) : () ),
282 ( defined( $opts->{local_port} ) ? ( LocalPort => $opts->{local_port} ) : () ),
283 %$ssl_opts,
284 ) )
285 {
286 0 return( $self->error( "Cannot create SSL connection: ", IO::Socket::SSL::errstr() ) );
287 }
288 0 $new->_set_sockopts( $sock );
289 0 return( $new );
290 }
291  
292 sub connect_ssl_over_proxy
293 0 ▶{
Subroutine connect_ssl_over_proxy: not called CC=27 SCAR=66.3
Pod documented
294 0 my $self = shift( @_ );
295 0 my $opts = $self->_get_args_as_hash( @_ );
296 0 ▶ my $proxy_host = $opts->{proxy_host} || return( $self->error( "No proxy host to connect to was provided." ) );
Condition0%0/2
$opts->{'proxy_host'} || (return $self->error('No proxy host to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'proxy_host'} || (return $self->error('No proxy host to connect to was provided.'))
$opts->{'proxy_host'}
Truth table0%0/2
A
A= $opts->{'proxy_host'}
Aresult
11
00
297 0 ▶ my $proxy_port = $opts->{proxy_port} || return( $self->error( "No proxy port to connect to was provided." ) );
Condition0%0/2
$opts->{'proxy_port'} || (return $self->error('No proxy port to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'proxy_port'} || (return $self->error('No proxy port to connect to was provided.'))
$opts->{'proxy_port'}
Truth table0%0/2
A
A= $opts->{'proxy_port'}
Aresult
11
00
298 0 ▶ my $host = $opts->{host} || return( $self->error( "No host to connect to was provided." ) );
Condition0%0/2
$opts->{'host'} || (return $self->error('No host to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'host'} || (return $self->error('No host to connect to was provided.'))
$opts->{'host'}
Truth table0%0/2
A
A= $opts->{'host'}
Aresult
11
00
299 0 ▶ my $port = $opts->{port} || return( $self->error( "No port to connect to was provided." ) );
Condition0%0/2
$opts->{'port'} || (return $self->error('No port to connect to was provided.'))
l!l
00
MC/DC0%0/1
$opts->{'port'} || (return $self->error('No port to connect to was provided.'))
$opts->{'port'}
Truth table0%0/2
A
A= $opts->{'port'}
Aresult
11
00
300 0 ▶ return( $self->error( "Proxy port provided ($proxy_port) is not a number" ) ) if( $proxy_port !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $proxy_port =~ /^\d+$/ 0 0 0
301 0 ▶ return( $self->error( "Host port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $port =~ /^\d+$/ 0 0 0
302 0 ▶ return( $self->error( "Port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $port =~ /^\d+$/ 0 0 0
303 0 ▶ return( $self->error( "No timeout was provided to connect." ) ) if( !exists( $opts->{timeout} ) || !length( $opts->{timeout} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"timeout"} and length $opts->{"timeout"} 0 0 0
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"timeout"} and length $opts->{"timeout"}
exists $opts->{"timeout"} length $opts->{"timeout"}
Truth table0%0/3
A and B
A= exists $opts->{"timeout"}B= length $opts->{"timeout"}
ABresult
0X0
100
111
304 0 my $proxy_authorization = $opts->{proxy_authorization};
305 0 ▶ $self->_load_class( 'IO::Socket::SSL' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("IO::Socket::SSL") or return $self->pass_error 0 0 0
306  
307 0 my $params = {};
308 0 ▶ if( $self->_is_array( $INIT_PARAMS ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($HTTP::Promise::IO::INIT_PARAMS)) 0 0 0
309 {
310 0 for( @$INIT_PARAMS )
311 {
312 0 ▶ $params->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{$_} 0 0 0
313 }
314 }
315 0 $params->{host} = $proxy_host;
316 0 $params->{port} = $proxy_port;
317 0 ▶ my $new = $self->connect( %$params ) ||
Condition0%0/2
$self->connect(%$params) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->connect(%$params) || (return $self->pass_error)
$self->connect(%$params)
Truth table0%0/2
A
A= $self->connect(%$params)
Aresult
11
00
318 return( $self->pass_error );
319 0 my $sock = $new->filehandle;
320  
321 0 my $p = "CONNECT ${host}:${port} HTTP/1.0${CRLF}Server: ${host}${CRLF}";
322 0 ▶ if( defined( $proxy_authorization ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proxy_authorization) 0 0 0
323 {
324 0 $p .= "Proxy-Authorization: ${proxy_authorization}${CRLF}";
325 }
326 0 $p .= $CRLF;
327 0 ▶ $new->_write_all( $sock, $p, $opts->{timeout} ) ||
Branch: 2 branches
BranchTrueFalseTotal
$new->_write_all($sock, $p, $opts->{"timeout"}) or return $self->error({"code", 500, "message", 'Failed to send HTTP request to proxy: ' . ($! != 0 ? "$!" : "timeout")}) 0 0 0
$! != 0 ? : 0 0 0
328 return( $self->error({
329 code => 500,
330 message => "Failed to send HTTP request to proxy: " . ( $! != 0 ? "$!" : 'timeout' )
331 }) );
332 0 my $buf = '';
333 0 my $read = $new->read( \$buf, $new->buffer_size, length( $buf ), $opts->{timeout} );
334 0 ▶ if( !defined( $read ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $read) { } 0 0 0
elsif ($read == 0) { } 0 0 0
elsif (not $buf =~ m[^HTTP/1\.[0-9] 200 .+\015\012]) { } 0 0 0
335 {
336 0 ▶ return( $self->error( "Cannot read proxy response: " . ( $! != 0 ? "$!" : 'timeout' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
$! != 0 ? : 0 0 0
337 }
338 # eof
339 elsif( $read == 0 )
340 {
341 0 return( $self->error( "Unexpected EOF while reading proxy response" ) );
342 }
343 elsif( $buf !~ /^HTTP\/1\.[0-9] 200 .+\015\012/ )
344 {
345 0 return( $self->error( "Invalid HTTP Response via proxy" ) );
346 }
347  
348 0 my $timeout = ( $opts->{timeout} - time() );
349 0 ▶ return( $self->error( "Cannot start SSL connection: timeout" ) ) if( $opts->{timeout} <= 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"timeout"} <= 0 0 0 0
350  
351 0 my $ssl_opts = $new->_ssl_opts;
352 0 ▶ unless( exists( $ssl_opts->{SSL_verifycn_name} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ssl_opts->{"SSL_verifycn_name"}) 0 0 0
353 {
354 0 $ssl_opts->{SSL_verifycn_name} = $host;
355 }
356 IO::Socket::SSL->start_SSL(
357 $sock,
358 PeerHost => "$host",
359 PeerPort => "$port",
360 Timeout => "$timeout",
361 ( defined( $opts->{local_host} ) ? ( LocalHost => $opts->{local_host} ) : () ),
362 0 ▶ ( defined( $opts->{local_port} ) ? ( LocalPort => $opts->{local_port} ) : () ),
Branch: 3 branches
BranchTrueFalseTotal
"IO::Socket::SSL"->start_SSL($sock, "PeerHost", "$host", "PeerPort", "$port", "Timeout", "$timeout", defined $opts->{"local_host"} ? ("LocalHost", $opts->{"local_host"}) : (), defined $opts->{"local_port"} ? ("LocalPort", $opts->{"local_port"}) : (), %$ssl_opts) or return $self->error('Cannot start SSL connection: ' . IO::Socket::SSL::errstr()) 0 0 0
defined $opts->{'local_host'} ? : 0 0 0
defined $opts->{'local_port'} ? : 0 0 0
363 %$ssl_opts
364 ) or return( $self->error( "Cannot start SSL connection: " . IO::Socket::SSL::errstr() ) );
365 0 $new->_set_sockopts( $sock );
366 0 return( $new );
367 }
368  
369 425 ▶sub filehandle { return( shift->_set_get_glob( '_fh', @_ ) ); }
Subroutine filehandle: called CC=1 SCAR=0.0
Pod documented
370  
371 # Credits: Olaf Alders in Net::HTTP
372 sub getline
373 8 ▶{
Subroutine getline: called CC=21 SCAR=40.4
Pod documented
374 8 my $self = shift( @_ );
375 8 my $opts = $self->_get_args_as_hash( @_ );
376 8 ▶ $opts->{chomp} = 0 if( !CORE::exists( $opts->{chomp} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"chomp"} 8 0 8
377 8 $opts->{max_read_buffer} = 0;
378 8 ▶ my $fh = $self->filehandle || return( $self->error( "No filehandle currently set." ) );
Condition50%1/2
$self->filehandle || (return $self->error('No filehandle currently set.'))
l!l
80
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle currently set.'))
$self->filehandle
Truth table50%1/2
A
A= $self->filehandle
Aresult
11
00
379 8 my $buff = $self->buffer;
380 8 ▶ my $max = $opts->{max_read_buffer} || $self->max_read_buffer;
Condition33%1/3
$opts->{'max_read_buffer'} || $self->max_read_buffer
l!l&&r!l&&!r
080
MC/DC0%0/2
$opts->{'max_read_buffer'} || $self->max_read_buffer
$opts->{'max_read_buffer'} $self->max_read_buffer
Truth table33%1/3
A || B
A= $opts->{'max_read_buffer'}B= $self->max_read_buffer
ABresult
1X1
011
000
381 8 my $pos;
382 8 ▶ my $is_object = $self->_can( $fh => 'sysread' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_can($fh, 'sysread') ? : 8 0 8
383 8 while(1)
384 {
385 # Get the position of line ending. \015 might not be there, but \012 will
386 16 $pos = $buff->index( "\012" );
387 16 ▶ last if( $pos >= 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= 0 8 8 16
388 # 413 Entity too large
389 8 ▶ return( $self->error({ code => 413, message => "Line too long (limit is $max)" }) ) if( $max && $buff->length > $max );
Branch: 1 branch
BranchTrueFalseTotal
if $max and $buff->length > $max 0 8 8
Condition33%1/3
$max and $buff->length > $max
!ll&&!rl&&r
080
MC/DC0%0/2
$max and $buff->length > $max
$max $buff->length > $max
Truth table33%1/3
A and B
A= $maxB= $buff->length > $max
ABresult
0X0
100
111
390 # need to read more data to find a line ending
391 8 my $new_bytes = 0;
392 READ:
393 {
394 8 my $rv = $self->can_read;
395 8 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 8 8
396 8 ▶ return( $self->error( "Cannot read from filehandle '$fh'" ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 8 8
397 # consume all incoming bytes
398 8 ▶ my $bytes_read = $is_object
Branch: 1 branch
BranchTrueFalseTotal
$is_object ? : 8 0 8
399 ? $fh->sysread( $$buff, 1024, $buff->length )
400 : sysread( $fh, $$buff, 1024, $buff->length );
401 8 ▶ if( defined( $bytes_read ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $bytes_read) { } 8 0 8
elsif ($!{'EINTR'} or $!{'EAGAIN'} or $!{'EWOULDBLOCK'}) { } 0 0 0
402 {
403 8 $new_bytes += $bytes_read;
404 }
405 ▶ elsif( $!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK} )
Condition0%0/6
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
$!{"EINTR"} or $!{"EAGAIN"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"} $!{"EAGAIN"} $!{"EWOULDBLOCK"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EAGAIN"}C= $!{"EWOULDBLOCK"}
ABCresult
1XX1
01X1
0011
0000
406 {
407 0 redo READ;
408 }
409 else
410 {
411 0 $self->mesage( 4, "$bytes_read bytes read from filehandle '$fh' with total read so far of ", $buff->length );
412 # if we have already accumulated some data let's at
413 # least return that as a line
414 0 ▶ $buff->length or return( $self->error( "read() failed: $!" ) );
Branch: 1 branch
BranchTrueFalseTotal
$buff->length or return $self->error("read() failed: $!") 0 0 0
415 }
416 # no line-ending, no new bytes
417 return(
418 8 ▶ $buff->length
Branch: 2 branches
BranchTrueFalseTotal
if $new_bytes == 0 0 8 8
$buff->length ? : 0 0 0
419 ? $buff->substr( 0, $buff->length, '' )
420 # : undef
421 : ''
422 ) if( $new_bytes == 0 );
423 };
424 }
425 8 ▶ return( $self->error( "Line too long ($pos; limit is $max)" ) ) if( $max && $pos > $max );
Branch: 1 branch
BranchTrueFalseTotal
if $max and $pos > $max 0 8 8
Condition33%1/3
$max and $pos > $max
!ll&&!rl&&r
080
MC/DC0%0/2
$max and $pos > $max
$max $pos > $max
Truth table33%1/3
A and B
A= $maxB= $pos > $max
ABresult
0X0
100
111
426 8 my $line = $buff->substr( 0, $pos + 1, '' );
427 # $line =~ s/(\015?\012)\z// || return( $self->error( 'No end-of-line found' ) );
428 # return( wantarray() ? ($line, $1) : $line;
429 8 ▶ $$line =~ s/(\015?\012)\z// if( $opts->{chomp} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"chomp"} 0 8 8
430 8 return( $$line );
431 }
432  
433 0 ▶sub inactivity_timeout { return( shift->_set_get_number_as_scalar( 'inactivity_timeout', @_ ) ); }
Subroutine inactivity_timeout: not called CC=1 SCAR=6.9
Pod documented
434  
435 72 ▶sub last_delimiter { return( shift->_set_get_scalar_as_object( 'last_delimiter', @_ ) ); }
Subroutine last_delimiter: called CC=1 SCAR=0.0
Pod documented
436  
437 sub make_select
438 0 ▶{
Subroutine make_select: not called CC=8 SCAR=42.8
Pod documented
439 0 my $self = shift( @_ );
440 0 my $opts = $self->_get_args_as_hash( @_ );
441 0 ▶ my $fh = $self->filehandle || return( $self->error( "No filehandle set to read from." ) );
Condition0%0/2
$self->filehandle || (return $self->error('No filehandle set to read from.'))
l!l
00
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle set to read from.'))
$self->filehandle
Truth table0%0/2
A
A= $self->filehandle
Aresult
11
00
442 0 ▶ my $timeout = $opts->{timeout} // $self->timeout;
Condition0%0/3
$opts->{"timeout"} // $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"timeout"} // $self->timeout
$opts->{"timeout"} $self->timeout
Truth table0%0/3
A // B
A= $opts->{"timeout"}B= $self->timeout
ABresult
1X1
011
000
443 0 ▶ return( $self->error( 'No timeout was provided.' ) ) if( !defined( $timeout ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 0 0 0
444 0 ▶ my $is_write = $opts->{write} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'write'} ? : 0 0 0
445 0 my( $rfd, $wfd );
446 0 my $efd = '';
447 0 vec( $efd, fileno( $fh ), 1 ) = 1;
448 0 ▶ if( $is_write )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_write) { } 0 0 0
449 {
450 0 $wfd = $efd;
451 }
452 else
453 {
454 0 $rfd = $efd;
455 }
456 0 my $nfound = select( $rfd, $wfd, $efd, $timeout );
457 0 ▶ return( $self->error( $! ) ) if( $nfound < 0 && $! );
Branch: 1 branch
BranchTrueFalseTotal
if $nfound < 0 and $! 0 0 0
Condition0%0/3
$nfound < 0 and $!
!ll&&!rl&&r
000
MC/DC0%0/2
$nfound < 0 and $!
$nfound < 0 $!
Truth table0%0/3
A and B
A= $nfound < 0B= $!
ABresult
0X0
100
111
458 0 return( $nfound );
459 }
460  
461 # returns true if the socket is ready to read, false if timeout has occurred ($! will be cleared upon timeout)
462 sub make_select_timeout
463 0 ▶{
Subroutine make_select_timeout: not called CC=17 SCAR=57.2
Pod documented
464 0 my $self = shift( @_ );
465 0 my $opts = $self->_get_args_as_hash( @_ );
466 0 ▶ my $is_write = $opts->{write} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'write'} ? : 0 0 0
467 0 ▶ my $fh = $self->filehandle || return( $self->error( "No filehandle currently set." ) );
Condition0%0/2
$self->filehandle || (return $self->error('No filehandle currently set.'))
l!l
00
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle currently set.'))
$self->filehandle
Truth table0%0/2
A
A= $self->filehandle
Aresult
11
00
468 0 my $timeout;
469 0 ▶ $timeout = $opts->{timeout} if( exists( $opts->{timeout} ) && length( $opts->{timeout} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"timeout"} and length $opts->{"timeout"} 0 0 0
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opts->{"timeout"} and length $opts->{"timeout"}
exists $opts->{"timeout"} length $opts->{"timeout"}
Truth table0%0/3
A and B
A= exists $opts->{"timeout"}B= length $opts->{"timeout"}
ABresult
0X0
100
111
470 0 ▶ $timeout //= $self->timeout;
Condition0%0/3
$timeout //= $self->timeout
l!l&&r!l&&!r
000
MC/DC0%0/2
$timeout //= $self->timeout
$timeout $self->timeout
Truth table0%0/3
A //= B
A= $timeoutB= $self->timeout
ABresult
1X1
011
000
471 0 my $timeout_at = time() + $timeout;
472 0 ▶ return( $self->error( "No timeout option was provided nor is it defined with timeout()." ) ) if( !defined( $timeout ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 0 0 0
473 # Time::HiRes time()
474 0 my $now = time();
475 0 ▶ my $inactivity_timeout = $self->inactivity_timeout // $opts->{inactivity_timeout} // 600;
Condition0%0/5
($self->inactivity_timeout // $opts->{"inactivity_timeout"}) // 600
l!l
00
$self->inactivity_timeout // $opts->{"inactivity_timeout"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($self->inactivity_timeout // $opts->{"inactivity_timeout"}) // 600
$self->inactivity_timeout $opts->{"inactivity_timeout"}
Truth table0%0/3
A // B
A= $self->inactivity_timeoutB= $opts->{"inactivity_timeout"}
ABresult
1X1
011
000
476 0 my $inactivity_timeout_at = ( $now + $inactivity_timeout );
477 0 ▶ $self->message( 4, "Setting timeout_at to $inactivity_timeout_at (${inactivity_timeout_at} [", scalar( localtime( $inactivity_timeout_at ) ), "]) ? ", ( $timeout_at > $inactivity_timeout_at ? 'yes' : 'no' ) );
Branch: 1 branch
BranchTrueFalseTotal
$timeout_at > $inactivity_timeout_at ? : 0 0 0
478 0 ▶ $timeout_at = $inactivity_timeout_at if( $timeout_at > $inactivity_timeout_at );
Branch: 1 branch
BranchTrueFalseTotal
if $timeout_at > $inactivity_timeout_at 0 0 0
479 0 my $stop_if = $self->stop_if;
480 # wait for data
481 0 while(1)
482 {
483 0 my $timeout2 = ( $timeout_at - $now );
484 0 ▶ if( $timeout2 <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout2 <= 0) 0 0 0
485 {
486 0 $! = 0;
487 0 return(0);
488 }
489 0 my $nfound = $self->make_select( write => $is_write, timeout => $timeout2 );
490 0 ▶ return( $self->pass_error ) if( !defined( $nfound ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nfound 0 0 0
491 0 ▶ return(1) if( $nfound > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $nfound > 0 0 0 0
492 0 ▶ return(0) if( $nfound == -1 && $! == EINTR && $stop_if->() );
Branch: 1 branch
BranchTrueFalseTotal
if $nfound == -1 and $! == 4 and &$stop_if() 0 0 0
Condition0%0/6
$nfound == -1 and $! == 4 and &$stop_if()
!ll&&!rl&&r
000
$nfound == -1 and $! == 4
!ll&&!rl&&r
000
MC/DC0%0/3
$nfound == -1 and $! == 4 and &$stop_if()
$nfound == -1 $! == 4 &$stop_if()
Truth table0%0/4
A and B and C
A= $nfound == -1B= $! == 4C= &$stop_if()
ABCresult
0XX0
10X0
1100
1111
493 # Time::HiRes time()
494 0 $now = time();
495 }
496 0 return( $self->error( 'Error checking for readiness of socket. Should not get here.' ) );
497 }
498  
499 # Maximum size of read buffer, beyond which, if still nothing is found, then we give up
500 52 ▶sub max_read_buffer { return( shift->_set_get_number_as_scalar( 'max_read_buffer', @_ ) ); }
Subroutine max_read_buffer: called CC=1 SCAR=0.0
Pod documented
501  
502 110 ▶sub print { return( defined( shift->write( @_ ) ) ? 1 : 0 ); }
Subroutine print: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined((shift())->write(@_)) ? : 110 0 110
503  
504 sub read
505 48 ▶{
Subroutine read: called CC=22 SCAR=43.6
Pod documented
506 48 my $self = $_[0];
507 48 ▶ return( $self->error({ code => 500, message => "Wrong number of arguments. Usage: \$reader->read( \$buffer, \$length, \$offset )" }) ) unless( @_ > 2 && @_ < 5 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 2 and @_ < 5 0 48 48
Condition33%1/3
@_ > 2 and @_ < 5
!ll&&!rl&&r
0048
MC/DC0%0/2
@_ > 2 and @_ < 5
@_ > 2 @_ < 5
Truth table33%1/3
A and B
A= @_ > 2B= @_ < 5
ABresult
0X0
100
111
508 48 my $len = $_[2];
509 48 ▶ return( $self->error( "Length provided (${len}) is not a positive integer." ) ) if( !defined( $len ) || $len !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len and $len =~ /^\d+$/ 0 48 48
Condition33%1/3
defined $len and $len =~ /^\d+$/
!ll&&!rl&&r
0048
MC/DC0%0/2
defined $len and $len =~ /^\d+$/
defined $len $len =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $lenB= $len =~ /^\d+$/
ABresult
0X0
100
111
510 48 my $off = $_[3];
511 48 ▶ return( $self->error( "Offset provided (${off}) is not an integer." ) ) if( defined( $off ) && $off !~ /^-?\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $off and not $off =~ /^-?\d+$/ 0 48 48
Condition66%2/3
defined $off and not $off =~ /^-?\d+$/
!ll&&!rl&&r
37110
MC/DC0%0/2
defined $off and not $off =~ /^-?\d+$/
defined $off not $off =~ /^-?\d+$/
Truth table66%2/3
A and not(B)
A= defined $offB= not $off =~ /^-?\d+$/
ABresult
0X0
100
111
512 48 ▶ my $is_scalar = $self->_is_scalar( $_[1] ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_scalar($_[1]) ? : 0 48 48
513 48 ▶ return( $self->error( "scalar provided as first argument to read() is a reference (", overload::StrVal( $_[1] ), "). You need to first dereference it." ) ) if( ref( $_[1] ) && !$is_scalar );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] and not $is_scalar 0 48 48
Condition33%1/3
ref $_[1] and not $is_scalar
!ll&&!rl&&r
4800
MC/DC0%0/2
ref $_[1] and not $is_scalar
ref $_[1] not $is_scalar
Truth table33%1/3
A and not(B)
A= ref $_[1]B= not $is_scalar
ABresult
0X0
100
111
514 48 ▶ $off //= 0;
Condition100%2/2
$off //= 0
l!l
1137
MC/DC100%1/1
$off //= 0
$off
Truth table100%2/2
A
A= $off
Aresult
11
00
515 48 ▶ my $fh = $self->filehandle || return( $self->error( "No filehandle set to read from." ) );
Condition50%1/2
$self->filehandle || (return $self->error('No filehandle set to read from.'))
l!l
480
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle set to read from.'))
$self->filehandle
Truth table50%1/2
A
A= $self->filehandle
Aresult
11
00
516 48 my $buff = $self->buffer;
517 48 my $buff_len = $buff->length->scalar;
518 48 ▶ my $is_object = $self->_can( $fh => 'sysread' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_can($fh, 'sysread') ? : 48 0 48
519 48 my $stop_if = $self->stop_if;
520
521 my $sysread = sub
522 14 ▶ {
Subroutine __ANON__: called CC=13 SCAR=46.4
523 14 while(1)
524 {
525 14 ▶ my $n = $is_object
Branch: 3 branches
BranchTrueFalseTotal
$is_object ? : 14 0 14
@_ > 2 ? : 14 0 14
@_ > 2 ? : 0 0 0
526 ? $fh->sysread( $_[0], $_[1], ( @_ > 2 ? $_[2] : () ) )
527 : sysread( $fh, $_[0], $_[1], ( @_ > 2 ? $_[2] : () ) );
528 14 ▶ if( defined( $n ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 14 0 14
529 {
530 14 return( $n );
531 }
532
533 0 ▶ if( $! == EAGAIN || $! == EWOULDBLOCK || ( $IS_WIN32 && $! == EISCONN ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106) { } 0 0 0
elsif ($! == 4) { } 0 0 0
Condition0%0/9
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
l!l&&r!l&&!r
000
$! == 11 or $! == 11
l!l&&r!l&&!r
000
$HTTP::Promise::IO::IS_WIN32 and $! == 106
!ll&&!rl&&r
000
MC/DC0%0/4
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
$! == 11 $! == 11 $HTTP::Promise::IO::IS_WIN32 $! == 106
Truth table0%0/5
A or B or C and D
A= $! == 11B= $! == 11C= $HTTP::Promise::IO::IS_WIN32D= $! == 106
ABCDresult
1XXX1
01XX1
00111
000X0
00100
534 {
535 # passthru
536 }
537 elsif( $! == EINTR )
538 {
539 0 ▶ return( $self->error({ code => $!+0, message => "Received interruption signal: $!" }) ) if( $stop_if->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$stop_if() 0 0 0
540 # otherwise passthru
541 }
542 else
543 {
544 0 return( $self->error({ code => $!+0, message => "Unable to read from filehandle: $!" }) );
545 }
546 # on EINTER/EAGAIN/EWOULDBLOCK
547 0 my $rv = $self->make_select_timeout( write => 0 );
548 0 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
549 0 ▶ return( $self->error( "Timeout. Unable to select the filehandle." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
550 }
551 48 };
552
553 48 ▶ if( $buff_len )
Branch: 1 branch
BranchTrueFalseTotal
if ($buff_len) { } 42 6 48
554 {
555 # if our buffer is less than that is required, attempt to read the difference from the filehandle
556 42 ▶ if( $buff_len < $len )
Branch: 1 branch
BranchTrueFalseTotal
if ($buff_len < $len) 8 34 42
557 {
558 8 ▶ return( $self->pass_error ) unless( defined( $self->can_read ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->can_read 0 8 8
559 8 my $n = $sysread->( $$buff, ( $len - $buff_len ), $buff_len );
560 8 ▶ return( $self->pass_error ) if( !defined( $n ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 8 8
561 }
562
563 # What we will return
564 42 ▶ my $bytes = ( $buff->length > $len ? $len : $buff->length );
Branch: 1 branch
BranchTrueFalseTotal
$buff->length > $len ? : 1 41 42
565 # "A positive OFFSET greater than the length of SCALAR results in the string being
566 # padded to the required size with "\0" bytes before the result of the read is
567 # appended."
568 # (perlfunc)
569 42 ▶ if( $is_scalar )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_scalar) { } 0 42 42
570 {
571 0 ▶ if( $off > length( $$_[1] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($off > length $_->[1]) 0 0 0
572 {
573 0 $$_[1] .= \0 x ( $off - length( $$_[1] ) );
574 }
575 0 substr( $$_[1], $off, 0, $buff->substr( 0, $bytes, '' )->scalar );
576 # Truncate
577 0 substr( $$_[1], ( $off + $bytes ), length( $$_[1] ), '' );
578 }
579 else
580 {
581 42 ▶ if( $off > length( $_[1] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($off > length $_[1]) 0 42 42
582 {
583 0 $_[1] .= \0 x ( $off - length( $_[1] ) );
584 }
585 42 substr( $_[1], $off, 0, $buff->substr( 0, $bytes, '' )->scalar );
586 # Truncate
587 42 substr( $_[1], ( $off + $bytes ), length( $_[1] ), '' );
588 }
589 42 return( $bytes );
590 }
591 else
592 {
593 6 ▶ return( $sysread->( $_[1], $len, ( defined( $off ) ? $off : () ) ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $off ? : 6 0 6
594 }
595 }
596  
597 sub read_until
598 129 ▶{
Subroutine read_until: called CC=42 SCAR=49.4
Pod documented
599 129 my $self = $_[0];
600 129 ▶ return( $self->error({ code => 500, message => "Wrong number of arguments. Usage: \$reader->read_until( \$buffer, \$length, \$offset, { string => 'something', exclude => 1, include => 1, chunk_size => 2048 } )" }) ) unless( @_ > 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 2 0 129 129
601 129 my $len = $_[2];
602 129 ▶ return( $self->error( "Length provided (${len}) is not an integer." ) ) if( $len !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $len =~ /^\d+$/ 0 129 129
603 129 ▶ return( $self->error( "scalar provided as first argument to read_until() is a reference (", overload::StrVal( $_[1] ), "). You need to first dereference it." ) ) if( ref( $_[1] ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] 0 129 129
604 129 ▶ my $off = ( $_[3] =~ /^\-?\d+$/ ? $_[3] : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$_[3] =~ /^\-?\d+$/ ? : 0 129 129
605 129 my $opts = {};
606 129 ▶ $opts = $_[-1] if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 129 0 129
607 129 my $what = $opts->{string};
608 129 ▶ return( $self->error({ code => 500, message => "Nothing was provided to look for." }) ) if( !defined( $what ) || !CORE::length( $what ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what and length $what 0 129 129
Condition33%1/3
defined $what and length $what
!ll&&!rl&&r
00129
MC/DC0%0/2
defined $what and length $what
defined $what length $what
Truth table33%1/3
A and B
A= defined $whatB= length $what
ABresult
0X0
100
111
609 129 ▶ $what = qr/\Q${what}\E/ unless( ref( $what ) eq 'Regexp' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $what eq "Regexp" 0 129 129
610 129 ▶ my $fh = $self->filehandle || return( $self->error( "No filehandle set to read from." ) );
Condition50%1/2
$self->filehandle || (return $self->error('No filehandle set to read from.'))
l!l
1290
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle set to read from.'))
$self->filehandle
Truth table50%1/2
A
A= $self->filehandle
Aresult
11
00
611 129 ▶ $opts->{ignore} //= 0;
Condition50%1/2
$opts->{"ignore"} //= 0
l!l
1290
MC/DC0%0/1
$opts->{"ignore"} //= 0
$opts->{"ignore"}
Truth table50%1/2
A
A= $opts->{"ignore"}
Aresult
11
00
612 129 ▶ $opts->{exclude} = 0 if( !exists( $opts->{exclude} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"exclude"} 129 0 129
613 129 ▶ $opts->{inlude} = !$opts->{exclude} if( !exists( $opts->{include} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"include"} 129 0 129
614 # Should we capture the delimiter?
615 # This is useful for debugging, or in case of boundary for HTTP message multipart to know
616 # if we have reached the trailing delimiter for example.
617 129 ▶ $opts->{capture} //= 0;
Condition100%2/2
$opts->{"capture"} //= 0
l!l
13116
MC/DC100%1/1
$opts->{"capture"} //= 0
$opts->{"capture"}
Truth table100%2/2
A
A= $opts->{"capture"}
Aresult
11
00
618 129 my $re;
619 129 ▶ if( $opts->{ignore} )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'ignore'}) { } 129 0 129
elsif ($opts->{'include'}) { } 0 0 0
620 {
621 129 ▶ $re = $opts->{capture} ? qr/(.*?)(?<__reader_delimiter>${what})/s : qr/(.*?)${what}/s;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'capture'} ? : 13 116 129
622 }
623 elsif( $opts->{include} )
624 {
625 0 ▶ $re = $opts->{capture} ? qr/((?:.*?)(?<__reader_delimiter>${what}))/s : qr/((?:.*?)${what})/s;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'capture'} ? : 0 0 0
626 }
627 else
628 {
629 0 $re = qr/(.*?)(?=${what})/s;
630 }
631 129 ▶ my $chunk_size = $opts->{chunk_size} // 2048;
Condition50%1/2
$opts->{"chunk_size"} // 2048
l!l
0129
MC/DC0%0/1
$opts->{"chunk_size"} // 2048
$opts->{"chunk_size"}
Truth table50%1/2
A
A= $opts->{"chunk_size"}
Aresult
11
00
632 129 ▶ $chunk_size = $len if( $len > $chunk_size );
Branch: 1 branch
BranchTrueFalseTotal
if $len > $chunk_size 0 129 129
633 129 my $buff = $self->buffer;
634 129 my $n = -1;
635 129 my $sliding_buffer_size = $chunk_size * 2;
636 129 ▶ my $is_object = $self->_can( $fh => 'sysread' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_can($fh, 'sysread') ? : 129 0 129
637 129 my $buff_len = $buff->length->scalar;
638 129 my $stop_if = $self->stop_if;
639 129 ▶ if( !$buff_len || $$buff !~ /$re/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($buff_len and $$buff =~ /$re/) 114 15 129
Condition100%3/3
$buff_len and $$buff =~ /$re/
!ll&&!rl&&r
111315
MC/DC100%2/2
$buff_len and $$buff =~ /$re/
$buff_len $$buff =~ /$re/
Truth table100%3/3
A and B
A= $buff_lenB= $$buff =~ /$re/
ABresult
0X0
100
111
640 {
641 114 ▶ if( $buff_len < $sliding_buffer_size )
Branch: 1 branch
BranchTrueFalseTotal
if ($buff_len < $sliding_buffer_size) 114 0 114
642 {
643 114 ▶ return( $self->pass_error ) unless( defined( $self->can_read ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->can_read 0 114 114
644 114 while(1)
645 {
646 114 ▶ my $n = $is_object
Branch: 1 branch
BranchTrueFalseTotal
$is_object ? : 114 0 114
647 ? $fh->sysread( $$buff, ( $sliding_buffer_size - $buff_len ), $buff_len )
648 : sysread( $fh, $$buff, ( $sliding_buffer_size - $buff_len ), $buff_len );
649 114 ▶ if( !defined( $n ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $n) { } 0 114 114
elsif (not $n and $buff->is_empty) { } 1 113 114
650 {
651 0 ▶ if( $! == EAGAIN || $! == EWOULDBLOCK || ( $IS_WIN32 && $! == EISCONN ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106) { } 0 0 0
elsif ($! == 4) { } 0 0 0
Condition0%0/9
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
l!l&&r!l&&!r
000
$! == 11 or $! == 11
l!l&&r!l&&!r
000
$HTTP::Promise::IO::IS_WIN32 and $! == 106
!ll&&!rl&&r
000
MC/DC0%0/4
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
$! == 11 $! == 11 $HTTP::Promise::IO::IS_WIN32 $! == 106
Truth table0%0/5
A or B or C and D
A= $! == 11B= $! == 11C= $HTTP::Promise::IO::IS_WIN32D= $! == 106
ABCDresult
1XXX1
01XX1
00111
000X0
00100
652 {
653 # passthru
654 }
655 elsif( $! == EINTR )
656 {
657 0 ▶ return( $self->error({ code => $!+0, message => "Received interruption signal: $!" }) ) if( $stop_if->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$stop_if() 0 0 0
658 # otherwise passthru
659 }
660 else
661 {
662 0 return( $self->error({ code => $!+0, message => "Unable to read from filehandle: $!" }) );
663 }
664 # on EINTER/EAGAIN/EWOULDBLOCK
665 0 my $rv = $self->make_select_timeout( write => 0 );
666 0 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
667 0 ▶ return( $self->error( "Unable to select the filehandle." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
668 }
669 # 0, meaning there is no more data to read
670 # If our buffer still has some data, we'll return whatever we have left
671 ▶ elsif( !$n && $buff->is_empty )
Condition66%2/3
not $n and $buff->is_empty
!ll&&!rl&&r
11301
MC/DC50%1/2
not $n and $buff->is_empty
not $n $buff->is_empty
Truth table66%2/3
not(A) and B
A= not $nB= $buff->is_empty
ABresult
0X0
100
111
672 {
673 1 return( $n );
674 }
675 else
676 {
677 113 last;
678 }
679 }
680 }
681 }
682
683 128 ▶ $_[1] //= '';
Condition100%2/2
$_[1] //= ""
l!l
1271
MC/DC100%1/1
$_[1] //= ""
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
684 # "A positive OFFSET greater than the length of SCALAR results in the string being
685 # padded to the required size with "\0" bytes before the result of the read is
686 # appended."
687 # (perlfunc)
688 128 ▶ if( $off > length( $_[1] ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($off > length $_[1]) 0 128 128
689 {
690 0 $_[1] .= \0 x ( $off - length( $_[1] ) );
691 }
692
693 128 ▶ if( $$buff =~ s/^$re// )
Branch: 1 branch
BranchTrueFalseTotal
if ($$buff =~ s/^$re//) { } 18 110 128
694 {
695 18 my $trail = $1;
696 18 ▶ if( exists( $+{__reader_delimiter} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $+{'__reader_delimiter'}) { } 13 5 18
697 {
698 13 $self->last_delimiter( $+{__reader_delimiter} );
699 }
700 else
701 {
702 5 $self->last_delimiter->reset;
703 }
704 18 my $bytes = length( $trail );
705 18 substr( $_[1], $off, 0, $trail );
706 # Truncate
707 18 substr( $_[1], ( $off + $bytes ), length( $_[1] ), '' );
708 # < 0 means in our API there is a match and this is what was returned.
709 # The caller can simply use abs() to get the bytes value.
710 # 0 means no more data, and
711 # undef means there is an error
712 # > 0 is returned when no match was found, but only data
713 18 return( $bytes * -1 );
714 }
715 else
716 {
717 110 ▶ my $bytes = $buff->length > $len ? $len : $buff->length;
Branch: 1 branch
BranchTrueFalseTotal
$buff->length > $len ? : 110 0 110
718 110 substr( $_[1], $off, 0, $buff->substr( 0, $bytes, '' ) );
719 # Truncate
720 110 substr( $_[1], ( $off + $bytes ), length( $_[1] ), '' );
721 110 return( $bytes );
722 }
723 }
724  
725 sub read_until_in_memory
726 36 ▶{
Subroutine read_until_in_memory: called CC=22 SCAR=33.9
Pod documented
727 36 my $self = shift( @_ );
728 36 my $what = shift( @_ );
729 36 my $opts = $self->_get_args_as_hash( @_ );
730 36 ▶ return( $self->error({ code => 500, message => "Nothing was provided to look for." }) ) if( !defined( $what ) || !CORE::length( $what ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what and length $what 0 36 36
Condition33%1/3
defined $what and length $what
!ll&&!rl&&r
0036
MC/DC0%0/2
defined $what and length $what
defined $what length $what
Truth table33%1/3
A and B
A= defined $whatB= length $what
ABresult
0X0
100
111
731 36 ▶ $what = qr/\Q${what}\E/ unless( ref( $what ) eq 'Regexp' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $what eq "Regexp" 0 36 36
732 36 ▶ $opts->{ignore} //= 0;
Condition50%1/2
$opts->{"ignore"} //= 0
l!l
036
MC/DC0%0/1
$opts->{"ignore"} //= 0
$opts->{"ignore"}
Truth table50%1/2
A
A= $opts->{"ignore"}
Aresult
11
00
733 36 ▶ $opts->{exclude} = 0 if( !exists( $opts->{exclude} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"exclude"} 35 1 36
734 36 ▶ $opts->{inlude} = !$opts->{exclude} if( !exists( $opts->{include} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"include"} 1 35 36
735 # Should we capture the delimiter?
736 # This is useful for debugging, or in case of boundary for HTTP message multipart to know
737 # if we have reached the trailing delimiter for example.
738 36 ▶ $opts->{capture} //= 0;
Condition100%2/2
$opts->{"capture"} //= 0
l!l
531
MC/DC100%1/1
$opts->{"capture"} //= 0
$opts->{"capture"}
Truth table100%2/2
A
A= $opts->{"capture"}
Aresult
11
00
739 36 my $re;
740 36 ▶ if( $opts->{ignore} )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'ignore'}) { } 0 36 36
elsif ($opts->{'include'}) { } 35 1 36
741 {
742 0 ▶ $re = $opts->{capture} ? qr/(.*?)(?<__reader_delimiter>${what})/s : qr/(.*?)${what}/s;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'capture'} ? : 0 0 0
743 }
744 elsif( $opts->{include} )
745 {
746 35 ▶ $re = $opts->{capture} ? qr/((?:.*?)(?<__reader_delimiter>${what}))/s : qr/((?:.*?)${what})/s;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'capture'} ? : 5 30 35
747 }
748 else
749 {
750 1 $re = qr/(.*?)(?=${what})/s;
751 }
752 36 ▶ my $chunk_size = $opts->{chunk_size} // 2048;
Condition50%1/2
$opts->{"chunk_size"} // 2048
l!l
036
MC/DC0%0/1
$opts->{"chunk_size"} // 2048
$opts->{"chunk_size"}
Truth table50%1/2
A
A= $opts->{"chunk_size"}
Aresult
11
00
753 36 my $max = $self->max_read_buffer;
754 36 my $buff = '';
755 # Make an initial read to get whatever is in the internal buffer
756 # Maybe that is sufficient to satisfy the regular expression need
757 36 ▶ if( my $buff_len = $self->buffer->length )
Branch: 1 branch
BranchTrueFalseTotal
if (my $buff_len = $self->buffer->length) 33 3 36
758 {
759 33 my $bytes = $self->read( $buff, $buff_len );
760 33 ▶ return( $self->pass_error ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 33 33
761 }
762  
763 36 ▶ while( $buff !~ /$re/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($buff =~ /$re/) 3 35 38
764 {
765 3 my $n = $self->read( $buff, $chunk_size, CORE::length( $buff ) );
766 3 ▶ return( $self->pass_error ) if( !defined( $n ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 3 3
767 3 ▶ return( '' ) if( !$n );
Branch: 1 branch
BranchTrueFalseTotal
unless $n 1 2 3
768
769 2 ▶ if( $max && CORE::length( $buff ) > $max )
Branch: 1 branch
BranchTrueFalseTotal
if ($max and length $buff > $max) 0 2 2
Condition33%1/3
$max and length $buff > $max
!ll&&!rl&&r
200
MC/DC0%0/2
$max and length $buff > $max
$max length $buff > $max
Truth table33%1/3
A and B
A= $maxB= length $buff > $max
ABresult
0X0
100
111
770 {
771 0 $self->unread( $buff );
772 0 return( $self->error({ code => 413, message => "Maximum read buffer limit ($max) reached." }) );
773 }
774 }
775 35 ▶ if( $buff =~ s/^$re// )
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ s/^$re//) { } 35 0 35
776 {
777 35 my $match = $1;
778 35 ▶ if( exists( $+{__reader_delimiter} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $+{'__reader_delimiter'}) { } 5 30 35
779 {
780 5 $self->last_delimiter( $+{__reader_delimiter} );
781 }
782 else
783 {
784 30 $self->last_delimiter->reset;
785 }
786 35 $self->unread( $buff );
787 35 return( $match );
788 }
789 else
790 {
791 }
792 0 $self->unread( $buff );
793 0 return( '' );
794 }
795  
796 # NOTE: request parameter
797 0 ▶sub ssl_opts { return( shift->_set_get_hash_as_mix_object( 'ssl_opts', @_ ) ); }
Subroutine ssl_opts: not called CC=1 SCAR=6.9
Pod documented
798  
799 177 ▶sub stop_if { return( shift->_set_get_code( 'stop_if', @_ ) ); }
Subroutine stop_if: called CC=1 SCAR=0.0
Pod documented
800  
801 # sub timeout { return( shift->_set_get_number_as_scalar( 'timeout', @_ ) ); }
802 sub timeout
803 228 ▶{
Subroutine timeout: called CC=2 SCAR=7.1
Pod documented
804 228 my $self = shift( @_ );
805 228 ▶ $self->{timeout} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 228 228
806 228 return( $self->{timeout} );
807 }
808  
809 sub unread
810 47 ▶{
Subroutine unread: called CC=2 SCAR=6.9
Pod documented
811 47 my $self = shift( @_ );
812 47 my $buff = $self->buffer;
813 47 ▶ if( $buff->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($buff->is_empty) { } 43 4 47
814 {
815 43 $buff->set( shift( @_ ) );
816 }
817 else
818 {
819 4 $buff->prepend( shift( @_ ) );
820 }
821 47 return( $self );
822 }
823  
824 # returns (positive) number of bytes written, or undef if the filehandle is to be closed
825 sub write
826 110 ▶{
Subroutine write: called CC=18 SCAR=46.2
Pod documented
827 110 my $self = $_[0];
828 110 ▶ return( $self->error( "Invalid number of arguments. Usage: \$self->write( \$buffer, \$length, \$offset )" ) ) unless( @_ > 1 && @_ < 6 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 and @_ < 6 0 110 110
Condition33%1/3
@_ > 1 and @_ < 6
!ll&&!rl&&r
00110
MC/DC0%0/2
@_ > 1 and @_ < 6
@_ > 1 @_ < 6
Truth table33%1/3
A and B
A= @_ > 1B= @_ < 6
ABresult
0X0
100
111
829 # Buffer is #1
830 110 ▶ my $len = @_ > 2 ? $_[2] : length( $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 ? : 0 110 110
831 110 ▶ my $off = @_ > 3 ? $_[3] : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ > 3 ? : 0 110 110
832 110 ▶ my $timeout = @_ > 4 ? $_[4] : $self->timeout;
Branch: 1 branch
BranchTrueFalseTotal
@_ > 4 ? : 0 110 110
833 110 ▶ my $fh = $self->filehandle || return( $self->error( "No filehandle set to read from." ) );
Condition50%1/2
$self->filehandle || (return $self->error('No filehandle set to read from.'))
l!l
1100
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle set to read from.'))
$self->filehandle
Truth table50%1/2
A
A= $self->filehandle
Aresult
11
00
834 110 ▶ my $is_object = $self->_can( $fh => 'syswrite' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_can($fh, 'syswrite') ? : 110 0 110
835 110 while(1)
836 {
837 110 ▶ my $bytes = $is_object
Branch: 1 branch
BranchTrueFalseTotal
$is_object ? : 110 0 110
838 ? $fh->syswrite( $_[1], $len, $off )
839 : syswrite( $fh, $_[1], $len, $off );
840 110 ▶ if( defined( $bytes ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bytes) 110 0 110
841 {
842 110 return( $bytes );
843 }
844 0 ▶ if( $! == EAGAIN || $! == EWOULDBLOCK || ( $IS_WIN32 && $! == EISCONN ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106) { } 0 0 0
elsif ($! == 4) { } 0 0 0
Condition0%0/9
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
l!l&&r!l&&!r
000
$! == 11 or $! == 11
l!l&&r!l&&!r
000
$HTTP::Promise::IO::IS_WIN32 and $! == 106
!ll&&!rl&&r
000
MC/DC0%0/4
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
$! == 11 $! == 11 $HTTP::Promise::IO::IS_WIN32 $! == 106
Truth table0%0/5
A or B or C and D
A= $! == 11B= $! == 11C= $HTTP::Promise::IO::IS_WIN32D= $! == 106
ABCDresult
1XXX1
01XX1
00111
000X0
00100
845 {
846 # passthru
847 }
848 # Could not write because of an interruption
849 elsif( $! == EINTR )
850 {
851 0 ▶ return( $self->error({ code => ERROR_EINTR, message => "Interruption prevented writing to filehandle '$fh': $!" }) ) if( $self->stop_if->() );
Branch: 1 branch
BranchTrueFalseTotal
if $self->stop_if->() 0 0 0
852 # otherwise passthru
853 }
854 else
855 {
856 0 return( $self->error( "Error writing ${len} bytes at offset ${off} from buffer (size: ", length( $_[2] ), " bytes) to filehandle '$fh': $!" ) );
857 }
858 0 my $rv = $self->make_select_timeout( write => 1, timeout => $timeout );
859 0 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
860 0 ▶ return( $self->error( "Unable to select the filehandle." ) ) if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 0 0
861 }
862 }
863  
864 sub write_all
865 0 ▶{
Subroutine write_all: not called CC=8 SCAR=42.8
Pod documented
866 0 my $self = $_[0];
867 0 ▶ return( $self->error( "Invalid number of arguments. Usage: \$self->_write_all( \$buffer )" ) ) unless( @_ > 1 && @_ < 4 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 and @_ < 4 0 0 0
Condition0%0/3
@_ > 1 and @_ < 4
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 1 and @_ < 4
@_ > 1 @_ < 4
Truth table0%0/3
A and B
A= @_ > 1B= @_ < 4
ABresult
0X0
100
111
868 # Buffer is #1
869 0 ▶ my $timeout = @_ > 2 ? $_[2] : $self->timeout;
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 ? : 0 0 0
870 0 my $off = 0;
871 0 ▶ while( my $len = length( $_[1] ) - $off )
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = length($_[1]) - $off) 0 0 0
872 {
873 0 my $bytes = $self->write( $_[1], $len, $off, $timeout );
874 0 ▶ return( $self->pass_error ) if( !defined( $bytes ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
875 0 ▶ return( $bytes ) if( !$bytes );
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes 0 0 0
876 0 $off += $bytes;
877 # Should never happen
878 0 ▶ last if( $len < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $len < 0 0 0 0
879 }
880 # Return total bytes sent
881 0 return( $off );
882 }
883  
884 sub _set_sockopts
885 0 ▶{
Subroutine _set_sockopts: not called CC=8 SCAR=42.8
886 0 my $self = shift( @_ );
887 0 ▶ my $sock = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No socket was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No socket was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
888 return( $self->error( "No socket was provided." ) );
889  
890 0 ▶ setsockopt( $sock, IPPROTO_TCP, TCP_NODELAY, 1 ) or
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $sock, 6, 1, 1 or return $self->error("Failed to setsockopt(TCP_NODELAY): $!") 0 0 0
891 return( $self->error( "Failed to setsockopt(TCP_NODELAY): $!" ) );
892 0 ▶ if( $IS_WIN32 )
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Promise::IO::IS_WIN32) { } 0 0 0
893 {
894 0 ▶ if( ref( $sock ) ne 'IO::Socket::SSL' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sock ne "IO::Socket::SSL") 0 0 0
895 {
896 0 my $tmp = 1;
897 0 ▶ ioctl( $sock, 0x8004667E, \$tmp ) or
Branch: 1 branch
BranchTrueFalseTotal
ioctl $sock, 2147772030, \$tmp or return $self->error("Cannot set flags for the socket: $!") 0 0 0
898 return( $self->error( "Cannot set flags for the socket: $!" ) );
899 }
900 }
901 else
902 {
903 0 ▶ my $flags = fcntl( $sock, F_GETFL, 0 ) or
Branch: 1 branch
BranchTrueFalseTotal
my $flags = fcntl($sock, 3, 0) or return $self->error("Cannot get flags for the socket: $!") 0 0 0
904 return( $self->error( "Cannot get flags for the socket: $!" ) );
905 0 ▶ $flags = fcntl( $sock, F_SETFL, $flags | O_NONBLOCK ) or
Branch: 1 branch
BranchTrueFalseTotal
$flags = fcntl($sock, 4, $flags | 2048) or return $self->error("Cannot set flags for the socket: $!") 0 0 0
906 return( $self->error( "Cannot set flags for the socket: $!" ) );
907 }
908  
909 {
910 # no buffering
911 0 my $orig = select();
912 0 select( $sock ); $| = 1;
913 0 select( $orig );
914 }
915 0 binmode( $sock );
916 0 return( $sock );
917 }
918  
919 sub _ssl_opts
920 0 ▶{
Subroutine _ssl_opts: not called CC=9 SCAR=45.0
921 0 my $self = shift( @_ );
922 0 my $ssl_opts = $self->ssl_opts;
923 0 ▶ unless( exists( $ssl_opts->{SSL_verify_mode} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ssl_opts->{"SSL_verify_mode"}) 0 0 0
924 {
925 0 ▶ if( exists( $ssl_opts->{verify_hostname} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ssl_opts->{'verify_hostname'} and not $ssl_opts->{'verify_hostname'}) { } 0 0 0
Condition0%0/3
exists $ssl_opts->{"verify_hostname"} and not $ssl_opts->{"verify_hostname"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ssl_opts->{"verify_hostname"} and not $ssl_opts->{"verify_hostname"}
exists $ssl_opts->{"verify_hostname"} not $ssl_opts->{"verify_hostname"}
Truth table0%0/3
A and not(B)
A= exists $ssl_opts->{"verify_hostname"}B= not $ssl_opts->{"verify_hostname"}
ABresult
0X0
100
111
926 !$ssl_opts->{verify_hostname} )
927 {
928 0 $ssl_opts->{SSL_verify_mode} = IO::Socket::SSL::SSL_VERIFY_NONE();
929 }
930 else
931 {
932 # set SSL_VERIFY_PEER as default.
933 0 $ssl_opts->{SSL_verify_mode} = IO::Socket::SSL::SSL_VERIFY_PEER();
934 }
935 0 ▶ unless( exists( $ssl_opts->{SSL_verifycn_scheme} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ssl_opts->{"SSL_verifycn_scheme"}) 0 0 0
936 {
937 0 $ssl_opts->{SSL_verifycn_scheme} = 'www'
938 }
939 }
940 0 ▶ if( $ssl_opts->{SSL_verify_mode} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ssl_opts->{"SSL_verify_mode"}) 0 0 0
941 {
942 0 ▶ unless( exists( $ssl_opts->{SSL_ca_file} ) || exists( $ssl_opts->{SSL_ca_path} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ssl_opts->{"SSL_ca_file"} or exists $ssl_opts->{"SSL_ca_path"}) 0 0 0
Condition0%0/3
exists $ssl_opts->{"SSL_ca_file"} or exists $ssl_opts->{"SSL_ca_path"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $ssl_opts->{"SSL_ca_file"} or exists $ssl_opts->{"SSL_ca_path"}
exists $ssl_opts->{"SSL_ca_file"} exists $ssl_opts->{"SSL_ca_path"}
Truth table0%0/3
A or B
A= exists $ssl_opts->{"SSL_ca_file"}B= exists $ssl_opts->{"SSL_ca_path"}
ABresult
1X1
011
000
943 {
944 0 ▶ $self->_load_class( 'Mozilla::CA' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Mozilla::CA") or return $self->pass_error 0 0 0
945 0 $ssl_opts->{SSL_ca_file} = Mozilla::CA::SSL_ca_file();
946 }
947 }
948 0 return( $ssl_opts );
949 }
950  
951 sub FREEZE
952 2 ▶{
Subroutine FREEZE: called CC=7 SCAR=21.1
Pod undocumented
953 2 my $self = CORE::shift( @_ );
954 2 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition50%1/2
shift @_ // ""
l!l
20
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
955 2 my $class = CORE::ref( $self );
956 2 my %hash = %$self;
957 2 CORE::delete( @hash{ qw( _fh ) } );
958 2 ▶ if( CORE::exists( $hash{stop_if} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{"stop_if"} and defined $hash{"stop_if"} and ref $hash{"stop_if"}) 2 0 2
Condition33%2/6
exists $hash{"stop_if"} and defined $hash{"stop_if"} and ref $hash{"stop_if"}
!ll&&!rl&&r
002
exists $hash{"stop_if"} and defined $hash{"stop_if"}
!ll&&!rl&&r
002
MC/DC0%0/3
exists $hash{"stop_if"} and defined $hash{"stop_if"} and ref $hash{"stop_if"}
exists $hash{"stop_if"} defined $hash{"stop_if"} ref $hash{"stop_if"}
Truth table25%1/4
A and B and C
A= exists $hash{"stop_if"}B= defined $hash{"stop_if"}C= ref $hash{"stop_if"}
ABCresult
0XX0
10X0
1100
1111
959 CORE::defined( $hash{stop_if} ) &&
960 CORE::ref( $hash{stop_if} ) )
961 {
962 2 require B::Deparse;
963 2 my $deparse = B::Deparse->new( '-p', '-sC' );
964 2 my $code = $deparse->coderef2text( CORE::delete( $hash{stop_if} ) );
965 2 $hash{stop_if_code} = $code;
966 }
967 # Return an array reference rather than a list so this works with Sereal and CBOR
968 2 ▶ CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023") 0 2 2
Condition66%2/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
!ll&&!rl&&r
110
MC/DC0%0/2
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
$serialiser eq "Sereal" "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
Truth table66%2/3
A and B
A= $serialiser eq "Sereal"B= "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
ABresult
0X0
100
111
969 # But Storable want a list with the first element being the serialised element
970 2 CORE::return( $class, \%hash );
971 }
972  
973 1 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
974  
975 1 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
976  
977 sub THAW
978 2 ▶{
Subroutine THAW: called CC=14 SCAR=29.0
Pod undocumented
979 2 my( $self, undef, @args ) = @_;
980 2 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 2 2
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
200
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
981 2 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 2 0 2
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
002
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
002
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table25%1/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
982 2 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 2 0 2
983 2 my $new;
984 # Storable pattern requires to modify the object it created rather than returning a new one
985 2 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 1 1 2
986 {
987 1 foreach( CORE::keys( %$hash ) )
988 {
989 20 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
990 }
991 1 $new = $self;
992 }
993 else
994 {
995 1 $new = bless( $hash => $class );
996 }
997 2 ▶ if( CORE::exists( $hash->{stop_if_code} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash->{"stop_if_code"} and defined $hash->{"stop_if_code"} and length $hash->{"stop_if_code"}) 1 1 2
Condition66%4/6
exists $hash->{"stop_if_code"} and defined $hash->{"stop_if_code"} and length $hash->{"stop_if_code"}
!ll&&!rl&&r
101
exists $hash->{"stop_if_code"} and defined $hash->{"stop_if_code"}
!ll&&!rl&&r
101
MC/DC33%1/3
exists $hash->{"stop_if_code"} and defined $hash->{"stop_if_code"} and length $hash->{"stop_if_code"}
exists $hash->{"stop_if_code"} defined $hash->{"stop_if_code"} length $hash->{"stop_if_code"}
Truth table50%2/4
A and B and C
A= exists $hash->{"stop_if_code"}B= defined $hash->{"stop_if_code"}C= length $hash->{"stop_if_code"}
ABCresult
0XX0
10X0
1100
1111
998 CORE::defined( $hash->{stop_if_code} ) &&
999 CORE::length( $hash->{stop_if_code} ) )
1000 {
1001 1 my $code = CORE::delete( $hash->{stop_if_code} );
1002 1 my $saved = $@;
1003 # "if you want to eval the result, you should prepend "sub subname ", or "sub " for an anonymous function constructor."
1004 # <https://metacpan.org/pod/B::Deparse#coderef2text>
1005 1 my $ref;
1006 {
1007 10 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1008 1 ▶ $ref = eval( "sub{ $code }" );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
1009 }
1010 1 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
1011 {
1012 0 $@ =~ s/ at .*\n//;
1013 0 die( $@ );
1014 }
1015 1 $@ = $saved;
1016 1 $new->{stop_if} = $ref;
1017 }
1018 2 CORE::return( $new );
1019 }
1020  
1021 10 1;
1022 # NOTE: POD
1023 __END__
« Promise/Entity.pm ↑ Summary Promise/Message.pm »