Proc/Parallel/RemoteKiller.pm

filter: Statementstmt 25.8% 15 / 58 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 41.6% 5 / 12 Podpod 0.0% 0 / 5 totaltotal 19.4% 20 / 103 CC 14 SCAR 33.4
CC
14
Cov
18%
kill_them_all
72.0
forget
20.0
END
7.6
CRAP 28.1
« Proc/Parallel/Unreliable.pm ↑ Summary RPC/ToWorker/Callback.pm »
1  
2 package Proc::Parallel::RemoteKiller;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Slurp::Remote::BrokenDNS qw($myfqdn %fqdnify);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 my %active;
10  
11 sub new
12 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my $pkg = shift;
14 0 my $self = bless { hosts => {} }, $pkg;
15 0 $self->{old_sig} = $SIG{INT};
16 0 ▶ $SIG{INT} = sub { $self->kill_them_all };
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 $active{"$self"} = $self;
18 0 weaken($active{"$self"});
19 0 return $self;
20 }
21  
22 sub note
23 0 ▶{
Subroutine note: not called CC=2 SCAR=17.9
Pod undocumented
24 0 my ($self, $host, $pid) = @_;
25 0 ▶ $host = $myfqdn unless defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 0 0
26 0 my $precache_answer = $fqdnify{$host};
27 0 $self->{hosts}{$host}{$pid} = 1;
28 }
29  
30 sub forget
31 0 ▶{
Subroutine forget: not called CC=4 SCAR=30.0
Pod undocumented
32 0 my ($self, $host, $pid) = @_;
33 0 ▶ return unless defined($host) && defined($pid);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host and defined $pid 0 0 0
Condition0%0/3
defined $host and defined $pid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $host and defined $pid
defined $host defined $pid
Truth table0%0/3
A and B
A= defined $hostB= defined $pid
ABresult
0X0
100
111
34 0 delete $self->{hosts}{$host}{$pid};
35 0 ▶ delete $self->{hosts}{$host} unless keys %{$self->{hosts}{$host}};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$self{"hosts"}{$host};} 0 0 0
36 }
37  
38 sub forget_all
39 0 ▶{
Subroutine forget_all: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ($self) = @_;
41 0 $self->{hosts} = {};
42 }
43  
44 sub kill_them_all
45 0 ▶{
Subroutine kill_them_all: not called CC=8 SCAR=42.8
Pod undocumented
46 0 my ($self, $do_not_exit) = @_;
47  
48 0 ▶ print STDERR "Bailing out!\n" unless $do_not_exit;
Branch: 1 branch
BranchTrueFalseTotal
unless $do_not_exit 0 0 0
49  
50 0 my $x = "set -x\n";
51 0 my $wait = 0;
52 0 my $do = 0;
53 0 for my $host (keys %{$self->{hosts}}) {
54 0 my @pids = keys %{$self->{hosts}{$host}};
55 0 delete $self->{hosts}{$host};
56 0 ▶ next unless @pids;
Branch: 1 branch
BranchTrueFalseTotal
unless @pids 0 0 0
57 0 ▶ if ($fqdnify{$host} eq $myfqdn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::Parallel::RemoteKiller::fqdnify{$host} eq $Proc::Parallel::RemoteKiller::myfqdn) { } 0 0 0
58 0 $x .= "kill @pids\n";
59 0 $do = 1;
60 } else {
61 0 $x .= "ssh -o StrictHostKeyChecking=no $host -n kill @pids &\n";
62 0 $wait = 1;
63 }
64 }
65 0 ▶ $x .= "wait\n" if $wait;
Branch: 1 branch
BranchTrueFalseTotal
if $wait 0 0 0
66 0 ▶ system($x) if $do || $wait;
Branch: 1 branch
BranchTrueFalseTotal
if $do or $wait 0 0 0
Condition0%0/3
$do or $wait
l!l&&r!l&&!r
000
MC/DC0%0/2
$do or $wait
$do $wait
Truth table0%0/3
A or B
A= $doB= $wait
ABresult
1X1
011
000
67 0 exit(0);
68 }
69  
70 sub DESTROY
71 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
72 0 my ($self) = @_;
73 0 delete $SIG{INT};
74 # $self->kill_them_all(1);
75 0 delete $active{"$self"};
76 }
77  
78 1 ▶END {
Subroutine END: called CC=3 SCAR=20.3
79 1 for my $rk (values %active) {
80 0 ▶ next unless $rk;
Branch: 1 branch
BranchTrueFalseTotal
unless $rk 0 0 0
81 0 $rk->kill_them_all(1);
82 }
83 }
84  
85  
86 1 1;
87  
88 __END__
« Proc/Parallel/Unreliable.pm ↑ Summary RPC/ToWorker/Callback.pm »