Branch Coverage

blib/lib/Net/Server.pm
Criterion Covered Total %
branch 203 458 44.3


line true false branch
55 3 94 @_ == 1 ? :
64 8 88 ref $_[0] ? :
65 3 93 @_ == 1 ? :
91 32 0 if ($ok) { }
108 96 3 unless eval { do { local $SIG{'__DIE__'}; $self->commandline } }
112 0 99 unless $self->default_values
113 20 79 if @defaults
118 96 0 ref $_[0] ? :
96 99 if @_
125 96 0 if $script =~ m[^[^/]+/] and $ENV{'PWD'}
135 28 99 $_[0] && ref $_[0] ? :
137 4 123 if @ARGV
138 127 0 if $prop->{'_run_args'}
140 8 119 if ($prop->{'conf_file'}) { }
144 1 118 if $def->{'conf_file'}
154 96 0 unless defined $prop->{'log_level'} and $prop->{'log_level'} =~ /^\d+$/
155 0 96 if $prop->{'log_level'} > 4
158 0 96 if ($prop->{'pid_file'})
159 0 0 unless (eval { do { &check_pid_file($prop->{'pid_file'}) } })
160 0 0 unless $ENV{'BOUND_SOCKETS'}
165 95 1 unless ($prop->{'_is_inet'})
166 0 95 if ($prop->{'setsid'} or length $prop->{'log_file'})
167 0 0 unless open STDIN, "<", "/dev/null"
168 0 0 unless open STDOUT, ">", "/dev/null"
172 96 0 unless ($ENV{'BOUND_SOCKETS'})
173 0 96 if ($prop->{'setsid'} or $prop->{'background'})
175 0 0 unless defined $pid
176 0 0 if $pid
180 0 96 if $prop->{'setsid'}
183 0 96 if (length $prop->{'log_file'} and not $prop->{'log_function'}) { }
0 96 elsif ($prop->{'setsid'}) { }
192 0 96 if ($prop->{'pid_file'})
193 0 0 if (eval { do { &create_pid_file($prop->{'pid_file'}) } }) { }
203 0 96 if $prop->{'double_reverse_lookups'}
205 0 96 if $prop->{'reverse_lookups'} and $prop->{'reverse_lookups'} =~ /^(?:double|2)(.*)$/i
211 96 0 unless (defined $prop->{'log_file'})
217 0 0 if (my $code = $prop->{'log_function'}) { }
0 0 elsif ($prop->{'log_file'} =~ /^([a-zA-Z]\w*(?:::[a-zA-Z]\w*)*)$/) { }
218 0 0 if (ref $code ne "CODE")
220 0 0 unless $self->can($code)
228 0 0 if (eval { do { require $file } }) { }
0 0 elsif ($file =~ /::/ or grep {-e "$_/$file";} @INC) { }
238 0 0 unless $prop->{'log_file'} =~ m(^([\:\w\.\-/\\]+)$)
240 0 0 unless open _SERVER_LOG, ">>", $prop->{'log_file'}
256 3 92 if ($self->isa("Net::Server::MultiType"))
260 95 0 if $type ne $super
264 0 95 if not @{$prop->{'sock'};}
273 7 88 if (not defined $ports or ref $ports and not @$ports)
275 0 7 if (not defined $ports or ref $ports and not @$ports)
283 88 7 ref $ports ? :
284 97 33 @$bind >= @$hosts ? :
130 0 ref $hosts ? :
285 119 11 @$bind >= @$protos ? :
130 0 ref $protos ? :
286 103 27 @$bind >= @$ipvs ? :
130 0 ref $ipvs ? :
289 0 136 if ($port ne 0 and $bound{"$host\e$port\e$proto\e$ipv"}++)
314 0 25 if (exists $ENV{'BOUND_SOCKETS'}) { }
320 0 0 unless defined $orig
321 0 0 $fd =~ /^(\d+)$/ ? :
326 0 0 if (my $ref = $map{$sock->hup_string}) { }
330 0 0 unless keys %$ref
352 10 15 if (@{$prop->{'sock'};} > 1 or $prop->{'multi_port'}) { }
369 26 0 if (not defined $prop->{'group'}) { }
0 0 elsif ($prop->{'group'} =~ /^([\w.-]+(?:[ ,][\w.-]+)*)$/) { }
374 0 0 if $@
379 26 0 if (not defined $prop->{'user'}) { }
0 0 elsif ($prop->{'user'} =~ /^([\w.-]+)$/) { }
384 0 0 if $@
390 0 26 if ($prop->{'group'} ne $) or $prop->{'user'} ne $>)
393 0 0 if $prop->{'pid_file_unlink'}
394 0 0 if $prop->{'lock_file_unlink'}
395 0 0 unless $prop->{'chown_files'}
399 0 0 unless chown $uid, $gid, $file
403 0 26 if ($prop->{'chroot'})
404 0 0 unless -d $prop->{'chroot'}
406 0 0 unless chroot $prop->{'chroot'}
411 0 26 if ($prop->{'group'} ne $))
415 0 26 if ($prop->{'user'} ne $>)
420 0 26 if ($@)
421 0 0 if ($> == 0) { }
0 0 elsif ($< == 0) { }
449 2 9 if $self->done
460 16 16 if ($prop->{'multi_port'}) { }
461 0 16 if $prop->{'_HUP'}
463 0 15 if $prop->{'_HUP'}
464 0 15 if ($self->can_read_hook($sock))
471 0 31 unless defined $sock
473 1 30 if (&SOCK_DGRAM() == $sock->getsockopt(&SOL_SOCKET(), &SO_TYPE())) { }
483 0 31 if $prop->{'_HUP'}
484 31 0 if $prop->{'client'}
497 0 15 unless @waiting
509 1 30 if $prop->{'udp_true'}
511 0 30 unless ($client)
516 5 25 if $client->can("post_accept")
517 29 1 if (not $prop->{'no_client_stdout'})
520 6 23 if ($prop->{'tie_client_stdout'} or $client->can('tie_stdout') and $client->tie_stdout) { }
23 0 elsif (defined(my $fileno = fileno $prop->{'client'})) { }
521 0 6 unless open STDIN, "<", "/dev/null"
522 0 6 unless open STDOUT, ">", "/dev/null"
523 0 6 unless tie *STDOUT, "Net::Server::TiedHandle", $client, $prop->{'tied_stdout_callback'}
524 0 6 unless tie *STDIN, "Net::Server::TiedHandle", $client, $prop->{'tied_stdin_callback'}
526 0 23 unless open STDIN, "<&", $fileno
527 0 23 unless open STDOUT, ">&", $fileno
543 0 31 if ($client->NS_proto =~ /^UNIX/)
545 0 0 if $prop->{'log_level'} and 3 <= $prop->{'log_level'}
549 31 0 if (my $sockname = $client->sockname) { }
557 1 30 $prop->{'udp_true'} ? :
31 0 if (my $peer = $prop->{'udp_true'} ? $prop->{'udp_peer'} : eval { do { $client->peername } }) { }
558 31 0 if (my $family = sockaddr_family($prop->{'peername'} = $peer))
559 19 12 if ($family == 2) { }
12 0 elsif (eval { do { ipv6_package($self) } }) { }
574 0 31 if ($addr and $prop->{'reverse_lookups'})
575 0 0 if ($client->can('peerhostname')) { }
0 0 elsif ($prop->{'peername'} and my(@res) = safe_name_info($prop->{'peername'}, 0)) { }
578 0 0 if @res > 1 and not $res[0]
582 0 0 if ($prop->{'peerhost'} and $prop->{'double_reverse_lookups'})
590 0 0 $prop->{'peerhost'} ? :
0 31 if $prop->{'log_level'} and 3 <= $prop->{'log_level'}
601 0 32 if $sock and $sock->NS_proto =~ /^UNIX/
605 1 31 $prop->{'peeraddr'} =~ /^\s*::ffff:(\d+(?:\.\d+){3})$/ ? :
607 0 32 if ($prop->{'double_reverse_lookups'})
608 0 0 unless $self->double_reverse_lookup($peeraddr, $prop->{'peerhost'}, $prop->{'peerhost_rev'}, $prop->{'peeraddr'})
615 32 0 unless @{$prop->{'allow'};} or @{$prop->{'deny'};} or @{$prop->{'cidr_allow'};} or @{$prop->{'cidr_deny'};}
620 0 0 if $prop->{'reverse_lookups'} and defined $prop->{'peerhost'} and $prop->{'peerhost'} =~ /^$_$/
621 0 0 if $peeraddr =~ /^$_$/
623 0 0 if (@{$prop->{'cidr_deny'};})
625 0 0 if Net::CIDR::cidrlookup($peeraddr, @{$$prop{"cidr_deny"};})
631 0 0 if $prop->{'reverse_lookups'} and defined $prop->{'peerhost'} and $prop->{'peerhost'} =~ /^$_$/
632 0 0 if $peeraddr =~ /^$_$/
634 0 0 if (@{$prop->{'cidr_allow'};})
636 0 0 if Net::CIDR::cidrlookup($peeraddr, @{$$prop{"cidr_allow"};})
645 0 0 if (not $host) { }
0 0 elsif (not $rev_addrs) { }
652 0 0 $orig_addr && $orig_addr ne $addr ? :
653 0 0 if (not $rev_addrs->{$addr} || $rev_addrs->{$orig_addr}) { }
0 0 elsif ($cfg =~ /autofail/i) { }
0 0 elsif ($cfg =~ /debug/) { }
654 0 0 $cfg =~ /detail/i ? :
674 1 26 if ($prop->{'udp_true'})
676 0 1 if ($prop->{'udp_data'} =~ /dump/)
691 0 22 if (/get\s+(\w+)/) { }
0 22 elsif (/dump/) { }
3 19 elsif (/quit/) { }
19 0 elsif (/exit/) { }
700 0 7 if $@ eq "Timed Out!\n"
715 1 11 if $prop->{'udp_true'}
717 10 1 unless ($prop->{'no_client_stdout'})
718 4 6 if ($t)
719 4 6 if ($t)
720 0 10 unless open STDIN, "<", "/dev/null"
721 0 10 unless open STDOUT, ">", "/dev/null"
728 0 9 if @_
741 0 0 unless defined $pid
742 0 0 unless ($pid)
756 0 0 if $self->{'server'}{'children'}
777 0 3 if (defined $prop->{'ppid'} and $prop->{'ppid'} != $$ and not defined $prop->{'no_close_by_child'})
788 0 0 if ($prop->{'kind_quit'} and $prop->{'children'})
794 0 0 if $self->can("coordinate_children")
795 0 0 unless keys %{$$self{"server"}{"children"};}
800 0 25 if ($prop->{'_HUP'} and $prop->{'leave_children_open_on_hup'}) { }
804 3 22 if $prop->{'children'}
808 2 0 if (defined $prop->{'lock_file'} and -e $prop->{'lock_file'} and defined $prop->{'lock_file_unlink'})
811 0 2 unless unlink $prop->{'lock_file'}
813 0 0 if (defined $prop->{'pid_file'} and -e $prop->{'pid_file'} and not $prop->{'_HUP'} and defined $prop->{'pid_file_unlink'})
817 0 0 unless unlink $prop->{'pid_file'}
819 0 25 if (defined $prop->{'sem'})
823 0 25 if ($prop->{'_HUP'})
829 0 25 if $prop->{'no_exit_on_close'}
844 0 34 if $sock->NS_proto =~ /^UNIX/
856 0 0 unless $prop->{'ppid'}
865 0 3 unless $prop->{'children'} and scalar keys %{$$prop{"children"};}
869 4 0 if (kill "TERM", $pid or not kill(0, $pid))
883 0 0 unless defined $prop->{'children'} and scalar keys %{$$prop{"children"};}
884 0 0 unless $self->is_prefork
889 0 0 unless kill "HUP", $pid
913 0 0 unless $prop->{'_HUP'}[$i]->fdopen($fd, "w")
927 0 0 if ($prop->{'leave_children_open_on_hup'} and scalar keys %{$$prop{"children"};})
963 0 184 unless $prop->{'log_level'}
964 38 146 if $level =~ /^\d+$/ and $level > $prop->{'log_level'}
965 0 146 if @therest
967 5 141 if ($prop->{'log_function'})
968 5 0 if eval { do { $prop->{'log_function'}->($level, $msg); 1 } }
970 0 0 if ($prop->{'log_class'} and $prop->{'log_class'}->can('handle_error')) { }
977 0 141 unless $level =~ /^\d+$/
991 0 141 if ($prop->{'log_file'}) { }
0 141 elsif ($prop->{'setsid'}) { }
1016 760 296 if (not defined $prop->{$_}) { }
8 288 elsif (not ref $prop->{$_}) { }
1042 132 28 unless $template and ref $template
1043 0 0 unless ($_[2] or scalar keys %$template or $self->{'server'}{'_no_options'}++)
1050 404 13 if ($args->[$i] =~ /^(?:--)?(\w+)(?:[=\ ](\S+))?$/ and exists $template->{$1})
1054 401 3 unless (defined $val)
1055 0 401 if ($i > $args->$#* or $args->[$i] and $args->[$i] =~ /^--\w+/) { }
1060 0 41 if ref $val eq "ARRAY" and @$val == 1 and ref $template->{$key} ne "ARRAY"
1064 354 50 unless ref $val
1066 240 164 if (ref $template->{$key} eq 'ARRAY') { }
1067 198 42 unless (defined $previously_set{$key})
1070 12 228 if $previously_set{$key}
1071 41 187 ref $val eq 'ARRAY' ? :
1073 146 18 unless (defined $previously_set{$key})
1074 24 122 defined ${$$template{$key};} ? :
1076 27 137 if $previously_set{$key}
1077 0 137 if ref $val eq "ARRAY"
1087 9 0 $file =~ m[^([\w\.\-\/\\\:]+)$] ? :
1088 0 9 unless (open my $fh, "<", $file)
1089 0 0 if $ENV{'BOUND_SOCKETS'}
1093 54 135 if $line =~ /(.*?)(?
1095 99 90 if $line =~ /^\s*((?:--)?\w+)(?:\s*[=:]\s*|\s+)(.+)/
1111 0 4 unless exists $prop->{'children'}{$pid}
1114 1 3 if ($prop->{'child_communication'})
1115 1 0 if ($prop->{'children'}{$pid}{'sock'})
1131 0 0 unless kill $sig, $chld
1139 0 3 unless ref $ref
1140 0 3 if ref $ref ne "ARRAY"
1141 3 0 unless @$ref
1146 0 0 if ($code) { }
1149 0 0 ref $SIG{$sig} eq 'CODE' ? :
1151 0 0 if $code
1160 0 3 $s->[1] ? :
1161 0 0 $s->[1] ? :
1162 3 8 $s->[1] ? :
1163 0 0 $s->[1] ? :
1164 0 1 $s->[1] ? :
1165 0 1 $s->[1] ? :
1166 0 0 $s->[1] ? :
1167 0 0 $s->[1] ? :
1168 0 0 $s->[1] ? :
1171 0 0 $s->[1] ? :