Branch Coverage

blib/lib/YAHC.pm
Criterion Covered Total %
branch 192 480 40.0


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 == 46182808
579 0 0 if $IO::Socket::SSL::SSL_ERROR == 46182880
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 == 46182808
620 0 0 if $IO::Socket::SSL::SSL_ERROR == 46182880
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'}
669 0 2 if (not defined $rlen) { }
0 2 elsif ($rlen == 0) { }
670 0 0 if ($conn->{'is_ssl'})
671 0 0 if ($! == 11)
672 0 0 if $IO::Socket::SSL::SSL_ERROR == 46182808
673 0 0 if $IO::Socket::SSL::SSL_ERROR == 46182880
680 0 0 if $! == 11 or $! == 4 or $! == 11
684 0 0 if ($no_content_length)
690 0 0 if ($content_length > 0) { }
698 2 0 if (not $decapitated and ($neck_pos = index($buf, "$YAHC::CRLF$YAHC::CRLF")) > 0)
702 0 1 if ($is_chunked and exists $headers->{'Trailer'})
711 0 2 if (($conn->{'request'}{'method'} || '') eq 'HEAD' or $conn->{'response'}{'status'} =~ /^(1..|204|304)$/) { }
1 1 elsif ($is_chunked) { }
1 0 elsif (exists $headers->{'Content-Length'}) { }
717 0 1 unless ($content_length =~ /\A[0-9]+\z/)
727 1 1 if ($decapitated and $is_chunked) { }
1 0 elsif ($decapitated and not $no_content_length and length $buf >= $content_length) { }
734 4 0 if ($neck_pos > 0) { }
742 4 0 if exists $conn->{'debug_or_timeline'}
743 1 3 if ($chunk_size == 0) { }
748 3 0 if (length $buf >= $chunk_size + $neck_pos + 2 + 2) { }
757 0 0 if $neck_pos < 0 and $chunk_size == 0
763 0 1 length $buf > $content_length ? :
772 1 2 if exists $self->{'stop_condition'}
782 0 3 unless my $conn = $self->{'connections'}{$conn_id}
787 2 1 if exists $conn->{'debug_or_timeline'}
788 1 2 if $error != 0
791 2 1 unless exists $conn->{'has_callback'}
794 0 0 $error ? :
0 1 if exists $conn->{'debug_or_timeline'}
798 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 } })
807 0 1 if (yahc_terminal_error($error))
808 0 0 unless $state == 35 or $state == 100
814 0 1 if exists $conn->{'debug_or_timeline'}
816 0 1 if ($state == 0) { }
1 0 elsif ($state == 35 or $state == 100) { }
834 0 3 unless (defined $conn)
840 2 1 if exists $conn->{'debug_or_timeline'}
845 0 3 if exists $self->{'stop_condition'}
852 0 13 unless socket $sock, 2, 1, 0
855 0 13 unless my $flags = fcntl($sock, 3, 0)
856 0 13 unless fcntl $sock, 4, $flags | 2048
858 0 13 unless my $ip_addr = inet_aton($ip)
860 0 13 if (not connect($sock, $addr) and $! != 115)
872 11 6 if not $port and $host =~ /^(.+):([0-9]+)$/o
873 4 13 if not $ip and $host =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/o
886 0 20 unless my $watchers = $self->{'watchers'}{$conn->{'id'}}
887 7 13 unless my $fh = delete $watchers->{'_fh'}
900 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')
906 2 11 if $conn->{'debug_or_timeline'}
907 11 2 if ref $fh eq 'GLOB'
911 0 0 if $conn->{'debug_or_timeline'}
912 0 0 unless (eval { do { &$socket_cache(2, $conn, $fh); 1 } })
919 0 0 unless defined $conn
920 0 0 unless $conn->{'selected_target'}
921 0 0 unless $host and $port and $scheme
934 0 0 unless my $conn = $self->{'connections'}{$conn_id}
935 0 0 unless my $watchers = $self->{'watchers'}{$conn_id}
939 0 0 unless $timeout
942 0 0 if ($conn->{'state'} < $state) { }
946 0 0 if exists $conn->{'debug_or_timeline'}
950 0 0 if exists $conn->{'debug_or_timeline'}
961 0 0 unless my $conn = $self->{'connections'}{$conn_id}
962 0 0 unless my $watchers = $self->{'watchers'}{$conn_id}
966 0 0 unless $timeout
968 0 0 if exists $conn->{'debug_or_timeline'}
973 0 0 if $conn->{'state'} < 100
988 4 29 defined $request->{'query_string'} ? :
1003 12 21 defined $request->{'body'} ? :
7 26 defined $request->{'head'} && @{$request->{'head'};} ? :
33 0 !$has_host ? :
12 21 defined $request->{'body'} ? :
1025 2 1 if ($conn->{'debug_or_timeline'})
1041 0 14 if (defined $watchers and my $w = $watchers->{'lifetime_timer'})
1052 7 3 if $ref eq ''
1053 1 2 if $ref eq 'CODE'
1057 2 0 if $ref eq 'ARRAY' and @$value > 0
1066 0 0 if $ref eq ''
1067 0 0 if $ref eq 'CODE'
1076 0 0 if $ref eq 'CODE'
1079 0 0 if ($operation == 1)
1080 0 0 unless my $socket_cache_id = yahc_conn_socket_cache_id($conn)
1084 0 0 if ($operation == 2)
1085 0 0 unless my $socket_cache_id = yahc_conn_socket_cache_id($conn)
1086 0 0 if exists $value->{$socket_cache_id}
1090 0 0 if $ref eq 'HASH'
1098 0 0 unless $cb
1100 0 0 if exists $conn->{'debug_or_timeline'}
1105 0 0 unless (eval { do { &$cb($conn); 1 } })
1118 0 15 unless (eval { do { &$sub(@_); 1 } })
1128 0 22 if exists $conn->{'debug'}
1129 22 0 if exists $conn->{'keep_timeline'}
1135 0 12 if exists $conn->{'debug_or_timeline'}
1141 1 14 if $state eq 0
1142 0 14 if $state eq 5
1143 1 13 if $state eq 10
1144 3 10 if $state eq 15
1145 1 9 if $state eq 25
1146 5 4 if $state eq 30
1147 0 4 if $state eq 20
1148 2 2 if $state eq 35
1149 2 0 if $state eq 100