Footprintless/Command.pm

filter: Statementstmt 90.5% 172 / 190 Branchbran 82.4% 94 / 114 Conditioncond 67.5% 27 / 40 MC/DCmcdc 40.0% 10 / 25 Subroutinesub 100% 34 / 34 Podpod 90.9% 10 / 11 totaltotal 83.8% 347 / 414 CC 75 SCAR 23.5
CC
75
Cov
85%
clone
26.6
__ANON__
15.9
cp_command
14.1
CRAP 10.5
« Footprintless/CommandRunner/IPCRun.pm ↑ Summary Footprintless/Log.pm »
1 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Footprintless::Command;
5 15 $Footprintless::Command::VERSION = '1.29';
6 # ABSTRACT: A factory for building common commands
7 # PODNAME: Footprintless::Command
8  
9 15 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 our @EXPORT_OK = qw(
11 batch_command
12 command
13 command_options
14 cp_command
15 mkdir_command
16 pipe_command
17 rm_command
18 sed_command
19 tail_command
20 write_command
21 );
22  
23 15 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 35 ▶sub batch_command {
Subroutine batch_command: called CC=5 SCAR=16.1
Pod documented
26 35 my ( @commands, $batch_options, $command_options );
27 35 (@commands) = @_;
28 35 ▶ $command_options = pop(@commands)
Branch: 1 branch
BranchTrueFalseTotal
if ref $commands[$#commands] eq "Footprintless::Command::CommandOptions" 21 14 35
29 if ( ref( $commands[$#commands] ) eq 'Footprintless::Command::CommandOptions' );
30 35 ▶ $batch_options = pop(@commands) if ( ref( $commands[$#commands] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $commands[$#commands] eq "HASH" 7 28 35
31  
32 35 ▶ push( @commands, $command_options ) if ($command_options);
Branch: 1 branch
BranchTrueFalseTotal
if $command_options 21 14 35
33  
34 wrap(
35 $batch_options || {},
36 @commands,
37 35 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 35 return @_;
39 }
40 35 ▶ );
Condition100%2/2
$batch_options || {}
l!l
728
MC/DC100%1/1
$batch_options || {}
$batch_options
Truth table100%2/2
A
A= $batch_options
Aresult
11
00
41 }
42  
43 93 ▶sub command {
Subroutine command: called CC=1 SCAR=0.0
Pod documented
44 wrap(
45 {},
46 @_,
47 93 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 93 return shift;
49 }
50 93 );
51 }
52  
53 83 ▶sub command_options {
Subroutine command_options: called CC=1 SCAR=0.0
Pod documented
54 83 return Footprintless::Command::CommandOptions->new(@_);
55 }
56  
57 14 ▶sub cp_command {
Subroutine cp_command: called CC=14 SCAR=26.4
Pod documented
58 14 my ( $source_path, $source_command_options, $destination_path, $destination_command_options,
59 %cp_options );
60 14 $source_path = _escape_path(shift);
61 14 ▶ $source_command_options = shift
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "Footprintless::Command::CommandOptions" 9 5 14
62 if ( ref( $_[0] ) eq 'Footprintless::Command::CommandOptions' );
63 14 $destination_path = _escape_path(shift);
64 14 ▶ $destination_command_options = shift
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "Footprintless::Command::CommandOptions" 8 6 14
65 if ( ref( $_[0] ) eq 'Footprintless::Command::CommandOptions' );
66 14 %cp_options = @_;
67  
68 14 ▶ $source_command_options = command_options() unless ($source_command_options);
Branch: 1 branch
BranchTrueFalseTotal
unless $source_command_options 5 9 14
69 14 ▶ $destination_command_options = command_options() unless ($destination_command_options);
Branch: 1 branch
BranchTrueFalseTotal
unless $destination_command_options 6 8 14
70  
71 14 my $source_command;
72 my $destination_command;
73 14 ▶ if ( $cp_options{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp_options{'file'}) { } 6 8 14
74  
75 # is a file, so use cat | dd
76 6 ▶ if ( $cp_options{compress} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp_options{'compress'}) { } 1 5 6
77 1 $source_command = command( "gzip -c $source_path", $source_command_options );
78 1 $destination_command =
79 pipe_command( "gunzip", "dd of=$destination_path", $destination_command_options );
80 }
81 else {
82 5 $source_command = command( "cat $source_path", $source_command_options );
83 5 $destination_command =
84 command( "dd of=$destination_path", $destination_command_options );
85 }
86 }
87 else {
88 # is a directory, so use tar or unzip
89 8 ▶ if ( $cp_options{archive} && $cp_options{archive} eq 'zip' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp_options{'archive'} and $cp_options{'archive'} eq 'zip') { } 3 5 8
Condition66%2/3
$cp_options{"archive"} and $cp_options{"archive"} eq "zip"
!ll&&!rl&&r
503
MC/DC50%1/2
$cp_options{"archive"} and $cp_options{"archive"} eq "zip"
$cp_options{"archive"} $cp_options{"archive"} eq "zip"
Truth table66%2/3
A and B
A= $cp_options{"archive"}B= $cp_options{"archive"} eq "zip"
ABresult
0X0
100
111
90 my $temp_zip = File::Spec->catfile( $destination_path,
91 3 ▶ $cp_options{unzip_temp_file} || "temp_cp_command.zip" );
Condition50%1/2
$cp_options{'unzip_temp_file'} || 'temp_cp_command.zip'
l!l
03
MC/DC0%0/1
$cp_options{'unzip_temp_file'} || 'temp_cp_command.zip'
$cp_options{'unzip_temp_file'}
Truth table50%1/2
A
A= $cp_options{'unzip_temp_file'}
Aresult
11
00
92 3 $source_command =
93 command(
94 batch_command( "cd $source_path", "zip -qr - .", { subshell => "bash -c " } ),
95 $source_command_options );
96 3 $destination_command = batch_command(
97 "dd of=$temp_zip", "unzip -qod $destination_path $temp_zip",
98 rm_command($temp_zip), $destination_command_options
99 );
100 }
101 else {
102 # default, use tar
103 5 my @parts = ("tar -c -C $source_path .");
104 5 my @destination_parts = ();
105 5 ▶ if ( $cp_options{status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp_options{"status"}) 1 4 5
106 1 ▶ push(
Branch: 1 branch
BranchTrueFalseTotal
$source_command_options ? : 1 0 1
107 @parts,
108 join(
109 '',
110 'pv -f -s `',
111 _sudo_command(
112 $source_command_options
113 ? ( $source_command_options->get_sudo_command(),
114 $source_command_options->get_sudo_username()
115 )
116 : ( undef, undef ),
117 pipe_command( "du -sb $source_path", 'cut -f1' )
118 ),
119 '`'
120 )
121 );
122 }
123 5 ▶ if ( $cp_options{compress} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp_options{"compress"}) 2 3 5
124 2 push( @parts, 'gzip' );
125 2 push( @destination_parts, 'gunzip' );
126 }
127 push(
128 5 ▶ @destination_parts,
Branch: 1 branch
BranchTrueFalseTotal
$destination_command_options ? : 5 0 5
129 _sudo_command(
130 $destination_command_options
131 ? ( $destination_command_options->get_sudo_command(),
132 $destination_command_options->get_sudo_username()
133 )
134 : ( undef, undef ),
135 "tar --no-overwrite-dir -x -C $destination_path"
136 )
137 );
138  
139 5 $source_command = command( pipe_command(@parts), $source_command_options );
140 5 $destination_command = command( pipe_command(@destination_parts),
141 $destination_command_options->clone( sudo_username => undef ) );
142 }
143 }
144  
145 14 return pipe_command( $source_command, $destination_command );
146 }
147  
148 28 ▶sub _escape_path {
Subroutine _escape_path: called CC=1 SCAR=0.0
149 28 my ($path) = @_;
150 28 $path =~ s/(['"`\s])/\\$1/g;
151 28 return $path;
152 }
153  
154 15 ▶sub mkdir_command {
Subroutine mkdir_command: called CC=1 SCAR=0.0
Pod documented
155 wrap(
156 {},
157 @_,
158 15 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
159 15 return 'mkdir -p "' . join( '" "', @_ ) . '"';
160 }
161 15 );
162 }
163  
164 33 ▶sub pipe_command {
Subroutine pipe_command: called CC=1 SCAR=0.0
Pod documented
165 wrap(
166 { command_separator => '|' },
167 @_,
168 33 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
169 33 return @_;
170 }
171 33 );
172 }
173  
174 59 ▶sub _quote_command {
Subroutine _quote_command: called CC=1 SCAR=0.0
175 59 my ($command) = @_;
176 59 $command =~ s/\\/\\\\/g;
177 59 $command =~ s/\$/\\\$/g;
178 59 $command =~ s/`/\\`/g; # for `command`
179 59 $command =~ s/"/\\"/g;
180 59 return "\"$command\"";
181 }
182  
183 23 ▶sub rm_command {
Subroutine rm_command: called CC=1 SCAR=0.0
Pod documented
184 Footprintless::Command::wrap(
185 {},
186 @_,
187 23 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
188 23 my ( @dirs, @files );
189 23 foreach my $entry (@_) {
190 34 ▶ if ( $entry =~ /(?:\/|\\)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry =~ m[(?:/|\\)$]) { } 23 11 34
191 23 push( @dirs, $entry );
192 }
193 else {
194 11 push( @files, $entry );
195 }
196 }
197  
198 23 ▶ if (@dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs) { } 17 6 23
199 17 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 2 15 17
200 2 return batch_command(
201 'rm -rf "' . join( '" "', sort(@dirs) ) . '"',
202 'rm -f "' . join( '" "', sort(@files) ) . '"',
203 { subshell => 'bash -c ' }
204 );
205 }
206 else {
207 15 return 'rm -rf "' . join( '" "', sort(@dirs) ) . '"';
208 }
209 }
210 else {
211 6 return 'rm -f "' . join( '" "', sort(@files) ) . '"';
212 }
213 }
214 23 );
215 }
216  
217 2 ▶sub sed_command {
Subroutine sed_command: called CC=1 SCAR=0.8
Pod documented
218 wrap(
219 {},
220 @_,
221 2 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=27.6
222 2 my @args = @_;
223 2 my $options = {};
224  
225 2 ▶ if ( ref( $args[$#args] ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[$#args] eq "HASH") 1 1 2
226 1 $options = pop(@args);
227 }
228  
229 2 my $command = 'sed';
230 2 ▶ $command .= ' -i' if ( $options->{in_place} );
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"in_place"} 0 2 2
231 2 ▶ if ( defined( $options->{temp_script_file} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{'temp_script_file'}) { } 0 2 2
232 0 my $temp_script_file_name = $options->{temp_script_file}->filename();
233 0 ▶ print( { $options->{temp_script_file} } join( ' ', '', map {"$_;"} @args ) )
Branch: 1 branch
BranchTrueFalseTotal
if scalar @args 0 0 0
234 if ( scalar(@args) );
235 print(
236 0 { $options->{temp_script_file} } join( ' ',
237 '',
238 0 map {"s/$_/$options->{replace_map}{$_}/g;"}
239 0 keys( %{ $options->{replace_map} } ) )
240 0 ▶ ) if ( defined( $options->{replace_map} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options->{"replace_map"} 0 0 0
241 0 $options->{temp_script_file}->flush();
242 0 $command .= " -f $temp_script_file_name";
243 }
244 else {
245 2 ▶ $command .= join( ' ', '', map {"-e '$_'"} @args ) if ( scalar(@args) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @args 1 1 2
246 $command .= join( ' ',
247 '',
248 1 map {"-e 's/$_/$options->{replace_map}{$_}/g'"}
249 1 keys( %{ $options->{replace_map} } ) )
250 2 ▶ if ( defined( $options->{replace_map} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options->{"replace_map"} 1 1 2
251 }
252 0 ▶ $command .= join( ' ', '', @{ $options->{files} } ) if ( $options->{files} );
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"files"} 0 2 2
253  
254 2 return $command;
255 }
256 2 );
257 }
258  
259 295 ▶sub _sudo_command {
Subroutine _sudo_command: called CC=4 SCAR=13.9
260 295 my ( $sudo_command, $sudo_username, $command ) = @_;
261 295 ▶ if ( defined($sudo_username) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sudo_username) 49 246 295
262 49 ▶ $command =
Branch: 2 branches
BranchTrueFalseTotal
$sudo_command ? : 5 44 49
$sudo_username ? : 47 2 49
263 ( $sudo_command ? "$sudo_command " : 'sudo ' )
264 . ( $sudo_username ? "-u $sudo_username " : '' )
265 . $command;
266 }
267 295 return $command;
268 }
269  
270 10 ▶sub tail_command {
Subroutine tail_command: called CC=1 SCAR=0.0
Pod documented
271 Footprintless::Command::wrap(
272 {},
273 @_,
274 10 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
275 10 my ( $file, %options ) = @_;
276 10 my @command = ('tail');
277 10 ▶ if ( $options{follow} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($options{'follow'}) { } 9 1 10
elsif ($options{'lines'}) { } 1 0 1
278 9 push( @command, '-f' );
279 }
280 elsif ( $options{lines} ) {
281 1 push( @command, '-n', $options{lines} );
282 }
283 10 push( @command, $file );
284 10 return join( ' ', @command );
285 }
286 10 );
287 }
288  
289 5 ▶sub write_command {
Subroutine write_command: called CC=10 SCAR=23.4
Pod documented
290 5 my ( $filename, @lines, $write_options, $command_options );
291 5 $filename = shift;
292 5 @lines = @_;
293 5 ▶ $command_options = pop(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if ref $lines[$#lines] eq "Footprintless::Command::CommandOptions" 4 1 5
294 if ( ref( $lines[$#lines] ) eq 'Footprintless::Command::CommandOptions' );
295 5 ▶ $write_options = pop(@lines) if ( ref( $lines[$#lines] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $lines[$#lines] eq "HASH" 3 2 5
296  
297 5 my $remote_command = "dd of=$filename";
298 5 ▶ if ( defined($write_options) && defined( $write_options->{mode} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $write_options and defined $write_options->{'mode'}) { } 3 2 5
elsif (defined $command_options) { } 1 1 2
Condition66%2/3
defined $write_options and defined $write_options->{"mode"}
!ll&&!rl&&r
203
MC/DC50%1/2
defined $write_options and defined $write_options->{"mode"}
defined $write_options defined $write_options->{"mode"}
Truth table66%2/3
A and B
A= defined $write_optionsB= defined $write_options->{"mode"}
ABresult
0X0
100
111
299 3 ▶ if ( defined($command_options) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $command_options) { } 3 0 3
elsif (defined $command_options) { } 0 0 0
300 3 $remote_command =
301 batch_command( $remote_command, "chmod $write_options->{mode} $filename",
302 $command_options );
303 }
304 elsif ( defined($command_options) ) {
305 0 $remote_command =
306 batch_command( $remote_command, "chmod $write_options->{mode} $filename" );
307 }
308 }
309 elsif ( defined($command_options) ) {
310 1 $remote_command = command( $remote_command, $command_options );
311 }
312  
313 my $line_separator =
314 ( defined($write_options) && defined( $write_options->{line_separator} ) )
315 ? $write_options->{line_separator}
316 5 ▶ : '\n';
Branch: 1 branch
BranchTrueFalseTotal
defined $write_options && defined $write_options->{'line_separator'} ? : 2 3 5
Condition100%3/3
defined $write_options and defined $write_options->{"line_separator"}
!ll&&!rl&&r
212
MC/DC100%2/2
defined $write_options and defined $write_options->{"line_separator"}
defined $write_options defined $write_options->{"line_separator"}
Truth table100%3/3
A and B
A= defined $write_optionsB= defined $write_options->{"line_separator"}
ABresult
0X0
100
111
317 5 return pipe_command( 'printf "' . join( $line_separator, @lines ) . '"', $remote_command );
318 }
319  
320 # Handles wrapping commands with possible ssh and command prefix
321 211 ▶sub wrap {
Subroutine wrap: called CC=14 SCAR=26.4
Pod undocumented
322 211 my $wrap_options = shift;
323 211 my $builder = pop;
324 211 my @args = @_;
325 211 my ( $ssh, $username, $hostname, $sudo_command, $sudo_username, $pretty );
326  
327 211 ▶ if ( ref( $args[$#args] ) eq 'Footprintless::Command::CommandOptions' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[$#args] eq "Footprintless::Command::CommandOptions") 121 90 211
328 121 my $options = pop(@args);
329 121 ▶ $ssh = $options->get_ssh() || 'ssh';
Condition100%2/2
$options->get_ssh || 'ssh'
l!l
7249
MC/DC100%1/1
$options->get_ssh || 'ssh'
$options->get_ssh
Truth table100%2/2
A
A= $options->get_ssh
Aresult
11
00
330 121 $username = $options->get_username();
331 121 $hostname = $options->get_hostname();
332 121 $sudo_command = $options->get_sudo_command();
333 121 $sudo_username = $options->get_sudo_username();
334 121 $pretty = $options->get_pretty();
335 }
336  
337 211 my $destination_command = '';
338 211 ▶ my $command_separator = $wrap_options->{command_separator} || ';';
Condition100%2/2
$wrap_options->{'command_separator'} || ';'
l!l
33178
MC/DC100%1/1
$wrap_options->{'command_separator'} || ';'
$wrap_options->{'command_separator'}
Truth table100%2/2
A
A= $wrap_options->{'command_separator'}
Aresult
11
00
339 211 my $commands = 0;
340 211 foreach my $command ( &$builder(@args) ) {
341 290 ▶ if ( defined($command) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $command) 289 1 290
342 289 ▶ if ( $commands++ > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($commands++ > 0) 78 211 289
343 78 $destination_command .= $command_separator;
344 78 ▶ if ($pretty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pretty) 0 78 78
345 0 $destination_command .= "\n";
346 }
347 }
348  
349 289 $command =~ s/^(.*?[^\\]);$/$1/; # from find -exec
350  
351 289 $command = _sudo_command( $sudo_command, $sudo_username, $command );
352  
353 289 $destination_command .= $command;
354 }
355 }
356  
357 211 ▶ if ( $wrap_options->{subshell} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrap_options->{"subshell"}) 7 204 211
358 7 $destination_command = $wrap_options->{subshell} . _quote_command($destination_command);
359 }
360  
361 211 ▶ if ( !defined($username) && !defined($hostname) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $username or defined $hostname) 159 52 211
Condition100%3/3
defined $username or defined $hostname
l!l&&r!l&&!r
448159
MC/DC100%2/2
defined $username or defined $hostname
defined $username defined $hostname
Truth table100%3/3
A or B
A= defined $usernameB= defined $hostname
ABresult
1X1
011
000
362  
363 # silly to ssh to localhost as current user, so dont
364 159 return $destination_command;
365 }
366  
367 52 ▶ my $userAt =
Branch: 2 branches
BranchTrueFalseTotal
$username ? : 4 48 52
$ssh =~ /plink(?:\.exe)?$/ ? : 1 3 4
368 $username
369 ? ( ( $ssh =~ /plink(?:\.exe)?$/ ) ? "-l $username " : "$username\@" )
370 : '';
371  
372 52 $destination_command = _quote_command($destination_command);
373 52 ▶ return "$ssh $userAt" . ( $hostname || 'localhost' ) . " $destination_command";
Condition50%1/2
$hostname || 'localhost'
l!l
520
MC/DC0%0/1
$hostname || 'localhost'
$hostname
Truth table50%1/2
A
A= $hostname
Aresult
11
00
374 }
375  
376 package Footprintless::Command::CommandOptions;
377 15 $Footprintless::Command::CommandOptions::VERSION = '1.29';
378 92 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
379 92 return bless( {}, shift )->_init(@_);
380 }
381  
382 9 ▶sub clone {
Subroutine clone: called CC=13 SCAR=32.8
383 9 my ( $instance, %options ) = @_;
384  
385 9 ▶ if ( exists( $instance->{hostname} ) && !exists( $options{hostname} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $instance->{"hostname"} and not exists $options{"hostname"}) 3 6 9
Condition66%2/3
exists $instance->{"hostname"} and not exists $options{"hostname"}
!ll&&!rl&&r
603
MC/DC50%1/2
exists $instance->{"hostname"} and not exists $options{"hostname"}
exists $instance->{"hostname"} not exists $options{"hostname"}
Truth table66%2/3
A and not(B)
A= exists $instance->{"hostname"}B= not exists $options{"hostname"}
ABresult
0X0
100
111
386 3 $options{hostname} = $instance->{hostname};
387 }
388 9 ▶ if ( exists( $instance->{ssh} ) && !exists( $options{ssh} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $instance->{"ssh"} and not exists $options{"ssh"}) 0 9 9
Condition66%2/3
exists $instance->{"ssh"} and not exists $options{"ssh"}
!ll&&!rl&&r
540
MC/DC0%0/2
exists $instance->{"ssh"} and not exists $options{"ssh"}
exists $instance->{"ssh"} not exists $options{"ssh"}
Truth table66%2/3
A and not(B)
A= exists $instance->{"ssh"}B= not exists $options{"ssh"}
ABresult
0X0
100
111
389 0 $options{ssh} = $instance->{ssh};
390 }
391 9 ▶ if ( exists( $instance->{username} ) && !exists( $options{username} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $instance->{"username"} and not exists $options{"username"}) 0 9 9
Condition33%1/3
exists $instance->{"username"} and not exists $options{"username"}
!ll&&!rl&&r
900
MC/DC0%0/2
exists $instance->{"username"} and not exists $options{"username"}
exists $instance->{"username"} not exists $options{"username"}
Truth table33%1/3
A and not(B)
A= exists $instance->{"username"}B= not exists $options{"username"}
ABresult
0X0
100
111
392 0 $options{username} = $instance->{username};
393 }
394 9 ▶ if ( exists( $instance->{sudo_command} ) && !exists( $options{sudo_command} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $instance->{"sudo_command"} and not exists $options{"sudo_command"}) 0 9 9
Condition33%1/3
exists $instance->{"sudo_command"} and not exists $options{"sudo_command"}
!ll&&!rl&&r
900
MC/DC0%0/2
exists $instance->{"sudo_command"} and not exists $options{"sudo_command"}
exists $instance->{"sudo_command"} not exists $options{"sudo_command"}
Truth table33%1/3
A and not(B)
A= exists $instance->{"sudo_command"}B= not exists $options{"sudo_command"}
ABresult
0X0
100
111
395 0 $options{sudo_command} = $instance->{sudo_command};
396 }
397 9 ▶ if ( exists( $instance->{sudo_username} ) && !exists( $options{sudo_username} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $instance->{"sudo_username"} and not exists $options{"sudo_username"}) 0 9 9
Condition66%2/3
exists $instance->{"sudo_username"} and not exists $options{"sudo_username"}
!ll&&!rl&&r
630
MC/DC0%0/2
exists $instance->{"sudo_username"} and not exists $options{"sudo_username"}
exists $instance->{"sudo_username"} not exists $options{"sudo_username"}
Truth table66%2/3
A and not(B)
A= exists $instance->{"sudo_username"}B= not exists $options{"sudo_username"}
ABresult
0X0
100
111
398 0 $options{sudo_username} = $instance->{sudo_username};
399 }
400 9 ▶ if ( exists( $instance->{pretty} ) && !exists( $options{pretty} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $instance->{"pretty"} and not exists $options{"pretty"}) 0 9 9
Condition33%1/3
exists $instance->{"pretty"} and not exists $options{"pretty"}
!ll&&!rl&&r
900
MC/DC0%0/2
exists $instance->{"pretty"} and not exists $options{"pretty"}
exists $instance->{"pretty"} not exists $options{"pretty"}
Truth table33%1/3
A and not(B)
A= exists $instance->{"pretty"}B= not exists $options{"pretty"}
ABresult
0X0
100
111
401 0 $options{pretty} = $instance->{pretty};
402 }
403  
404 9 return new( ref($instance), %options );
405 }
406  
407 121 ▶sub get_hostname {
Subroutine get_hostname: called CC=1 SCAR=0.0
408 121 return $_[0]->{hostname};
409 }
410  
411 121 ▶sub get_pretty {
Subroutine get_pretty: called CC=1 SCAR=0.0
412 121 return $_[0]->{pretty};
413 }
414  
415 121 ▶sub get_ssh {
Subroutine get_ssh: called CC=1 SCAR=0.0
416 121 return $_[0]->{ssh};
417 }
418  
419 127 ▶sub get_sudo_command {
Subroutine get_sudo_command: called CC=1 SCAR=0.0
420 127 return $_[0]->{sudo_command};
421 }
422  
423 127 ▶sub get_sudo_username {
Subroutine get_sudo_username: called CC=1 SCAR=0.0
424 127 return $_[0]->{sudo_username};
425 }
426  
427 121 ▶sub get_username {
Subroutine get_username: called CC=1 SCAR=0.0
428 121 return $_[0]->{username};
429 }
430  
431 92 ▶sub _init {
Subroutine _init: called CC=7 SCAR=19.5
432 92 my ( $self, %options ) = @_;
433  
434 92 ▶ $self->{hostname} = $options{hostname} if ( defined( $options{hostname} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"hostname"} 42 50 92
435 92 ▶ $self->{ssh} = $options{ssh} if ( defined( $options{ssh} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"ssh"} 38 54 92
436 92 ▶ $self->{username} = $options{username} if ( defined( $options{username} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"username"} 4 88 92
437 92 ▶ $self->{sudo_command} = $options{sudo_command} if ( defined( $options{sudo_command} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"sudo_command"} 4 88 92
438 92 ▶ $self->{sudo_username} = $options{sudo_username} if ( defined( $options{sudo_username} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"sudo_username"} 27 65 92
439 92 ▶ $self->{pretty} = $options{pretty} if ( defined( $options{pretty} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"pretty"} 0 92 92
440  
441 92 return $self;
442 }
443  
444 __END__
« Footprintless/CommandRunner/IPCRun.pm ↑ Summary Footprintless/Log.pm »