blib/lib/Clustericious/Admin/RemoteHandler.pm

filter: Statementstmt 88.3% 68 / 77 Branchbran 77.5% 31 / 40 Conditioncond 70.0% 21 / 30 MC/DCmcdc 50.0% 9 / 18 Subroutinesub 85.7% 18 / 21 Podpod 0.0% 0 / 11 totaltotal 74.6% 147 / 197 CC 31 SCAR 22.1
CC
31
Cov
82%
print_line
20.0
__ANON__
7.2
color
6.0
CRAP 9.2
« blib/lib/App/clad.pm ↑ Summary /usr/local/bin/perldoc »
1 package Clustericious::Admin::RemoteHandler;
2  
3 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use AE;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 39 ▶use AnyEvent::Open3::Simple 0.76;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 39 our $VERSION = '1.11'; # VERSION
10  
11 sub new
12 30 ▶{
Subroutine new: called CC=4 SCAR=14.1
Pod undocumented
13 30 my($class, %args) = @_;
14
15 # args: prefix, clad, user, host, payload
16
17 my $self = bless {
18 prefix => $args{prefix},
19 clad => $args{clad},
20 cv => AE::cv,
21 summary => $args{clad}->summary,
22 30 }, $class;
23
24 30 my $clad = $args{clad};
25
26 # TODO: handle the same host multiple times
27 30 ▶ if($clad->log_dir)
Branch: 1 branch
BranchTrueFalseTotal
if ($clad->log_dir) 3 27 30
28 {
29 3 my $fn = $clad->log_dir->file($args{prefix} . ".log");
30 3 ▶ open(my $fh, '>', "$fn")
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$fn" or die "unable to write to $fn $!" 3 0 3
31 || die "unable to write to $fn $!";
32 3 $self->{logfile} = $fh;
33 3 $self->{logfilename} = $fn;
34 }
35
36 30 my $done = $self->{cv};
37
38 my $ipc = AnyEvent::Open3::Simple->new(
39 30 ▶ on_start => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
40 30 my($proc, $program, @args) = @_;
41 30 ▶ $self->print_line(star => "% $program @args") if $clad->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $clad->verbose 0 30 30
42 },
43 35 ▶ on_stdout => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 35 my($proc, $line) = @_;
45 35 $self->print_line(out => $line);
46 },
47 6 ▶ on_stderr => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 6 my($proc, $line) = @_;
49 6 $self->print_line(err => $line);
50 },
51 30 ▶ on_exit => sub {
Subroutine __ANON__: called CC=7 SCAR=19.7
52 30 my($proc, $exit, $signal) = @_;
53 30 ▶ $self->print_line(exit => $exit) if ($self->summary && !$signal) || $exit;
Branch: 1 branch
BranchTrueFalseTotal
if $self->summary and not $signal or $exit 6 24 30
Condition83%5/6
$self->summary and not $signal or $exit
l!l&&r!l&&!r
3324
$self->summary and not $signal
!ll&&!rl&&r
2703
MC/DC66%2/3
$self->summary and not $signal or $exit
$self->summary not $signal $exit
Truth table60%3/5
A and not(B) or C
A= $self->summaryB= not $signalC= $exit
ABCresult
11X1
0X11
1011
0X00
1000
54 30 ▶ $self->print_line(sig => $signal) if $signal;
Branch: 1 branch
BranchTrueFalseTotal
if $signal 0 30 30
55 30 ▶ $clad->ret(2) if $exit || $signal;
Branch: 1 branch
BranchTrueFalseTotal
if $exit or $signal 4 26 30
Condition66%2/3
$exit or $signal
l!l&&r!l&&!r
4026
MC/DC50%1/2
$exit or $signal
$exit $signal
Truth table66%2/3
A or B
A= $exitB= $signal
ABresult
1X1
011
000
56 30 $self->cleanup;
57 },
58 0 ▶ on_error => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 my($error) = @_;
60 0 $self->print_line(fail => $error);
61 0 $clad->ret(2);
62 0 $self->cleanup;
63 },
64 30 );
65
66 $ipc->run(
67 $clad->ssh_command,
68 $clad->ssh_options,
69 $clad->ssh_extra,
70 ($args{user} ? ('-l' => $args{user}) : ()),
71 $args{host},
72 $clad->server_command,
73 \$args{payload},
74 30 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'user'} ? : 9 21 30
75  
76 30 $self;
77 }
78  
79 69 ▶sub clad { shift->{clad} }
Subroutine clad: called CC=1 SCAR=0.0
Pod undocumented
80 41 ▶sub prefix { shift->{prefix} }
Subroutine prefix: called CC=1 SCAR=0.0
Pod undocumented
81 77 ▶sub summary { shift->{summary} }
Subroutine summary: called CC=1 SCAR=0.0
Pod undocumented
82 80 ▶sub logfile { shift->{logfile} }
Subroutine logfile: called CC=1 SCAR=0.0
Pod undocumented
83 0 ▶sub logfilename { shift->{logfilename} }
Subroutine logfilename: not called CC=1 SCAR=6.9
Pod undocumented
84  
85 sub cleanup
86 30 ▶{
Subroutine cleanup: called CC=2 SCAR=6.9
Pod undocumented
87 30 my($self) = @_;
88 30 ▶ $self->logfile->close if $self->logfile;
Branch: 1 branch
BranchTrueFalseTotal
if $self->logfile 3 27 30
89 30 $self->{cv}->send;
90 }
91  
92 sub color
93 0 ▶{
Subroutine color: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my($self) = @_;
95 0 ▶ $self->{color} //= $self->clad->next_color;
Condition0%0/3
$self->{"color"} //= $self->clad->next_color
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"color"} //= $self->clad->next_color
$self->{"color"} $self->clad->next_color
Truth table0%0/3
A //= B
A= $self->{"color"}B= $self->clad->next_color
ABresult
1X1
011
000
96 }
97  
98 sub is_color
99 88 ▶{
Subroutine is_color: called CC=2 SCAR=7.1
Pod undocumented
100 88 my($self) = @_;
101 88 ▶ $self->{is_color} //= $self->clad->color;
Condition66%2/3
$self->{"is_color"} //= $self->clad->color
l!l&&r!l&&!r
60280
MC/DC0%0/2
$self->{"is_color"} //= $self->clad->color
$self->{"is_color"} $self->clad->color
Truth table66%2/3
A //= B
A= $self->{"is_color"}B= $self->clad->color
ABresult
1X1
011
000
102 }
103  
104 sub print_line
105 47 ▶{
Subroutine print_line: called CC=18 SCAR=30.0
Pod undocumented
106 47 my($self, $code, $line) = @_;
107  
108 47 my $fh = $self->logfile;
109 47 ▶ printf $fh "[%-4s] %s\n", $code, $line
Branch: 1 branch
BranchTrueFalseTotal
if $fh 6 41 47
110 if $fh;
111
112 47 my $last_line = $code =~ /^(exit|sig|fail)$/;
113
114 47 ▶ return if $self->summary && ! $last_line;
Branch: 1 branch
BranchTrueFalseTotal
if $self->summary and not $last_line 6 41 47
Condition100%3/3
$self->summary and not $last_line
!ll&&!rl&&r
3836
MC/DC100%2/2
$self->summary and not $last_line
$self->summary not $last_line
Truth table100%3/3
A and not(B)
A= $self->summaryB= not $last_line
ABresult
0X0
100
111
115
116 41 ▶ if($last_line && $line ne '0')
Branch: 1 branch
BranchTrueFalseTotal
if ($last_line and $line ne '0') { } 4 37 41
Condition100%3/3
$last_line and $line ne 0
!ll&&!rl&&r
3524
MC/DC100%2/2
$last_line and $line ne 0
$last_line $line ne 0
Truth table100%3/3
A and B
A= $last_lineB= $line ne 0
ABresult
0X0
100
111
117 {
118 4 ▶ print Term::ANSIColor::color($self->clad->fail_color) if $self->is_color;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_color 0 4 4
119 }
120 else
121 {
122 37 ▶ print Term::ANSIColor::color($self->color) if $self->is_color;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_color 0 37 37
123 }
124  
125 41 printf "[%@{[ $self->clad->host_length ]}s %-4s] ", $self->prefix, $code;
126  
127 41 ▶ if(! $last_line)
Branch: 1 branch
BranchTrueFalseTotal
unless ($last_line) 35 6 41
128 {
129 35 ▶ if($code eq 'err')
Branch: 1 branch
BranchTrueFalseTotal
if ($code eq 'err') { } 6 29 35
130 {
131 6 ▶ print Term::ANSIColor::color($self->clad->err_color) if $self->is_color;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_color 0 6 6
132 }
133 else
134 {
135 29 ▶ print Term::ANSIColor::color('reset') if $self->is_color;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_color 0 29 29
136 }
137 }
138
139 41 print $line;
140
141 41 ▶ if($last_line || $code eq 'err')
Branch: 1 branch
BranchTrueFalseTotal
if ($last_line or $code eq "err") 12 29 41
Condition100%3/3
$last_line or $code eq "err"
l!l&&r!l&&!r
6629
MC/DC100%2/2
$last_line or $code eq "err"
$last_line $code eq "err"
Truth table100%3/3
A or B
A= $last_lineB= $code eq "err"
ABresult
1X1
011
000
142 {
143 12 ▶ print Term::ANSIColor::color('reset') if $self->is_color;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_color 0 12 12
144 }
145
146 41 print "\n";
147
148 41 ▶ if($fh && $last_line && $line ne '0')
Branch: 1 branch
BranchTrueFalseTotal
if ($fh and $last_line and $line ne 0) 0 41 41
Condition50%3/6
$fh and $last_line and $line ne 0
!ll&&!rl&&r
4100
$fh and $last_line
!ll&&!rl&&r
3560
MC/DC0%0/3
$fh and $last_line and $line ne 0
$fh $last_line $line ne 0
Truth table50%2/4
A and B and C
A= $fhB= $last_lineC= $line ne 0
ABCresult
0XX0
10X0
1100
1111
149 {
150 0 print ' ' x ($self->clad->host_length +8), "see @{[ $self->logfilename ]}\n";
151 }
152 }
153  
154 30 ▶sub cv { shift->{cv} }
Subroutine cv: called CC=1 SCAR=0.0
Pod undocumented
155  
156 39 1;
157  
158 __END__
« blib/lib/App/clad.pm ↑ Summary /usr/local/bin/perldoc »