| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 130 | ▶ | return(1) if( $fh->isa( 'IO::Socket::SSL' ) && $fh->pending ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fh->isa("IO::Socket::SSL") and $fh->pending
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 130 | ▶ | return(1) if( $fh->isa( 'Net::SSL' ) && $fh->can('pending') && $fh->pending ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$fh->isa("Net::SSL") and $fh->can("pending") and $fh->pending
$fh->isa("Net::SSL") and $fh->can("pending")
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 12 | ▶ | if( $self->_can( $fh => 'can_read' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return( ( $flags == O_RDONLY ) || ( $flags & ( O_RDONLY | O_RDWR ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$flags == 0 || $flags & 2
MC/DC0%0/2
$flags == 0 || $flags & 2
$flags == 0
$flags & 2
Truth table0%0/3
A || B
A= $flags == 0B= $flags & 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 118 | my $nfound = select( $fbits, undef, undef, $timeout ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 118 | ▶ | if( $nfound < 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if( $!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"} or $!{"EAGAIN"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # don't really think EAGAIN/EWOULDBLOCK can happen here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if( $timeout ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $timeout -= time() - $before; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | $timeout = 0 if( $timeout < 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | return( $self->error( "Port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return( $self->error( "No timeout was provided to connect." ) ) if( !exists( $opts->{timeout} ) || !length( $opts->{timeout} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $timeout and $timeout > 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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): $!"))
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my( $lport, $laddr ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $lport = $opts->{local_port} if( exists( $opts->{local_port} ) && defined( $opts->{local_port} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opts->{"local_port"} and defined $opts->{"local_port"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | $laddr = defined( $opts->{local_host} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ? Socket::inet_aton( $opts->{local_host} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | : INADDR_ANY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | return( $self->error( "Bad local host provided \"$opts->{local_host}\": $!" ) ) if( !defined( $laddr ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if( defined( $lport ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $lport or $laddr ne "\0\0\0\0"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'}): $!"))
$lport // 0
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)
Truth table0%0/2
A
A= $lport
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if( $laddr ne INADDR_ANY ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | return( $self->error( "Unable to create socket: $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | $self->_set_sockopts( $sock ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my $params = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if( $self->_is_array( $INIT_PARAMS ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | for( @$INIT_PARAMS ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | $params->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if( CORE::connect( $sock, $sock_addr ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # connected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | ▶ | elsif( $! == EINPROGRESS || ( $IS_WIN32 && $! == EWOULDBLOCK ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$! == 115 or $HTTP::Promise::IO::IS_WIN32 and $! == 11
$HTTP::Promise::IO::IS_WIN32 and $! == 11
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return( $self->error( "Select timeout on socket." ) ) if( !$rv ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # connected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if( $! == EINTR && !$stop_if->() ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$! == 4 and not &$stop_if()
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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | return( $self->error( "Port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | return( $self->error( "No timeout was provided to connect." ) ) if( !exists( $opts->{timeout} ) || !length( $opts->{timeout} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | $self->_load_class( 'IO::Socket::SSL' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $params = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if( $self->_is_array( $INIT_PARAMS ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | for( @$INIT_PARAMS ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | $params->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$self->connect(%$params) || (return $self->pass_error)
$self->connect(%$params)
Truth table0%0/2
A
A= $self->connect(%$params)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
$opts->{"timeout"} // $self->timeout
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | return( $self->error( "Proxy port provided ($proxy_port) is not a number" ) ) if( $proxy_port !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | return( $self->error( "Host port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | return( $self->error( "Port provided ($port) is not a number" ) ) if( $port !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | return( $self->error( "No timeout was provided to connect." ) ) if( !exists( $opts->{timeout} ) || !length( $opts->{timeout} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $proxy_authorization = $opts->{proxy_authorization}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | $self->_load_class( 'IO::Socket::SSL' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $params = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if( $self->_is_array( $INIT_PARAMS ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | for( @$INIT_PARAMS ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $params->{ $_ } = $opts->{ $_ } if( exists( $opts->{ $_ } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$self->connect(%$params) || (return $self->pass_error)
$self->connect(%$params)
Truth table0%0/2
A
A= $self->connect(%$params)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | return( $self->error( "Cannot read proxy response: " . ( $! != 0 ? "$!" : 'timeout' ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $ssl_opts = $new->_ssl_opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | unless( exists( $ssl_opts->{SSL_verifycn_name} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle currently set.'))
$self->filehandle
Truth table50%1/2
A
A= $self->filehandle
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 8 | my $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 8 | ▶ | my $is_object = $self->_can( $fh => 'sysread' ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$max and $buff->length > $max
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 8 | ▶ | return( $self->error( "Cannot read from filehandle '$fh'" ) ) if( !$rv ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # consume all incoming bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 8 | ▶ | my $bytes_read = $is_object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ? $fh->sysread( $$buff, 1024, $buff->length ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | : sysread( $fh, $$buff, 1024, $buff->length ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 8 | ▶ | if( defined( $bytes_read ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 8 | $new_bytes += $bytes_read; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | ▶ | elsif( $!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$!{"EINTR"} or $!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EINTR"} or $!{"EAGAIN"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # no line-ending, no new bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | return( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 8 | ▶ | $buff->length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$max and $pos > $max
MC/DC0%0/2
$max and $pos > $max
$max
$pos > $max
Truth table33%1/3
A and B
A= $maxB= $pos > $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | my $timeout = $opts->{timeout} // $self->timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{"timeout"} // $self->timeout
MC/DC0%0/2
$opts->{"timeout"} // $self->timeout
$opts->{"timeout"}
$self->timeout
Truth table0%0/3
A // B
A= $opts->{"timeout"}B= $self->timeout
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | return( $self->error( 'No timeout was provided.' ) ) if( !defined( $timeout ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | my $is_write = $opts->{write} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$nfound < 0 and $!
MC/DC0%0/2
$nfound < 0 and $!
$nfound < 0
$!
Truth table0%0/3
A and B
A= $nfound < 0B= $!
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
$self->filehandle || (return $self->error('No filehandle currently set.'))
$self->filehandle
Truth table0%0/2
A
A= $self->filehandle
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my $timeout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | $timeout = $opts->{timeout} if( exists( $opts->{timeout} ) && length( $opts->{timeout} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opts->{"timeout"} and length $opts->{"timeout"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | $timeout //= $self->timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$timeout //= $self->timeout
MC/DC0%0/2
$timeout //= $self->timeout
$timeout
$self->timeout
Truth table0%0/3
A //= B
A= $timeoutB= $self->timeout
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
$self->inactivity_timeout // $opts->{"inactivity_timeout"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | $timeout_at = $inactivity_timeout_at if( $timeout_at > $inactivity_timeout_at ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return(1) if( $nfound > 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | return(0) if( $nfound == -1 && $! == EINTR && $stop_if->() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$nfound == -1 and $! == 4 and &$stop_if()
$nfound == -1 and $! == 4
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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
@_ > 2 and @_ < 5
MC/DC0%0/2
@_ > 2 and @_ < 5
@_ > 2
@_ < 5
Truth table33%1/3
A and B
A= @_ > 2B= @_ < 5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $len and $len =~ /^\d+$/
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+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $off and not $off =~ /^-?\d+$/
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+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 48 | ▶ | my $is_scalar = $self->_is_scalar( $_[1] ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $_[1] and not $is_scalar
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 48 | ▶ | $off //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$off //= 0
MC/DC100%1/1
$off //= 0
$off
Truth table100%2/2
A
A= $off
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | ? $fh->sysread( $_[0], $_[1], ( @_ > 2 ? $_[2] : () ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | : sysread( $fh, $_[0], $_[1], ( @_ > 2 ? $_[2] : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 14 | ▶ | if( defined( $n ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 14 | return( $n ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | if( $! == EAGAIN || $! == EWOULDBLOCK || ( $IS_WIN32 && $! == EISCONN ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/9
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
$! == 11 or $! == 11
$HTTP::Promise::IO::IS_WIN32 and $! == 106
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | return( $self->error( "Timeout. Unable to select the filehandle." ) ) if( !$rv ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 48 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 48 | ▶ | if( $buff_len ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 8 | ▶ | return( $self->pass_error ) unless( defined( $self->can_read ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 8 | my $n = $sysread->( $$buff, ( $len - $buff_len ), $buff_len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 8 | ▶ | return( $self->pass_error ) if( !defined( $n ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # What we will return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 42 | ▶ | my $bytes = ( $buff->length > $len ? $len : $buff->length ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if( $off > length( $$_[1] ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 129 | my $len = $_[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 129 | ▶ | return( $self->error( "Length provided (${len}) is not an integer." ) ) if( $len !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 129 | ▶ | my $off = ( $_[3] =~ /^\-?\d+$/ ? $_[3] : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 129 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 129 | ▶ | $opts = $_[-1] if( ref( $_[-1] ) eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $what and length $what
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 129 | ▶ | $what = qr/\Q${what}\E/ unless( ref( $what ) eq 'Regexp' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 129 | ▶ | $opts->{ignore} //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"ignore"} //= 0
MC/DC0%0/1
$opts->{"ignore"} //= 0
$opts->{"ignore"}
Truth table50%1/2
A
A= $opts->{"ignore"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 129 | ▶ | $opts->{exclude} = 0 if( !exists( $opts->{exclude} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 129 | ▶ | $opts->{inlude} = !$opts->{exclude} if( !exists( $opts->{include} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$opts->{"capture"} //= 0
$opts->{"capture"}
Truth table100%2/2
A
A= $opts->{"capture"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 129 | my $re; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 129 | ▶ | if( $opts->{ignore} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 129 | ▶ | $re = $opts->{capture} ? qr/(.*?)(?<__reader_delimiter>${what})/s : qr/(.*?)${what}/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | elsif( $opts->{include} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | $re = $opts->{capture} ? qr/((?:.*?)(?<__reader_delimiter>${what}))/s : qr/((?:.*?)${what})/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$opts->{"chunk_size"} // 2048
$opts->{"chunk_size"}
Truth table50%1/2
A
A= $opts->{"chunk_size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 129 | ▶ | $chunk_size = $len if( $len > $chunk_size ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$buff_len and $$buff =~ /$re/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 114 | ▶ | if( $buff_len < $sliding_buffer_size ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 114 | ▶ | return( $self->pass_error ) unless( defined( $self->can_read ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 114 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 114 | ▶ | my $n = $is_object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | if( $! == EAGAIN || $! == EWOULDBLOCK || ( $IS_WIN32 && $! == EISCONN ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/9
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
$! == 11 or $! == 11
$HTTP::Promise::IO::IS_WIN32 and $! == 106
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | return( $self->error( "Unable to select the filehandle." ) ) if( !$rv ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | return( $n ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 113 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 128 | ▶ | $_[1] //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[1] //= ""
MC/DC100%1/1
$_[1] //= ""
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | $_[1] .= \0 x ( $off - length( $_[1] ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 128 | ▶ | if( $$buff =~ s/^$re// ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 18 | my $trail = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 18 | ▶ | if( exists( $+{__reader_delimiter} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $what and length $what
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 36 | ▶ | $what = qr/\Q${what}\E/ unless( ref( $what ) eq 'Regexp' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 36 | ▶ | $opts->{ignore} //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"ignore"} //= 0
MC/DC0%0/1
$opts->{"ignore"} //= 0
$opts->{"ignore"}
Truth table50%1/2
A
A= $opts->{"ignore"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 36 | ▶ | $opts->{exclude} = 0 if( !exists( $opts->{exclude} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 36 | ▶ | $opts->{inlude} = !$opts->{exclude} if( !exists( $opts->{include} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$opts->{"capture"} //= 0
$opts->{"capture"}
Truth table100%2/2
A
A= $opts->{"capture"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 36 | my $re; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 36 | ▶ | if( $opts->{ignore} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | $re = $opts->{capture} ? qr/(.*?)(?<__reader_delimiter>${what})/s : qr/(.*?)${what}/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | elsif( $opts->{include} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 35 | ▶ | $re = $opts->{capture} ? qr/((?:.*?)(?<__reader_delimiter>${what}))/s : qr/((?:.*?)${what})/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$opts->{"chunk_size"} // 2048
$opts->{"chunk_size"}
Truth table50%1/2
A
A= $opts->{"chunk_size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 33 | my $bytes = $self->read( $buff, $buff_len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 33 | ▶ | return( $self->pass_error ) if( !defined( $bytes ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 36 | ▶ | while( $buff !~ /$re/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 3 | ▶ | return( '' ) if( !$n ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 2 | ▶ | if( $max && CORE::length( $buff ) > $max ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$max and length $buff > $max
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 35 | my $match = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 35 | ▶ | if( exists( $+{__reader_delimiter} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
@_ > 1 and @_ < 6
MC/DC0%0/2
@_ > 1 and @_ < 6
@_ > 1
@_ < 6
Truth table33%1/3
A and B
A= @_ > 1B= @_ < 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | # Buffer is #1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 110 | ▶ | my $len = @_ > 2 ? $_[2] : length( $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 110 | ▶ | my $off = @_ > 3 ? $_[3] : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 110 | ▶ | my $timeout = @_ > 4 ? $_[4] : $self->timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 110 | ▶ | my $is_object = $self->_can( $fh => 'syswrite' ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 110 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 110 | ▶ | my $bytes = $is_object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | ? $fh->syswrite( $_[1], $len, $off ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | : syswrite( $fh, $_[1], $len, $off ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 110 | ▶ | if( defined( $bytes ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 110 | return( $bytes ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | ▶ | if( $! == EAGAIN || $! == EWOULDBLOCK || ( $IS_WIN32 && $! == EISCONN ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/9
$! == 11 or $! == 11 or $HTTP::Promise::IO::IS_WIN32 and $! == 106
$! == 11 or $! == 11
$HTTP::Promise::IO::IS_WIN32 and $! == 106
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | ▶ | return( $self->error( "Unable to select the filehandle." ) ) if( !$rv ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@_ > 1 and @_ < 4
MC/DC0%0/2
@_ > 1 and @_ < 4
@_ > 1
@_ < 4
Truth table0%0/3
A and B
A= @_ > 1B= @_ < 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # Buffer is #1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | ▶ | my $timeout = @_ > 2 ? $_[2] : $self->timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | my $off = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | ▶ | while( my $len = length( $_[1] ) - $off ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | my $bytes = $self->write( $_[1], $len, $off, $timeout ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | ▶ | return( $self->pass_error ) if( !defined( $bytes ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | ▶ | return( $bytes ) if( !$bytes ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | $off += $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | # Should never happen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | ▶ | last if( $len < 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.'))
MC/DC0%0/1
shift @_ || (return $self->error('No socket was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | return( $self->error( "No socket was provided." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | ▶ | setsockopt( $sock, IPPROTO_TCP, TCP_NODELAY, 1 ) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | return( $self->error( "Failed to setsockopt(TCP_NODELAY): $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | if( $IS_WIN32 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | ▶ | if( ref( $sock ) ne 'IO::Socket::SSL' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | my $tmp = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | ▶ | ioctl( $sock, 0x8004667E, \$tmp ) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | return( $self->error( "Cannot get flags for the socket: $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | ▶ | $flags = fcntl( $sock, F_SETFL, $flags | O_NONBLOCK ) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | ▶ | if( exists( $ssl_opts->{verify_hostname} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $ssl_opts->{"verify_hostname"} and not $ssl_opts->{"verify_hostname"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | $ssl_opts->{SSL_verifycn_scheme} = 'www' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | ▶ | if( $ssl_opts->{SSL_verify_mode} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | ▶ | unless( exists( $ssl_opts->{SSL_ca_file} ) || exists( $ssl_opts->{SSL_ca_path} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $ssl_opts->{"SSL_ca_file"} or exists $ssl_opts->{"SSL_ca_path"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | ▶ | $self->_load_class( 'Mozilla::CA' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 @_ // ""
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
exists $hash{"stop_if"} and defined $hash{"stop_if"} and ref $hash{"stop_if"}
exists $hash{"stop_if"} and defined $hash{"stop_if"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$serialiser eq "Sereal" and "Sereal::Encoder"->VERSION <= "version"->parse("4.023")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref and ref $ref eq "ARRAY"
ref $self or $self
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
Truth table0%0/3
A or B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 2 | ▶ | my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
exists $hash->{"stop_if_code"} and defined $hash->{"stop_if_code"} and length $hash->{"stop_if_code"}
exists $hash->{"stop_if_code"} and defined $hash->{"stop_if_code"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||