line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tak::Role::ScriptActions; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
615
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
1021
|
no warnings::illegalproto; |
|
1
|
|
|
|
|
352
|
|
|
1
|
|
|
|
|
15
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub every_exec (stream|s) { |
7
|
0
|
|
|
0
|
0
|
|
my ($self, $remotes, $options, @command) = @_; |
8
|
|
|
|
|
|
|
|
9
|
0
|
|
|
|
|
|
my @requests; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
$_->ensure(command_service => 'Tak::CommandService') for @$remotes; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
foreach my $remote (@$remotes) { |
14
|
0
|
0
|
|
|
|
|
if ($options->{stream}) { |
15
|
0
|
|
|
|
|
|
my $stdout = $self->stdout; |
16
|
0
|
|
|
|
|
|
my $host = $remote->host; |
17
|
|
|
|
|
|
|
push @requests, $remote->start( |
18
|
|
|
|
|
|
|
{ |
19
|
0
|
|
|
0
|
|
|
on_result => sub { $self->print_exec_result($remote, @_) }, |
20
|
|
|
|
|
|
|
on_progress => sub { |
21
|
0
|
|
|
0
|
|
|
$stdout->print($host.' '.$_[0].': '.$_[1]); |
22
|
0
|
0
|
|
|
|
|
$stdout->print("\n") unless $_[1] =~ /\n\Z/; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
}, |
25
|
0
|
|
|
|
|
|
command_service => stream_exec => \@command |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
} else { |
28
|
|
|
|
|
|
|
push @requests, $remote->start( |
29
|
0
|
|
|
0
|
|
|
{ on_result => sub { $self->print_exec_result($remote, @_) } }, |
30
|
0
|
|
|
|
|
|
command_service => exec => \@command |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
Tak->await_all(@requests); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub print_exec_result { |
38
|
0
|
|
|
0
|
0
|
|
my ($self, $remote, $result) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $res = eval { $result->get } |
41
|
0
|
0
|
|
|
|
|
or do { |
42
|
0
|
|
|
|
|
|
$self->stderr->print("Host ${\$remote->host}: Error: $@\n"); |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $code = $res->{exit_code}; |
47
|
0
|
0
|
|
|
|
|
$self->stdout->print( |
48
|
0
|
|
|
|
|
|
"Host ${\$remote->host}: ".($code ? "NOT OK ${code}" : "OK")."\n" |
49
|
|
|
|
|
|
|
); |
50
|
0
|
0
|
|
|
|
|
if ($res->{stderr}) { |
51
|
0
|
|
|
|
|
|
$self->stdout->print("Stderr:\n${\$res->{stderr}}\n"); |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
0
|
0
|
|
|
|
|
if ($res->{stdout}) { |
54
|
0
|
|
|
|
|
|
$self->stdout->print("Stdout:\n${\$res->{stdout}}\n"); |
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub each_repl (I=s@;m=s@;M=s@) { |
59
|
0
|
|
|
0
|
0
|
|
my ($self, $remote, $options) = @_; |
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
|
0
|
|
|
|
|
foreach my $lib (@{$options->{'I'}||[]}) { |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$remote->do(eval_service => eval => "lib->import(${\B::perlstring($lib)})"); |
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
0
|
0
|
|
|
|
|
foreach my $module (@{$options->{'m'}||[]}) { |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$remote->do(eval_service => eval => "use ${module} ()"); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
|
|
|
|
foreach my $spec (@{$options->{'M'}||[]}) { |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my ($module, $import) = split('=', $spec); |
74
|
0
|
|
|
|
|
|
my $extra = ''; |
75
|
0
|
0
|
|
|
|
|
if ($import) { |
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; |