Tak/Role/ScriptActions.pm

filter: Statementstmt 12.7% 7 / 55 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 2 / 8 Podpod 0.0% 0 / 3 totaltotal 10.4% 9 / 86 SCAR 53.3
CC
16
Cov
9%
each_repl
72.0
print_exec_result
30.0
every_exec
20.0
CRAP 206.8
↑ Summary Tak/Script.pm »
1 package Tak::Role::ScriptActions;
2  
3 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶no warnings::illegalproto;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub every_exec (stream|s) {
7 0 ▶ my ($self, $remotes, $options, @command) = @_;
Subroutine every_exec: not called CC=4 SCAR=30.0
Pod undocumented
8  
9 0 my @requests;
10  
11 0 $_->ensure(command_service => 'Tak::CommandService') for @$remotes;
12  
13 0 foreach my $remote (@$remotes) {
14 0 ▶ if ($options->{stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'stream'}) { } 0 0 0
15 0 my $stdout = $self->stdout;
16 0 my $host = $remote->host;
17 push @requests, $remote->start(
18 {
19 0 ▶ on_result => sub { $self->print_exec_result($remote, @_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 on_progress => sub {
21 0 ▶ $stdout->print($host.' '.$_[0].': '.$_[1]);
Subroutine __ANON__: not called CC=2 SCAR=17.9
22 0 ▶ $stdout->print("\n") unless $_[1] =~ /\n\Z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] =~ /\n\Z/ 0 0 0
23 }
24 },
25 0 command_service => stream_exec => \@command
26 );
27 } else {
28 push @requests, $remote->start(
29 0 ▶ { on_result => sub { $self->print_exec_result($remote, @_) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 command_service => exec => \@command
31 );
32 }
33 }
34 0 Tak->await_all(@requests);
35 }
36  
37 sub print_exec_result {
38 0 ▶ my ($self, $remote, $result) = @_;
Subroutine print_exec_result: not called CC=5 SCAR=34.0
Pod undocumented
39  
40 0 my $res = eval { $result->get }
41 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
my $res = eval { do { $result->get } } or do { $self->stderr->print("Host ${\$remote->host;}: Error: $@\n"); return } 0 0 0
42 0 $self->stderr->print("Host ${\$remote->host}: Error: $@\n");
43 0 return;
44 };
45  
46 0 my $code = $res->{exit_code};
47 0 $self->stdout->print(
48 0 ▶ "Host ${\$remote->host}: ".($code ? "NOT OK ${code}" : "OK")."\n"
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 0 0 0
49 );
50 0 ▶ if ($res->{stderr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"stderr"}) 0 0 0
51 0 $self->stdout->print("Stderr:\n${\$res->{stderr}}\n");
52 }
53 0 ▶ if ($res->{stdout}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"stdout"}) 0 0 0
54 0 $self->stdout->print("Stdout:\n${\$res->{stdout}}\n");
55 }
56 }
57  
58 sub each_repl (I=s@;m=s@;M=s@) {
59 0 ▶ my ($self, $remote, $options) = @_;
Subroutine each_repl: not called CC=8 SCAR=42.8
Pod undocumented
60 0 require Tak::REPL;
61 0 require B;
62 0 $remote->ensure(
63 eval_service => 'Tak::EvalService',
64 expose => { service_client => [] },
65 );
66 0 ▶ foreach my $lib (@{$options->{'I'}||[]}) {
Branch: 1 branch
BranchTrueFalseTotal
$options->{"I"} or [] 0 0 0
67 0 $remote->do(eval_service => eval => "lib->import(${\B::perlstring($lib)})");
68 }
69 0 ▶ foreach my $module (@{$options->{'m'}||[]}) {
Branch: 1 branch
BranchTrueFalseTotal
$options->{"m"} or [] 0 0 0
70 0 $remote->do(eval_service => eval => "use ${module} ()");
71 }
72 0 ▶ foreach my $spec (@{$options->{'M'}||[]}) {
Branch: 1 branch
BranchTrueFalseTotal
$options->{"M"} or [] 0 0 0
73 0 my ($module, $import) = split('=', $spec);
74 0 my $extra = '';
75 0 ▶ if ($import) {
Branch: 1 branch
BranchTrueFalseTotal
if ($import) 0 0 0
76 0 $extra = ' '.join(', ', map B::perlstring($_), split(',',$import));
77 }
78 0 $remote->do(eval_service => eval => "use ${module}${extra}");
79 }
80 0 Tak::REPL->new(client => $remote->curry('eval_service'))->run;
81 }
82  
83 1 1;
↑ Summary Tak/Script.pm »