| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | warnings::register_categories( 'HTTP::Promise' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 11 | ▶ | use vars qw( $CRLF $IS_WIN32 $INIT_PARAMS $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | ▶ | use Errno qw( EAGAIN ECONNRESET EINPROGRESS EINTR EWOULDBLOCK ECONNABORTED EISCONN ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | ▶ | 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 | 11 | use Socket qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | PF_INET SOCK_STREAM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | IPPROTO_TCP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | TCP_NODELAY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | pack_sockaddr_in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | INADDR_ANY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | ▶ | use Time::HiRes qw( time ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | use constant ERROR_EINTR => ( abs( Errno::EINTR ) * -1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | our $CRLF = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | our $IS_WIN32 = ( $^O eq 'MSWin32' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # This is for connect() so it knows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | our $INIT_PARAMS = [qw( buffer debug inactivity_timeout last_delimiter max_read_buffer ssl_opts stop_if timeout )]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 11 | our $VERSION = 'v0.1.1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 25 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 130 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_read: called CC=20 SCAR=46.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=36 SCAR=71.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_ssl: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_ssl_over_proxy: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 8 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getline: called CC=21 SCAR=40.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_select: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_select_timeout: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 48 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=22 SCAR=43.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 14 | ▶ | while(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=46.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 129 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_until: called CC=42 SCAR=49.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 36 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_until_in_memory: called CC=22 SCAR=33.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 228 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 228 | ▶ | $self->{timeout} = shift( @_ ) if( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 228 | return( $self->{timeout} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | sub unread | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 47 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unread: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 110 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=18 SCAR=46.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_all: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_sockopts: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ssl_opts: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 2 | ▶ | my $self = CORE::shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FREEZE: called CC=7 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 2 | ▶ | my( $self, undef, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
THAW: called CC=14 SCAR=29.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 11 | ▶ | 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 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | HTTP::Promise::IO - I/O Handling Class for HTTP::Promise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | use HTTP::Promise::IO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | my $this = HTTP::Promise::IO->new( $fh ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | die( HTTP::Promise::IO->error, "\n" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | v0.1.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | This class implements a filehandle reader and writer with a twist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | First off, it does not rely on lines, since data stream or in general data from HTTP requests and responses do not necessarily always contain lines. Binary data are sent without necessarily any line at all. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | Second, it is easy on memory by implementing L</read>, which uses a shared L</buffer>, and you can use L</unread> to return data to it (they would be prepended). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | Last, but not least, it implements 2 methods to read in chunks of data from the filehandle until some string pattern specified is found: L</read_until> and L</read_until_in_memory> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | This takes a proper filehandle and will ensure the C<O_NONBLOCK> bit is set, so that it can timeout if there is no more data streamed from the filehandle. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | It returns the newly instantiated object upon success, and upon error, sets an L<error|Module::Generic/error> and return C<undef> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | Possible optional parameters are: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | =item C<buffer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | You can pass some data that will set the initial read buffer, from which other methods in this class access before reading from the filehandle. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | =item C<max_read_buffer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | An integer. You can set this a default value for the maximum size of the read buffer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | This is used by L</getline> and L</read_until_in_memory> to limit how much data can be read into the buffer until it returns an error. Hopefully a line or a match specified with C<read_until> would be found and returned before this limit is reached. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | If this is greater than 0 and the amount of data loaded exceeds this limit, and error is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | =item C<timeout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | AN integer. This is the read timeout. It defaults to 10. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | =head2 buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | Sets or gets the buffer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | This is used by those class methods to get leftover data from the buffer, if any, or from the filehandle if necessary. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | This returns a L<scalar object|Module::Generic::Scalar> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | =head2 can_read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | Returns true if it can read from the filehandle or false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | It takes an optional hash or hash reference of options, of which, C<timeout> is the only one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | =head2 close | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | Close the filehandle and destroys the current object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | =head2 connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | Provided with an hash or hash reference of options and this will connect to the remote server. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | It returns a new L<HTTP::Promise::IO> object, or upon error, it sets an L<error|Module::Generic/error> and returns C<undef> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | Supported options are: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | All the options used for object instantiation. See L</CONSTRUCTOR> and the following ones: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | =item * C<debug> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | Integer representing the level of debug. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | =item * C<host> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | The remote host to connect to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | =item * C<port> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | An integer representing the remote port to connect to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | =item * C<stop_if> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | A code reference that serves as a callback and that is called where there is an C<EINTR> error. If the callback returns true, the connection attempts stop there and returns an error. This default to return false. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | =item * C<timeout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | An integer or a decimal representing a timeout to be used when resolving the host, or when making remote connection. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | =head2 connect_ssl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | This takes the same options has L</connect>, but performs an SSL connection. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | Like L</connect>, this returns a new L<HTTP::Promise::IO> object, or upon error, it sets an L<error|Module::Generic/error> and returns C<undef> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | =head2 connect_ssl_over_proxy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | Provided with an hash or hash reference of options and this will connect to the remote server. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | It returns a new L<HTTP::Promise::IO> object, or upon error, it sets an L<error|Module::Generic/error> and returns C<undef> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | Supported options are: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | All the options used for object instantiation. See L</CONSTRUCTOR> and the following ones: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | =item * C<debug> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | Integer representing the level of debug. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | =item * C<host> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | The remote host to connect to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | =item * C<port> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | An integer representing the remote port to connect to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | =item * C<proxy_authorization> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | The proxy authorisation string to use for authentication. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | =item * C<proxy_host> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | The remote proxy host to connect to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | =item * C<proxy_port> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | An integer representing the remote proxy port to connect to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | =item * C<stop_if> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | A code reference that serves as a callback and that is called where there is an C<EINTR> error. If the callback returns true, the connection attempts stop there and returns an error. This default to return false. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | =item * C<timeout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | An integer or a decimal representing a timeout to be used when resolving the host, or when making remote connection. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | =head2 filehandle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | Sets or gets the filehandle being used. This is the same filehandle that was passed upon object instantiation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | =head2 getline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | Reads from the buffer, if there is enough data left over, or from the filehandle and returns the first line found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | A line is a string that ends with C<\012> which is portable and universal. This would be the equivalent of C<\n>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | It returns the line found, if any, or C<undef> if there was an error that you can retrieve with L<error|Module::Generic/error>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | it takes an optional hash or hash reference of options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | =item C<chomp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | If true, this will chomp any trailing sequence of C<\012> possibly preceded by C<\015> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | =item C<max_read_buffer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | An integer that limits how much cumulative data can be read until it exceeds this allowed maximum. When that happens, an error is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | =head2 inactivity_timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | Integer representing the amount of second to wait until a connection is deemed idle and closed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | =head2 last_delimiter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | Sets or gets the last delimiter found. A delimiter is some pattern that is provided to L</read_until> and L</read_until_in_memory> with the option C<capture> set to a true value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | This returns the last delimited found as a L<scalar object|Module::Generic::Scalar> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | =head2 make_select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | Provided with an hash or hash reference of options and this L<perlfunc/select> the filehandle or socket using the C<timeout> provided. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | It returns a positive integer upon success, and upon error, this sets an L<error|Module::Generic/error> and returns C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | Supported options are: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | =item * C<timeout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | Integer representing the timeout. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | =item * C<write> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | Boolean. When true, this will check the filehandle or socket for write capability, or if false for read capability. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | =head2 make_select_timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | This takes the same options as L</make_select>, and it will retry selecting the filehandle or socket until success or a timeout occurs. If an C<EINTR> error occurs, it will query the callback provided with L</stop_if>. If the callback returns true, it will return an error, or keep trying otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | Returns true upon success, and upon error, this sets an L<error|Module::Generic/error> and returns C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | =head2 max_read_buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | Sets or gets the maximum bytes amount of the read buffer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | This is used by L</getline> and L</read_until_in_memory> to limit how much data can be read into the buffer until it returns an error. Hopefully a line or a match specified with C<read_until> would be found and returned before this limit is reached. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | If this is greater than 0 and the amount of data loaded exceeds this limit, and error is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | =head2 print | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | Provided with some data to print to the underlying filehandle or socket, and this will call L</write> and return true upon success, or false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | =head2 read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | my $bytes = $r->read( $buffer, $length ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | my $bytes = $r->read( $buffer, $length, $offset ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | This reads C<$length> bytes from either the internal buffer if there are leftover data, or the filehandle, or even both if the internal buffer is not big enough to meet the C<$length> requirement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | It returns how many bytes actually were loaded into the caller's C<$buffer>. It returns C<undef> after having set an L<error|Module::Generic/error> if an error occurred. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | Just like the perl core L<perlfunc/read> function, this one too will pad with C<\0> the caller's buffer if the offset specified is greater than the actual size of the caller's buffer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | Note that there is no guarantee that you can read from the filehandle the desired amount of bytes in just one time, especially if the filehandle is a socket, so you may need to do: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | my $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | my $total_to_read = 102400; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | my $total_bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | while( $bytes = $r->read( $buffer, $chunk_size ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | $out-print( $buffer ) || die( $! ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | # If you want to make sure you do not read more than necessary, otherwise, you can discard this line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | $chunk_size = ( $total_to_read - $total_bytes ) if( ( $total_bytes < $total_to_read ) && ( ( $total_bytes + $chunk_size ) > $total_to_read ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | $total_bytes += $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | last if( $total_bytes == $total_to_read ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | # Check if something bad happened | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | die( "Something wrong happened: ", $r->error ) if( !defined( $bytes ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | =head2 read_until | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | my $bytes = $r->read_until( $buffer, $length, $options_hashref ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | my $bytes = $r->read_until( $buffer, $length, $offset, $options_hashref ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | This is similar to L</read>, but will read data from either the buffer, the filehandle or a combination of both until the specified C<string>, passed as an option, is found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | It loads data in chunks specified with the option C<chunk_size> or by default 2048 bytes. If the specified string is not found within that buffer, it returns how many bytes where read and sets the caller's buffer with the data collected. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | Upon the last call when the C<string> is finally found, this will return the number of bytes read, but as a negative number. This will tell you it has found the match. You can consider the number is negative because those are the last n bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | When no more data at all can be read, this will return 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | If an error occurred, this will set an L<error|Module::Generic/error> and return C<undef> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | The possible options that can be passed as an hash reference B<only> are: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | =item C<capture> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | Boolean. When set to true, this will capture the match specified with C<string>. The resulting would then be retrievable using L</last_delimiter> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | =item C<chunk_size> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | An integer. This is the maximum bytes this will read per each iteration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | =item C<exclude> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | Boolean. If this is true, this will exclude the C<string> sought from the buffer allocation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | =item C<include> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | Boolean. If this is true, this will set the buffer including the C<string> sought after. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | =item C<string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | This is the C<string> to read data until it is found. The C<string> can be a simple string, or a regular expression. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | =head2 read_until_in_memory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | my $data = $r->read_until_in_memory( $string ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | my $data = $r->read_until_in_memory( $string, $options_hash_or_hashref ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | die( "Error: ", $r->error ) if( !defined( $data ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | Provided with a C<string> to be found, this will load data from the internal buffer, the filehandle, or a combination of both into memory until the specified C<string> is found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | Upon success, it returns the data read, which could be an empty string if nothing matched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | If an error occurred, this will set an L<error|Module::Generic/error> and return C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | It takes the following possible options, either as an hash or hash reference: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | =item C<capture> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | Boolean. When set to true, this will capture the match specified with C<string>. The resulting would then be retrievable using L</last_delimiter> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | =item C<chunk_size> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | An integer. This is the maximum bytes this will read per each iteration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | =item C<exclude> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | Boolean. If this is true, this will exclude the C<string> sought from the buffer allocation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | =item C<include> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | Boolean. If this is true, this will set the buffer including the C<string> sought after. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | =head2 ssl_opts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | Sets or gets an hash reference of ssl options to be used with L<IO::Socket::SSL/start_SSL> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | =head2 stop_if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | Sets or gets a code reference acting as a callback when an error C<EINTR> if encountered. If the callback returns true, the method using it, will stop and return an error, otherwise, it will keep trying. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | =head2 timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | Sets or gets the timeout threshold. This returns a L<number object|Module::Generic::Number> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | =head2 unread | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | Provided with some data and this will put it back into the internal buffer, at its beginning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | This returns the current object for chaining. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | =head2 write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | This write to the filehandle set, and takes a buffer to write, an optional length, an optional offset, and an optional timeout value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | If no length is provided, this default to the length of the buffer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | If no offset is provided, this default to C<0>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | If no timeout is provided, this default to the value set with L</timeout> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | It returns the number of bytes written or, upon error, sets an L<error|Module::Generic/error> and returns C<undef> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | =head2 write_all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | Provided with some data an an optional timeout, and this will write the data to the filehandle set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | It returns the number of bytes written or, upon error, sets an L<error|Module::Generic/error> and returns C<undef> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | =head1 THREAD-SAFETY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||