Branch Coverage

blib/lib/YAHC.pm
Criterion Covered Total %
branch 204 480 42.5


line true false branch
15 0 20 $ENV{'YAHC_NO_SSL'} ? :
91 10 1 unless defined $LAST_CONNECTION_ID
93 0 11 if defined $args and ref $args ne 'HASH'
94 0 11 unless wantarray
98 2 9 if $args->{'host'}
99 0 11 if $args->{'backoff_delay'}
100 0 11 if $args->{'socket_cache'}
117 1 10 if (delete $args->{'account_for_signals'})
118 0 1 if $self->{'debug'}
128 0 16 unless @args
129 0 16 unless $self->{'storage'}
131 16 0 @args == 1 ? :
133 0 16 if exists $self->{'connections'}{$conn_id}
136 0 128 if $pool_args->{$_}
139 14 2 if ($request->{'host'}) { }
2 0 elsif ($pool_args->{'_target'}) { }
147 0 16 if ($request->{'backoff_delay'}) { }
0 16 elsif ($pool_args->{'_backoff'}) { }
153 0 16 if ($request->{'socket_cache'}) { }
0 16 elsif ($pool_args->{'_socket_cache'}) { }
169 0 16 $debug ? :
9 7 $keep_timeline ? :
9 7 $debug || $keep_timeline ? :
0 16 defined $user_data ? :
181 93 3 unless exists $request->{$_}
190 0 16 if $request->{'lifetime_timeout'}
192 13 3 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 2 4 ($_[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 1 unless $conn->{'errors'} and @{$conn->{'errors'};}
265 1 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 2 2 if @_
309 0 11 unless $self->{'storage'}
310 0 11 if $self->{'loop'}->depth
312 0 11 if ($self->{'pid'} != $$)
313 0 0 if $self->{'debug'}
318 0 0 if $active_connections
322 2 9 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 11 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 16 unless my $conn = $self->{'connections'}{$conn_id}
382 1 15 if exists $conn->{'debug_or_timeline'}
383 0 16 if exists $conn->{'has_init_callback'}
389 2 14 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 14 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 14 unless my $conn = $self->{'connections'}{$conn_id}
441 0 14 unless my $watchers = $self->{'watchers'}{$conn_id}
447 0 14 if $request->{'request_timeout'}
449 0 14 if $request->{'connect_timeout'}
451 0 14 if $request->{'drain_timeout'}
456 1 13 if exists $conn->{'debug_or_timeline'}
459 0 14 if (my $socket_cache = $request->{'_socket_cache'})
463 0 14 if (defined $sock) { }
464 0 0 if $conn->{'debug_or_timeline'}
469 1 13 if $conn->{'debug_or_timeline'}
475 0 14 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 14 unless my $conn = $self->{'connections'}{$conn_id}
489 0 14 unless my $watchers = $self->{'watchers'}{$conn_id}
492 1 13 if exists $conn->{'debug_or_timeline'}
493 0 14 if exists $conn->{'has_connecting_callback'}
497 0 13 unless ($sockopt)
503 12 1 if (my $err = unpack('L', $sockopt))
515 0 14 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 == 62303200
579 0 0 if $IO::Socket::SSL::SSL_ERROR == 62303272
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 == 62303200
620 0 0 if $IO::Socket::SSL::SSL_ERROR == 62303272
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 8 unless my $conn = $self->{'connections'}{$conn_id}
650 0 8 unless my $watchers = $self->{'watchers'}{$conn_id}
653 8 0 if exists $conn->{'debug_or_timeline'}
654 0 8 if exists $conn->{'has_reading_callback'}
669 0 9 if (not defined $rlen) { }
2 7 elsif ($rlen == 0) { }
670 0 0 if ($conn->{'is_ssl'})
671 0 0 if ($! == 11)
672 0 0 if $IO::Socket::SSL::SSL_ERROR == 62303200
673 0 0 if $IO::Socket::SSL::SSL_ERROR == 62303272
680 0 0 if $! == 11 or $! == 4 or $! == 11
684 2 0 if ($no_content_length)
690 0 0 if ($content_length > 0) { }
698 7 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 7 if (($conn->{'request'}{'method'} || '') eq 'HEAD' or $conn->{'response'}{'status'} =~ /^(1..|204|304)$/) { }
1 6 elsif ($is_chunked) { }
4 2 elsif (exists $headers->{'content-length'}) { }
717 1 3 unless ($content_length =~ /\A[0-9]+\z/)
727 1 5 if ($decapitated and $is_chunked) { }
3 4 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 1 2 length $buf > $content_length ? :
772 1 7 if exists $self->{'stop_condition'}
782 0 9 unless my $conn = $self->{'connections'}{$conn_id}
787 7 2 if exists $conn->{'debug_or_timeline'}
788 3 6 if $error != 0
791 7 2 unless exists $conn->{'has_callback'}
794 0 0 $error ? :
0 2 if exists $conn->{'debug_or_timeline'}
798 0 2 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 2 if (yahc_terminal_error($error))
808 0 0 unless $state == 35 or $state == 100
814 0 2 if exists $conn->{'debug_or_timeline'}
816 0 2 if ($state == 0) { }
2 0 elsif ($state == 35 or $state == 100) { }
834 0 9 unless (defined $conn)
840 7 2 if exists $conn->{'debug_or_timeline'}
845 0 9 if exists $self->{'stop_condition'}
852 0 14 unless socket $sock, 2, 1, 0
855 0 14 unless my $flags = fcntl($sock, 3, 0)
856 0 14 unless fcntl $sock, 4, $flags | 2048
858 0 14 unless my $ip_addr = inet_aton($ip)
860 0 14 if (not connect($sock, $addr) and $! != 115)
872 12 6 if not $port and $host =~ /^(.+):([0-9]+)$/o
873 4 14 if not $ip and $host =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/o
886 0 34 unless my $watchers = $self->{'watchers'}{$conn->{'id'}}
887 15 19 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 7 12 if $conn->{'debug_or_timeline'}
907 12 7 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 7 1 if ($conn->{'debug_or_timeline'})
1041 0 16 if (defined $watchers and my $w = $watchers->{'lifetime_timer'})
1052 12 4 if $ref eq ''
1053 1 3 if $ref eq 'CODE'
1057 3 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 23 unless (eval { do { &$sub(@_); 1 } })
1128 0 48 if exists $conn->{'debug'}
1129 48 0 if exists $conn->{'keep_timeline'}
1135 1 14 if exists $conn->{'debug_or_timeline'}
1141 1 29 if $state eq 0
1142 0 29 if $state eq 5
1143 1 28 if $state eq 10
1144 3 25 if $state eq 15
1145 1 24 if $state eq 25
1146 10 14 if $state eq 30
1147 0 14 if $state eq 20
1148 7 7 if $state eq 35
1149 7 0 if $state eq 100