blib/lib/App/clad.pm

filter: Statementstmt 82.5% 237 / 287 Branchbran 71.5% 73 / 102 Conditioncond 61.9% 13 / 21 MC/DCmcdc 23.0% 3 / 13 Subroutinesub 90.7% 59 / 65 Podpod 0.0% 0 / 37 totaltotal 73.3% 385 / 525 CC 72 SCAR 23.3
CC
72
Cov
79%
run_list
30.0
run
23.8
new
23.1
CRAP 10.3
« blib/lib/Clustericious/Admin/Server.pm ↑ Summary blib/lib/Clustericious/Admin/RemoteHandler.pm »
1 package App::clad;
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 Getopt::Long 1.24 qw( GetOptionsFromArray :config pass_through);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 39 ▶use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use Clustericious::Config 1.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 39 ▶use Term::ANSIColor ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 39 ▶use Sys::Hostname qw( hostname );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 39 ▶use YAML::XS qw( Dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 39 ▶use File::Basename qw( basename );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶use File::Glob qw( bsd_glob );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use AE;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 39 ▶use Clustericious::Admin::RemoteHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 39 ▶use Clustericious::Admin::Dump qw( perl_dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 39 ▶use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 39 ▶use Path::Class ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # ABSTRACT: (Deprecated) Parallel SSH client
21 39 our $VERSION = '1.11'; # VERSION
22  
23  
24 sub _local_default ($$)
25 79 ▶{
Subroutine _local_default: called CC=2 SCAR=6.9
26 79 ▶ eval { require Clustericious::Admin::ConfigData }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Clustericious::Admin::ConfigData } } ? : 3 76 79
27 ? Clustericious::Admin::ConfigData->config($_[0])
28 : $_[1];
29 }
30  
31 sub main
32 30 ▶{
Subroutine main: called CC=1 SCAR=0.0
Pod undocumented
33 30 my $clad = shift->new(@_);
34 30 $clad->run;
35 }
36  
37 # this hook is used for testing
38 # see t/args.t subtest 'color'
39 102 ▶our $_stdout_is_terminal = sub { -t STDOUT };
Subroutine __ANON__: called CC=1 SCAR=0.0
40  
41 sub _rc
42 1 ▶{
Subroutine _rc: called CC=2 SCAR=7.1
43 1 my $dir = bsd_glob('~/.clad');
44 1 ▶ mkdir $dir unless $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 0 1 1
45 1 $dir;
46 }
47  
48 sub new
49 104 ▶{
Subroutine new: called CC=23 SCAR=31.4
Pod undocumented
50 104 my $class = shift;
51  
52 104 my $self = bless {
53 dry_run => 0,
54 color => $_stdout_is_terminal->(),
55 server => 0,
56 verbose => 0,
57 serial => 0,
58 next_color => -1,
59 ret => 0,
60 fat => 0,
61 max => 0,
62 count => 0,
63 summary => 0,
64 files => [],
65 purge => 0,
66 list => 0,
67 }, $class;
68
69 104 my @argv = @_;
70
71 104 my $config_name = 'Clad';
72
73 GetOptionsFromArray(
74 \@argv,
75 'n' => \$self->{dry_run},
76 1 ▶ 'a' => sub { $self->{color} = 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 'l=s' => \$self->{user},
78 'server' => \$self->{server},
79 'verbose' => \$self->{verbose},
80 'serial' => \$self->{serial},
81 'config=s' => \$config_name,
82 'fat' => \$self->{fat},
83 'max=s' => \$self->{max},
84 'file=s' => $self->{files},
85 'dir=s' => \$self->{dir},
86 'summary' => \$self->{summary},
87 'purge' => \$self->{purge},
88 'list' => \$self->{list},
89  
90 1 ▶ 'log' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
91 1 $self->{log_dir} = Path::Class::Dir->new(
92 _rc(),
93 'log',
94 sprintf("%08x.%s", time, $$)
95 );
96 },
97  
98 2 ▶ 'log-dir=s' => sub { $self->{log_dir} = Path::Class::Dir->new($_[1]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
99  
100 2 ▶ 'help|h' => sub { pod2usage({ -verbose => 2}) },
Subroutine __ANON__: called CC=1 SCAR=0.0
101 1 ▶ 'version' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
102 1 ▶ say STDERR 'App::clad version ', ($App::clad::VERSION // 'dev');
Condition50%1/2
$App::clad::VERSION // "dev"
l!l
10
MC/DC0%0/1
$App::clad::VERSION // "dev"
$App::clad::VERSION
Truth table50%1/2
A
A= $App::clad::VERSION
Aresult
11
00
103 1 exit 1;
104 },
105 104 ▶ ) || pod2usage(1);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@argv, "n", \$self->{"dry_run"}, "a", sub { $self->{"color"} = 0; } , "l=s", \$self->{"user"}, "server", \$self->{"server"}, "verbose", \$self->{"verbose"}, "serial", \$self->{"serial"}, "config=s", \$config_name, "fat", \$self->{"fat"}, "max=s", \$self->{"max"}, "file=s", $self->{"files"}, "dir=s", \$self->{"dir"}, "summary", \$self->{"summary"}, "purge", \$self->{"purge"}, "list", \$self->{"list"}, "log", sub { $self->{"log_dir"} = "Path::Class::Dir"->new(_rc(), "log", sprintf("%08x.%s", time, $$)); } , "log-dir=s", sub { $self->{"log_dir"} = "Path::Class::Dir"->new($_[1]); } , "help|h", sub { pod2usage({"-verbose", 2}); } , "version", sub { say STDERR "App::clad version ", $VERSION // "dev"; &CORE::GLOBAL::exit(1); } ) or pod2usage(1) 101 0 101
106
107 101 ▶ $self->log_dir->mkpath(0,0700) if $self->log_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $self->log_dir 3 98 101
108  
109 101 $self->{config} = Clustericious::Config->new($config_name);
110  
111 101 ▶ return $self if $self->server;
Branch: 1 branch
BranchTrueFalseTotal
if $self->server 50 51 101
112 51 ▶ return $self if $self->purge;
Branch: 1 branch
BranchTrueFalseTotal
if $self->purge 1 50 51
113 50 ▶ return $self if $self->list;
Branch: 1 branch
BranchTrueFalseTotal
if $self->list 1 49 50
114
115 # make sure there is at least one cluster specified
116 # and that it doesn't look like a command line option
117 49 ▶ unless(@argv)
Branch: 1 branch
BranchTrueFalseTotal
unless (@argv) 1 48 49
118 {
119 1 pod2usage({
120 -exitval => 'NOEXIT',
121 -message => "No clusters specified",
122 -sections => [ qw( SYNOPSIS) ],
123 -verbose => 99,
124 });
125 1 $self->{list} = 1;
126 1 $self->ret(1);
127 1 return $self;
128 }
129 48 ▶ pod2usage({ -exitvalue => 1, -message => "Unknown option: $1" })
Branch: 1 branch
BranchTrueFalseTotal
if $argv[0] =~ /^--?(.*)$/ 1 47 48
130 if $argv[0] =~ /^--?(.*)$/;
131  
132 47 $self->{clusters} = [ split ',', shift @argv ];
133  
134 # make sure there is at least one command argument is specified
135 # and that it doesn't look like a command line option
136 47 ▶ pod2usage({ -exitval => 1, -message => "No commands specified" })
Branch: 1 branch
BranchTrueFalseTotal
unless @argv 1 46 47
137 unless @argv;
138 46 ▶ pod2usage({ -exitvalue => 1, -message => "Unknown option: $1" })
Branch: 1 branch
BranchTrueFalseTotal
if $argv[0] =~ /^--?(.*)$/ 1 45 46
139 if $argv[0] =~ /^--?(.*)$/;
140
141 45 $self->{command} = [ @argv ];
142  
143 45 ▶ if(my $expanded = $self->alias->{$self->command->[0]})
Branch: 1 branch
BranchTrueFalseTotal
if (my $expanded = $self->alias->{$self->command->[0]}) 2 43 45
144 {
145 2 ▶ if(ref $expanded)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $expanded) { } 1 1 2
146 {
147 1 splice @{ $self->command }, 0, 1, @$expanded;
148 }
149 else
150 {
151 1 $self->command->[0] = $expanded;
152 }
153 }
154
155 45 ▶ if($self->config->script(default => {})->{$self->command->[0]})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->config->script("default", {})->{$self->command->[0]}) 1 44 45
156 {
157 1 my $name = shift @{ $self->command };
158 1 unshift @{ $self->command }, '$SCRIPT1';
159 1 my $content = $self->config->script(default => {})->{$name};
160 1 $self->{script} = [ $name => $content ];
161 }
162
163 45 my $ok = 1;
164
165 45 foreach my $cluster (map { "$_" } $self->clusters)
166 {
167 46 $cluster =~ s/^.*@//;
168 46 ▶ unless($self->cluster_list->{$cluster})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->cluster_list->{$cluster}) 2 44 46
169 {
170 2 $self->cluster_list->{$cluster} = [$cluster];
171 }
172 }
173
174 45 foreach my $file ($self->files)
175 {
176 6 ▶ next if -r $file;
Branch: 1 branch
BranchTrueFalseTotal
if -r $file 5 1 6
177 1 say STDERR "unable to find $file";
178 1 $ok = 0;
179 }
180
181 45 ▶ if(defined $self->dir && ! -d $self->dir)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->dir and not -d $self->dir) 1 44 45
Condition100%3/3
defined $self->dir and not -d $self->dir
!ll&&!rl&&r
4221
MC/DC100%2/2
defined $self->dir and not -d $self->dir
defined $self->dir not -d $self->dir
Truth table100%3/3
A and not(B)
A= defined $self->dirB= not -d $self->dir
ABresult
0X0
100
111
182 {
183 1 say STDERR "unable to find @{[ $self->dir ]}";
184 1 $ok = 0;
185 }
186  
187 45 ▶ unless(-t STDIN)
Branch: 1 branch
BranchTrueFalseTotal
unless (-t STDIN) 45 0 45
188 {
189 45 $self->{stdin} = do { local $/; <STDIN> };
190 delete $self->{stdin}
191 unless defined $self->{stdin}
192 45 ▶ && length $self->{stdin};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"stdin"} and length $self->{"stdin"} 45 0 45
Condition66%2/3
defined $self->{"stdin"} and length $self->{"stdin"}
!ll&&!rl&&r
4050
MC/DC0%0/2
defined $self->{"stdin"} and length $self->{"stdin"}
defined $self->{"stdin"} length $self->{"stdin"}
Truth table66%2/3
A and B
A= defined $self->{"stdin"}B= length $self->{"stdin"}
ABresult
0X0
100
111
193 }
194
195 45 ▶ exit 2 unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 2 43 45
196
197 43 $self;
198 }
199  
200 375 ▶sub config { shift->{config} }
Subroutine config: called CC=1 SCAR=0.0
Pod undocumented
201 32 ▶sub dry_run { shift->{dry_run} }
Subroutine dry_run: called CC=1 SCAR=0.0
Pod undocumented
202 30 ▶sub color { shift->{color} }
Subroutine color: called CC=1 SCAR=0.0
Pod undocumented
203 65 ▶sub clusters { @{ shift->{clusters} } }
Subroutine clusters: called CC=1 SCAR=0.0
Pod undocumented
204 109 ▶sub command { shift->{command} }
Subroutine command: called CC=1 SCAR=0.0
Pod undocumented
205 20 ▶sub user { shift->{user} }
Subroutine user: called CC=1 SCAR=0.0
Pod undocumented
206 161 ▶sub server { shift->{server} }
Subroutine server: called CC=1 SCAR=0.0
Pod undocumented
207 44 ▶sub verbose { shift->{verbose} }
Subroutine verbose: called CC=1 SCAR=0.0
Pod undocumented
208 32 ▶sub serial { shift->{serial} }
Subroutine serial: called CC=1 SCAR=0.0
Pod undocumented
209 13 ▶sub max { shift->{max} }
Subroutine max: called CC=1 SCAR=0.0
Pod undocumented
210 59 ▶sub files { @{ shift->{files} } }
Subroutine files: called CC=1 SCAR=0.0
Pod undocumented
211 63 ▶sub dir { shift->{dir} }
Subroutine dir: called CC=1 SCAR=0.0
Pod undocumented
212 13 ▶sub script { @{ shift->{script} // [] } }
Subroutine script: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
+(shift())->{"script"} // []
l!l
211
MC/DC100%1/1
+(shift())->{"script"} // []
+(shift())->{"script"}
Truth table100%2/2
A
A= +(shift())->{"script"}
Aresult
11
00
213 12 ▶sub stdin { defined shift->{stdin} }
Subroutine stdin: called CC=1 SCAR=0.0
Pod undocumented
214 32 ▶sub summary { shift->{summary} }
Subroutine summary: called CC=1 SCAR=0.0
Pod undocumented
215 152 ▶sub log_dir { shift->{log_dir} }
Subroutine log_dir: called CC=1 SCAR=0.0
Pod undocumented
216 64 ▶sub purge { shift->{purge} }
Subroutine purge: called CC=1 SCAR=0.0
Pod undocumented
217 63 ▶sub list { shift->{list} }
Subroutine list: called CC=1 SCAR=0.0
Pod undocumented
218 0 ▶sub fail_color { shift->config->fail_color ( default => 'bold red' ) }
Subroutine fail_color: not called CC=1 SCAR=6.9
Pod undocumented
219 0 ▶sub err_color { shift->config->err_color ( default => 'bold yellow' ) }
Subroutine err_color: not called CC=1 SCAR=6.9
Pod undocumented
220 32 ▶sub ssh_command { shift->config->ssh_command( default => 'ssh' ) }
Subroutine ssh_command: called CC=1 SCAR=0.0
Pod undocumented
221 32 ▶sub ssh_options { shift->config->ssh_options( default => [ -o => 'StrictHostKeyChecking=no',
Subroutine ssh_options: called CC=1 SCAR=0.0
Pod undocumented
222 -o => 'BatchMode=yes',
223 -o => 'PasswordAuthentication=no',
224 '-T', ] ) }
225 32 ▶sub ssh_extra { shift->config->ssh_extra( default => [] ) }
Subroutine ssh_extra: called CC=1 SCAR=0.0
Pod undocumented
226 44 ▶sub fat { my $self = shift; $self->{fat} || $self->config->fat( default => _local_default 'clad_fat', 0 ) }
Subroutine fat: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$self->{"fat"} or $self->config->fat("default", &_local_default("clad_fat", 0)) 0 44 44
227  
228 sub server_command
229 32 ▶{
Subroutine server_command: called CC=2 SCAR=7.2
Pod undocumented
230 32 my($self) = @_;
231
232 32 ▶ $self->fat
Branch: 1 branch
BranchTrueFalseTotal
$self->fat ? : 0 32 32
233 ? $self->config->fat_server_command( default => _local_default 'clad_fat_server_command', 'perl' )
234 : $self->config->server_command( default => _local_default 'clad_server_command', 'clad --server' );
235 }
236  
237 sub alias
238 48 ▶{
Subroutine alias: called CC=1 SCAR=0.0
Pod undocumented
239 48 my($self) = @_;
240 16 ▶ $self->config->alias( default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
241 16 my %deprecated = $self->config->aliases( default => {} );
242 16 ▶ say STDERR "use of aliases key in configuration is deprecated, use alias instead"
Branch: 1 branch
BranchTrueFalseTotal
if %deprecated 0 16 16
243 if %deprecated;
244 16 \%deprecated;
245 48 });
246 }
247  
248 sub cluster_list
249 71 ▶{
Subroutine cluster_list: called CC=1 SCAR=3.1
Pod undocumented
250 71 my($self) = @_;
251 0 ▶ $self->config->cluster( default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
252 0 my %deprecated = $self->config->clusters( default => {} );
253 0 ▶ say STDERR "use of clusters key in configuration is deprecated, use cluster instead"
Branch: 1 branch
BranchTrueFalseTotal
if %deprecated 0 0 0
254 if %deprecated;
255 0 \%deprecated;
256 71 });
257 }
258  
259 sub ret
260 17 ▶{
Subroutine ret: called CC=2 SCAR=6.9
Pod undocumented
261 17 my($self, $new) = @_;
262 17 ▶ $self->{ret} = $new if defined $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new 5 12 17
263 17 $self->{ret};
264 }
265  
266 sub host_length
267 41 ▶{
Subroutine host_length: called CC=7 SCAR=19.5
Pod undocumented
268 41 my($self) = @_;
269  
270 41 ▶ unless($self->{host_length})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"host_length"}) 9 32 41
271 {
272 9 my $length = 0;
273
274 9 foreach my $cluster (map { "$_" } $self->clusters)
275 {
276 10 ▶ my $user = $cluster =~ s/^(.*)@// ? $1 : $self->user;
Branch: 1 branch
BranchTrueFalseTotal
$cluster =~ s/^(.*)@// ? : 2 8 10
277 10 foreach my $host (@{ $self->cluster_list->{$cluster} })
278 {
279 28 ▶ my $prefix = ($user ? "$user\@" : '') . $host;
Branch: 1 branch
BranchTrueFalseTotal
$user ? : 9 19 28
280 28 ▶ $length = length $prefix if length $prefix > $length;
Branch: 1 branch
BranchTrueFalseTotal
if length $prefix > $length 9 19 28
281 }
282 }
283
284 9 $self->{host_length} = $length;
285 }
286
287 41 $self->{host_length};
288 }
289  
290 sub next_color
291 8 ▶{
Subroutine next_color: called CC=2 SCAR=7.0
Pod undocumented
292 8 my($self) = @_;
293 8 my @colors = $self->config->colors( default => ['green','cyan'] );
294 8 ▶ $colors[ ++$self->{next_color} ] // $colors[ $self->{next_color} = 0 ];
Condition66%2/3
$colors[++$self->{"next_color"}] // $colors[$self->{"next_color"} = 0]
l!l&&r!l&&!r
620
MC/DC0%0/2
$colors[++$self->{"next_color"}] // $colors[$self->{"next_color"} = 0]
$colors[++$self->{"next_color"}] $colors[$self->{"next_color"} = 0]
Truth table66%2/3
A // B
A= $colors[++$self->{"next_color"}]B= $colors[$self->{"next_color"} = 0]
ABresult
1X1
011
000
295 }
296  
297 sub payload
298 12 ▶{
Subroutine payload: called CC=10 SCAR=24.6
Pod undocumented
299 12 my($self, $clustername) = @_;
300
301 12 my %env = $self->config->env( default => {} );
302 12 ▶ $env{CLUSTER} //= $clustername; # deprecate
Condition33%1/3
$env{"CLUSTER"} //= $clustername
l!l&&r!l&&!r
0120
MC/DC0%0/2
$env{"CLUSTER"} //= $clustername
$env{"CLUSTER"} $clustername
Truth table33%1/3
A //= B
A= $env{"CLUSTER"}B= $clustername
ABresult
1X1
011
000
303 12 ▶ $env{CLAD_CLUSTER} //= $clustername;
Condition33%1/3
$env{"CLAD_CLUSTER"} //= $clustername
l!l&&r!l&&!r
0120
MC/DC0%0/2
$env{"CLAD_CLUSTER"} //= $clustername
$env{"CLAD_CLUSTER"} $clustername
Truth table33%1/3
A //= B
A= $env{"CLAD_CLUSTER"}B= $clustername
ABresult
1X1
011
000
304  
305 12 ▶ my $payload = {
Condition50%1/2
$App::clad::VERSION // "dev"
l!l
120
MC/DC0%0/1
$App::clad::VERSION // "dev"
$App::clad::VERSION
Truth table50%1/2
A
A= $App::clad::VERSION
Aresult
11
00
306 env => \%env,
307 command => $self->command,
308 verbose => $self->verbose,
309 version => $App::clad::VERSION // 'dev',
310 };
311
312 12 ▶ if($self->files)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->files) 1 11 12
313 {
314 1 $payload->{require} = '1.01';
315
316 1 foreach my $filename ($self->files)
317 {
318 2 my %h;
319 2 open my $fh, '<', $filename;
320 2 binmode $fh;
321 2 $h{content} = do { local $/; <$fh> };
322 2 close $fh;
323 2 $h{name} = basename $filename;
324 2 $h{mode} = sprintf "%o", (stat $filename)[2] & 0777;
325 2 push @{ $payload->{files} }, \%h;
326 }
327 }
328
329 12 ▶ if($self->script)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->script) 1 11 12
330 {
331 1 my($name, $content) = $self->script;
332 1 $payload->{require} = '1.01';
333
334 1 push @{ $payload->{files} }, {
335 name => $name,
336 content => $content,
337 mode => '0700',
338 env => 'SCRIPT1',
339 };
340 }
341
342 12 ▶ if($self->dir)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dir) 1 11 12
343 {
344 1 $payload->{require} = '1.02';
345
346 1 $CWD = $self->dir;
347
348 1 my $recurse;
349 4 ▶ $recurse = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
350 4 my($dir) = @_;
351 4 foreach my $child ($dir->children(no_hidden => 1))
352 {
353 7 my $key = $child->relative->stringify;
354 7 ▶ if($child->is_dir)
Branch: 1 branch
BranchTrueFalseTotal
if ($child->is_dir) { } 3 4 7
355 {
356 3 $payload->{dir}->{$key} = {
357 is_dir => 1,
358 };
359 3 $recurse->($child);
360 }
361 else
362 {
363 4 $payload->{dir}->{$key} = {
364 content => scalar $child->slurp(iomode => '<:bytes'),
365 };
366 }
367 7 $payload->{dir}->{$key}->{mode} = sprintf '%o', $child->stat->mode & 0777;
368 }
369 1 };
370
371 1 $recurse->(Path::Class::Dir->new);
372 }
373  
374 12 ▶ if($self->stdin)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->stdin) 0 12 12
375 {
376 0 $payload->{require} = '1.04';
377
378 # TODO:
379 # In Perl 5.22 we could refalias this
380 # and save some memory copies.
381 0 $payload->{stdin} = $self->{stdin};
382 }
383
384 12 ▶ if($self->fat)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fat) { } 0 12 12
385 {
386 # Perl on the remote end may not have YAML
387 # so we dump as Perl data structure
388 # instead.
389 0 $payload = perl_dump($payload);
390 0 require Clustericious::Admin::Server;
391 0 open my $fh, '<', $INC{'Clustericious/Admin/Server.pm'};
392 0 my $code = do { local $/; <$fh> };
393 0 close $fh;
394 0 $code =~ s{\s*$}{"\n"}e;
395 0 $payload = $code . $payload;
396 }
397 else
398 {
399 12 $payload = Dump($payload);
400 }
401
402 12 $payload;
403 }
404  
405 sub run
406 58 ▶{
Subroutine run: called CC=15 SCAR=31.7
Pod undocumented
407 58 my($self) = @_;
408
409 58 ▶ return $self->run_server if $self->server;
Branch: 1 branch
BranchTrueFalseTotal
if $self->server 47 11 58
410 11 ▶ return $self->run_purge if $self->purge;
Branch: 1 branch
BranchTrueFalseTotal
if $self->purge 0 11 11
411 11 ▶ return $self->run_list if $self->list;
Branch: 1 branch
BranchTrueFalseTotal
if $self->list 0 11 11
412
413 11 my @done;
414 11 my $max = $self->max;
415  
416
417 11 foreach my $cluster (map { "$_" } $self->clusters)
418 {
419 12 ▶ my $user = $cluster =~ s/^(.*)@// ? $1 : $self->user;
Branch: 1 branch
BranchTrueFalseTotal
$cluster =~ s/^(.*)@// ? : 2 10 12
420  
421 12 my $payload = $self->payload($cluster);
422  
423 12 foreach my $host (@{ $self->cluster_list->{$cluster} })
424 {
425 30 ▶ my $prefix = ($user ? "$user\@" : '') . $host;
Branch: 1 branch
BranchTrueFalseTotal
$user ? : 9 21 30
426 30 ▶ if($self->dry_run)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dry_run) { } 0 30 30
427 {
428 0 say "$prefix % @{ $self->command }";
429 }
430 else
431 {
432 30 my $remote = Clustericious::Admin::RemoteHandler->new(
433 prefix => $prefix,
434 clad => $self,
435 user => $user,
436 host => $host,
437 payload => $payload,
438 );
439  
440 30 my $done = $remote->cv;
441
442 0 ▶ $done->cb(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
443 0 my $count = --$self->{count};
444 0 ▶ $self->{cv}->send if $self->{cv};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cv"} 0 0 0
445 30 ▶ }) if $max;
Branch: 1 branch
BranchTrueFalseTotal
if $max 0 30 30
446
447 30 ▶ if($max)
Branch: 1 branch
BranchTrueFalseTotal
if ($max) 0 30 30
448 {
449 0 my $count = ++$self->{count};
450 0 ▶ if($count >= $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($count >= $max) 0 0 0
451 {
452 0 $self->{cv} = AE::cv;
453 0 $self->{cv}->recv;
454 0 delete $self->{cv};
455 }
456 }
457
458 30 ▶ $self->serial ? $done->recv : push @done, $done;
Branch: 1 branch
BranchTrueFalseTotal
$self->serial ? : 0 30 30
459 }
460 }
461 }
462
463 11 $_->recv for @done;
464  
465 11 ▶ say "See @{[ $self->log_dir ]} for all logs" if $self->log_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $self->log_dir 1 10 11
466
467 11 $self->ret;
468 }
469  
470 sub run_server
471 47 ▶{
Subroutine run_server: called CC=1 SCAR=0.0
Pod undocumented
472 47 require Clustericious::Admin::Server;
473 47 Clustericious::Admin::Server->_server(*STDIN);
474 }
475  
476 sub run_purge
477 0 ▶{
Subroutine run_purge: not called CC=4 SCAR=30.0
Pod undocumented
478 0 my $log_dir = Path::Class::Dir->new(
479 _rc(),
480 'log',
481 );
482
483 0 ▶ return unless -d $log_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $log_dir 0 0 0
484
485 0 foreach my $path ($log_dir->children)
486 {
487 0 ▶ if(-d $path)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) { } 0 0 0
488 {
489 0 say "PURGE DIR $path";
490 0 $path->rmtree(1, 1);
491 }
492 else
493 {
494 0 say "PURGE FILE $path";
495 0 $path->remove;
496 }
497 }
498 }
499  
500 sub run_list
501 0 ▶{
Subroutine run_list: not called CC=5 SCAR=34.0
Pod undocumented
502 0 my($self) = @_;
503
504 0 my @clusters = sort keys %{ $self->cluster_list };
505
506 0 my $cluster = shift @clusters;
507 0 ▶ if($cluster)
Branch: 1 branch
BranchTrueFalseTotal
if ($cluster) { } 0 0 0
508 {
509 0 say "Clusters: $cluster";
510 0 say " $_" for @clusters;
511 }
512 else
513 {
514 0 say "Clusters: [none]";
515 }
516  
517 0 my @alias = sort keys %{ $self->alias };
518 0 my $alias = shift @alias;
519 0 ▶ if($alias)
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) { } 0 0 0
520 {
521 0 say "Aliases: $alias";
522 0 say " $_" for @alias;
523 }
524 else
525 {
526 0 say "Aliases: [none]";
527 }
528  
529 0 $self->ret;
530 }
531  
532 39 1;
533  
534 __END__
« blib/lib/Clustericious/Admin/Server.pm ↑ Summary blib/lib/Clustericious/Admin/RemoteHandler.pm »