| 1 | package Serge::Interface::SysCmdRunner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | sub run_cmd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | my ($self, $command, $capture, $ignore_codes) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_cmd: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | if ($self->{echo_commands}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my $line = $command; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | $line =~ s/(\-\-password \").+?(\")/$1******$2/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | print "RUN: $line\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if ($capture) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $result = `$command`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | print "\n--------------------\n$result\n--------------------\n" if $self->{echo_output}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | system($command); # output will be echoed but not captured | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $error_code = unpack 'c', pack 'C', $? >> 8; # error code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (($error_code > 0) && $ignore_codes && (ref(\$ignore_codes) eq 'SCALAR' || (grep($_ eq $error_code, @$ignore_codes) > 0))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$error_code > 0 and $ignore_codes and ref \$ignore_codes eq "SCALAR" || grep(($_ eq $error_code), @$ignore_codes) > 0
$error_code > 0 and $ignore_codes
ref \$ignore_codes eq "SCALAR" or grep(($_ eq $error_code), @$ignore_codes) > 0
MC/DC0%0/4
$error_code > 0 and $ignore_codes and ref \$ignore_codes eq "SCALAR" || grep(($_ eq $error_code), @$ignore_codes) > 0
$error_code > 0
$ignore_codes
ref \$ignore_codes eq "SCALAR"
grep(($_ eq $error_code), @$ignore_codes) > 0
Truth table0%0/5
A and B and C or D
A= $error_code > 0B= $ignore_codesC= ref \$ignore_codes eq "SCALAR"D= grep(($_ eq $error_code), @$ignore_codes) > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | print "Exit code: $error_code (ignored)\n" if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $error_code = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | die $result."\nExit code: $error_code; last error: $!\n" if $error_code != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | sub run_in { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my ($self, $directory, $command, $capture, $ignore_codes) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_in: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | die "directory parameter shouldn't be empty" if $directory eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $curdir = getcwd(); # preserve current directory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (chdir($directory)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | print "RUN IN: $directory\n" if $self->{echo_commands}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $result = $self->run_cmd($command, $capture, $ignore_codes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | chdir($curdir); # restore current directory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | die "Failed to chdir to '$directory': $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||