lib/Serge/Interface/SysCmdRunner.pm

filter: Statementstmt 31.7% 13 / 41 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 20.7% 17 / 82 SCAR 47.9
CC
14
Cov
19%
run_cmd
110.0
run_in
30.0
BEGIN
1.0
CRAP 119.8
« lib/Serge/Sync/Plugin/VCS/mercurial.pm ↑ Summary lib/Serge/Sync/Plugin/VCS/git.pm »
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
BranchTrueFalseTotal
if ($self->{"echo_commands"}) 0 0 0
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
BranchTrueFalseTotal
if ($capture) { } 0 0 0
18 0 $result = `$command`;
19 0 ▶ print "\n--------------------\n$result\n--------------------\n" if $self->{echo_output};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"echo_output"} 0 0 0
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
BranchTrueFalseTotal
if ($error_code > 0 and $ignore_codes and ref \$ignore_codes eq "SCALAR" || grep(($_ eq $error_code), @$ignore_codes) > 0) 0 0 0
Condition0%0/9
$error_code > 0 and $ignore_codes and ref \$ignore_codes eq "SCALAR" || grep(($_ eq $error_code), @$ignore_codes) > 0
!ll&&!rl&&r
000
$error_code > 0 and $ignore_codes
!ll&&!rl&&r
000
ref \$ignore_codes eq "SCALAR" or grep(($_ eq $error_code), @$ignore_codes) > 0
l!l&&r!l&&!r
000
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
ABCDresult
0XXX0
10XX0
11000
111X1
11011
26 0 ▶ print "Exit code: $error_code (ignored)\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
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
BranchTrueFalseTotal
if $error_code != 0 0 0 0
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
BranchTrueFalseTotal
if $directory eq "" 0 0 0
39  
40 0 my $result;
41 0 my $curdir = getcwd(); # preserve current directory
42 0 ▶ if (chdir($directory)) {
Branch: 1 branch
BranchTrueFalseTotal
if (chdir $directory) { } 0 0 0
43 0 ▶ print "RUN IN: $directory\n" if $self->{echo_commands};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"echo_commands"} 0 0 0
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
BranchTrueFalseTotal
if $@ 0 0 0
49 } else {
50 0 die "Failed to chdir to '$directory': $!";
51 }
52 0 return $result;
53 }
54  
55 1 1;
« lib/Serge/Sync/Plugin/VCS/mercurial.pm ↑ Summary lib/Serge/Sync/Plugin/VCS/git.pm »