Branch Coverage

blib/lib/YAHC.pm
Criterion Covered Total %
branch 189 474 39.8


line true false branch
15 0 16 $ENV{'YAHC_NO_SSL'} ? :
91 8 1 unless defined $LAST_CONNECTION_ID
93 0 9 if defined $args and ref $args ne 'HASH'
94 0 9 unless wantarray
98 2 7 if $args->{'host'}
99 0 9 if $args->{'backoff_delay'}
100 0 9 if $args->{'socket_cache'}
117 1 8 if (delete $args->{'account_for_signals'})
118 0 1 if $self->{'debug'}
128 0 10 unless @args
129 0 10 unless $self->{'storage'}
131 10 0 @args == 1 ? :
133 0 10 if exists $self->{'connections'}{$conn_id}
136 0 80 if $pool_args->{$_}
139 8 2 if ($request->{'host'}) { }
2 0 elsif ($pool_args->{'_target'}) { }
147 0 10 if ($request->{'backoff_delay'}) { }
0 10 elsif ($pool_args->{'_backoff'}) { }
153 0 10 if ($request->{'socket_cache'}) { }
0 10 elsif ($pool_args->{'_socket_cache'}) { }
169 0 10 $debug ? :
4 6 $keep_timeline ? :
4 6 $debug || $keep_timeline ? :
0 10 defined $user_data ? :
181 58 2 unless exists $request->{$_}
190 0 10 if $request->{'lifetime_timeout'}
192 8 2 if $request->{'_test'}
197 0 0 if ($stop_condition and $stop_condition->{'all'})
206 0 0 ref $c eq 'HASH' ? :
207 0 0 unless my $conn = $self->{'connections'}{$conn_id}
208 0 0 if exists $conn->{'debug_or_timeline'}
209 0 0 unless $conn->{'state'} == 100
221 0 3 unless $self->is_running
222 0 3 if $self->{'debug'}
231 0 1 ($_[0] & 1073741824) == 1073741824 ? :
237 0 0 if $conn->{'state'} >= 100
241 0 0 unless defined $args and ref $args eq 'HASH'
244 0 0 if $args->{'host'}
245 0 0 if $args->{'backoff_delay'}
246 0 0 if $args->{$_}
252 0 0 if $conn->{'state'} >= 100
253 0 0 unless yahc_conn_attempts_left($conn) > 0
256 0 0 unless defined $args and ref $args eq 'HASH'
259 0 0 if $args->{'backoff_delay'}
264 0 0 unless $conn->{'errors'} and @{$conn->{'errors'};}
265 0 0 wantarray ? :
275 2 2 $_[0]{'attempt'} > $_[0]{'retries'} ? :
279 0 4 unless $target and scalar @{$target;}
281 0 4 $port ne '80' && $port ne '443' ? :
287 0 0 unless $target and @{$target;}
294 0 0 $port ne '80' && $port ne '443' ? :
0 0 defined $request->{'query_string'} ? :
299 0 0 if @_
309 0 6 unless $self->{'storage'}
310 0 6 if $self->{'loop'}->depth
312 0 6 if ($self->{'pid'} != $$)
313 0 0 if $self->{'debug'}
318 0 0 if $active_connections
322 2 4 if (defined $until_state) { }
324 0 2 if $until_state_str =~ /unknown/
328 0 2 unless $self->{'connections'}{$_}
329 0 2 ref $_ eq 'HASH' ? :
0 2 $is_all ? :
343 0 6 if ($self->{'debug'}) { }
345 0 0 $until_state ? :
356 0 2 if not $stop_condition or $conn->{'state'} < $stop_condition->{'expected_state'}
362 2 0 if ($awaiting_connections == 0)
368 0 0 if $self->{'debug'}
378 0 14 unless my $conn = $self->{'connections'}{$conn_id}
382 1 13 if exists $conn->{'debug_or_timeline'}
383 0 14 if exists $conn->{'has_init_callback'}
389 1 13 if $conn->{'attempt'} > $conn->{'retries'}
394 0 10 if ($attempt > 1 and exists $conn->{'request'}{'_backoff'})
396 0 0 if (my $error = $@)
401 0 0 if ($backoff_delay)
403 0 0 if exists $conn->{'debug_or_timeline'}
405 0 0 if exists $conn->{'debug_or_timeline'}
406 0 0 if _init_helper($self, $conn_id) == 1
412 0 13 if (_init_helper($self, $conn_id) == 1)
414 0 0 if exists $conn->{'debug_or_timeline'}
428 0 0 if exists $conn->{'debug_or_timeline'}
440 0 13 unless my $conn = $self->{'connections'}{$conn_id}
441 0 13 unless my $watchers = $self->{'watchers'}{$conn_id}
447 0 13 if $request->{'request_timeout'}
449 0 13 if $request->{'connect_timeout'}
451 0 13 if $request->{'drain_timeout'}
456 1 12 if exists $conn->{'debug_or_timeline'}
459 0 13 if (my $socket_cache = $request->{'_socket_cache'})
463 0 13 if (defined $sock) { }
464 0 0 if $conn->{'debug_or_timeline'}
469 1 12 if $conn->{'debug_or_timeline'}
475 0 13 unless (eval { do { my($host, $ip, $port, $scheme) = _get_next_target($conn); _register_in_timeline($conn, "Target ${scheme}://${host}:$port (${ip}:$port) chosen for attempt #%d", $conn->{'attempt'}) if exists $conn->{'debug_or_timeline'}; my $sock; if (my $socket_cache = $request->{'_socket_cache'}) { $sock = &$socket_cache(1, $conn); } ; if (defined $sock) { _register_in_timeline($conn, 'reuse socket') if $conn->{'debug_or_timeline'}; $watchers->{'_fh'} = $sock; $watchers->{'io'} = $self->{'loop'}->io($sock, 2, sub { } ); _set_write_state($self, $conn_id); } else { _register_in_timeline($conn, 'build new socket') if $conn->{'debug_or_timeline'}; $sock = _build_socket_and_connect($ip, $port); _set_connecting_state($self, $conn_id, $sock); } ; 1 } })
488 0 13 unless my $conn = $self->{'connections'}{$conn_id}
489 0 13 unless my $watchers = $self->{'watchers'}{$conn_id}
492 1 12 if exists $conn->{'debug_or_timeline'}
493 0 13 if exists $conn->{'has_connecting_callback'}
497 0 12 unless ($sockopt)
503 11 1 if (my $err = unpack('L', $sockopt))
515 0 13 if exists $self->{'stop_condition'}
521 0 1 unless my $conn = $self->{'connections'}{$conn_id}
522 0 1 unless my $watchers = $self->{'watchers'}{$conn_id}
525 1 0 if exists $conn->{'debug_or_timeline'}
526 0 1 if exists $conn->{'has_connected_callback'}
529 0 0 if ($conn->{'is_ssl'}) { }
538 1 0 if exists $self->{'stop_condition'}
544 0 0 unless my $conn = $self->{'connections'}{$conn_id}
545 0 0 unless my $watchers = $self->{'watchers'}{$conn_id}
548 0 0 if exists $conn->{'debug_or_timeline'}
557 0 0 'IO::Socket::SSL'->can_client_sni ? :
0 0 unless $conn->{'request'}{'ssl_options'}
560 0 0 if ($conn->{'debug_or_timeline'})
565 0 0 unless ('IO::Socket::SSL'->start_SSL($fh, %options, 'SSL_startHandshake', 0))
572 0 0 if ($fh->connect_SSL)
573 0 0 if exists $conn->{'debug_or_timeline'}
577 0 0 if ($! == 11)
578 0 0 if $IO::Socket::SSL::SSL_ERROR == 27308168
579 0 0 if $IO::Socket::SSL::SSL_ERROR == 27308240
589 0 0 if exists $self->{'stop_condition'}
595 0 1 unless my $conn = $self->{'connections'}{$conn_id}
596 0 1 unless my $watchers = $self->{'watchers'}{$conn_id}
599 1 0 if exists $conn->{'debug_or_timeline'}
600 0 1 if exists $conn->{'has_writing_callback'}
606 0 1 if utf8::is_utf8($buf)
610 0 1 $length > 1024 ? :
1 0 if exists $conn->{'debug_or_timeline'}
616 0 1 if (not defined $wlen) { }
0 1 elsif ($wlen == 0) { }
617 0 0 if ($conn->{'is_ssl'})
618 0 0 if ($! == 11)
619 0 0 if $IO::Socket::SSL::SSL_ERROR == 27308168
620 0 0 if $IO::Socket::SSL::SSL_ERROR == 27308240
627 0 0 if $! == 11 or $! == 4 or $! == 11
636 1 0 if $length == 0
643 0 1 if exists $self->{'stop_condition'}
649 0 3 unless my $conn = $self->{'connections'}{$conn_id}
650 0 3 unless my $watchers = $self->{'watchers'}{$conn_id}
653 3 0 if exists $conn->{'debug_or_timeline'}
654 0 3 if exists $conn->{'has_reading_callback'}
668 0 2 if (not defined $rlen) { }
0 2 elsif ($rlen == 0) { }
669 0 0 if ($conn->{'is_ssl'})
670 0 0 if ($! == 11)
671 0 0 if $IO::Socket::SSL::SSL_ERROR == 27308168
672 0 0 if $IO::Socket::SSL::SSL_ERROR == 27308240
679 0 0 if $! == 11 or $! == 4 or $! == 11
683 0 0 if ($content_length > 0) { }
691 2 0 if (not $decapitated and ($neck_pos = index($buf, "$YAHC::CRLF$YAHC::CRLF")) > 0)
695 0 2 if ($is_chunked and exists $headers->{'Trailer'}) { }
0 2 elsif (not $is_chunked || exists $headers->{'Content-Length'}) { }
708 1 1 if ($decapitated and $is_chunked) { }
0 1 elsif ($decapitated and ($conn->{'request'}{'method'} and $conn->{'request'}{'method'} eq 'HEAD')) { }
1 0 elsif ($decapitated and length $buf >= $content_length) { }
715 4 0 if ($neck_pos > 0) { }
723 4 0 if exists $conn->{'debug_or_timeline'}
724 1 3 if ($chunk_size == 0) { }
729 3 0 if (length $buf >= $chunk_size + $neck_pos + 2 + 2) { }
738 0 0 if $neck_pos < 0 and $chunk_size == 0
746 0 1 length $buf > $content_length ? :
755 1 2 if exists $self->{'stop_condition'}
765 0 3 unless my $conn = $self->{'connections'}{$conn_id}
770 2 1 if exists $conn->{'debug_or_timeline'}
771 1 2 if $error != 0
774 2 1 unless exists $conn->{'has_callback'}
777 0 0 $error ? :
0 1 if exists $conn->{'debug_or_timeline'}
781 0 1 unless (eval { do { _register_in_timeline($conn, 'call callback%s', $error ? " error=$error, strerror='${strerror}'" : '') if exists $conn->{'debug_or_timeline'}; my $cb = $self->{'callbacks'}{$conn_id}{'callback'}; &$cb($conn, $error, $strerror); 1 } })
790 0 1 if (yahc_terminal_error($error))
791 0 0 unless $state == 35 or $state == 100
797 0 1 if exists $conn->{'debug_or_timeline'}
799 0 1 if ($state == 0) { }
1 0 elsif ($state == 35 or $state == 100) { }
817 0 3 unless (defined $conn)
823 2 1 if exists $conn->{'debug_or_timeline'}
828 0 3 if exists $self->{'stop_condition'}
835 0 13 unless socket $sock, 2, 1, 0
838 0 13 unless my $flags = fcntl($sock, 3, 0)
839 0 13 unless fcntl $sock, 4, $flags | 2048
841 0 13 unless my $ip_addr = inet_aton($ip)
843 0 13 if (not connect($sock, $addr) and $! != 115)
855 11 6 if not $port and $host =~ /^(.+):([0-9]+)$/o
856 4 13 if not $ip and $host =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/o
869 0 20 unless my $watchers = $self->{'watchers'}{$conn->{'id'}}
870 7 13 unless my $fh = delete $watchers->{'_fh'}
883 0 0 if ($force_close or not defined $socket_cache or ($conn->{'request'}{'proto'} || '') eq 'HTTP/1.0' or ($conn->{'response'}{'proto'} || '') eq 'HTTP/1.0' or ($conn->{'response'}{'head'}{'Connection'} || '') eq 'close')
889 2 11 if $conn->{'debug_or_timeline'}
890 11 2 if ref $fh eq 'GLOB'
894 0 0 if $conn->{'debug_or_timeline'}
895 0 0 unless (eval { do { &$socket_cache(2, $conn, $fh); 1 } })
902 0 0 unless defined $conn
903 0 0 unless $conn->{'selected_target'}
904 0 0 unless $host and $port and $scheme
917 0 0 unless my $conn = $self->{'connections'}{$conn_id}
918 0 0 unless my $watchers = $self->{'watchers'}{$conn_id}
922 0 0 unless $timeout
925 0 0 if ($conn->{'state'} < $state) { }
929 0 0 if exists $conn->{'debug_or_timeline'}
933 0 0 if exists $conn->{'debug_or_timeline'}
944 0 0 unless my $conn = $self->{'connections'}{$conn_id}
945 0 0 unless my $watchers = $self->{'watchers'}{$conn_id}
949 0 0 unless $timeout
951 0 0 if exists $conn->{'debug_or_timeline'}
956 0 0 if $conn->{'state'} < 100
971 4 29 defined $request->{'query_string'} ? :
986 12 21 defined $request->{'body'} ? :
7 26 defined $request->{'head'} && @{$request->{'head'};} ? :
33 0 !$has_host ? :
12 21 defined $request->{'body'} ? :
1008 2 1 if ($conn->{'debug_or_timeline'})
1024 0 14 if (defined $watchers and my $w = $watchers->{'lifetime_timer'})
1035 7 3 if $ref eq ''
1036 1 2 if $ref eq 'CODE'
1040 2 0 if $ref eq 'ARRAY' and @$value > 0
1049 0 0 if $ref eq ''
1050 0 0 if $ref eq 'CODE'
1059 0 0 if $ref eq 'CODE'
1062 0 0 if ($operation == 1)
1063 0 0 unless my $socket_cache_id = yahc_conn_socket_cache_id($conn)
1067 0 0 if ($operation == 2)
1068 0 0 unless my $socket_cache_id = yahc_conn_socket_cache_id($conn)
1069 0 0 if exists $value->{$socket_cache_id}
1073 0 0 if $ref eq 'HASH'
1081 0 0 unless $cb
1083 0 0 if exists $conn->{'debug_or_timeline'}
1088 0 0 unless (eval { do { &$cb($conn); 1 } })
1101 0 15 unless (eval { do { &$sub(@_); 1 } })
1111 0 22 if exists $conn->{'debug'}
1112 22 0 if exists $conn->{'keep_timeline'}
1118 0 12 if exists $conn->{'debug_or_timeline'}
1124 1 14 if $state eq 0
1125 0 14 if $state eq 5
1126 1 13 if $state eq 10
1127 3 10 if $state eq 15
1128 1 9 if $state eq 25
1129 5 4 if $state eq 30
1130 0 4 if $state eq 20
1131 2 2 if $state eq 35
1132 2 0 if $state eq 100