Markup/Cmd.pm

filter: Statementstmt 70.6% 41 / 58 Branchbran 16.6% 2 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod 100% 3 / 3 totaltotal 63.3% 57 / 90 CC 10 SCAR 19.1
CC
10
Cov
60%
open_pipe
20.0
find_cmd
7.5
exec_or_die
3.7
CRAP 6.7
↑ Summary Markup/CommonMark.pm »
1 package Text::Markup::Cmd;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IPC::Open3;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;use constant WIN32 => $^O eq 'MSWin32';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our @EXPORT = qw(find_cmd exec_or_die open_pipe WIN32);
11  
12 3 ▶sub find_cmd {
Subroutine find_cmd: called CC=6 SCAR=20.2
Pod documented
13 3 my ($names, @opts) = @_;
14 3 my $cli;
15 EXE: {
16 3 for my $exe (@{ $names }) {
17 5 for my $p (File::Spec->path) {
18 50 my $path = File::Spec->catfile($p, $exe);
19 50 ▶ next unless -f $path && -x $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $path and -x $path 50 0 50
Condition33%1/3
-f $path and -x $path
!ll&&!rl&&r
5000
MC/DC0%0/2
-f $path and -x $path
-f $path -x $path
Truth table33%1/3
A and B
A= -f $pathB= -x $path
ABresult
0X0
100
111
20 0 $cli = $path;
21 0 last EXE;
22 }
23 }
24 }
25  
26 3 ▶ unless ($cli) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cli) 3 0 3
27 3 my $list = join(', ', @{ $names }[0..$#$names-1]) . ", or $names->[-1]";
28 3 Carp::croak( "Cannot find $list in path $ENV{PATH}" );
29 }
30  
31 # Make sure it looks like it will work.
32 0 exec_or_die("$cli will not execute", $cli, @opts);
33 0 return $cli;
34 }
35  
36 0 ▶sub exec_or_die {
Subroutine exec_or_die: not called CC=2 SCAR=13.0
Pod documented
37 0 my $err = shift;
38 0 my $output = gensym;
39 0 my $pid = open3(undef, $output, $output, @_);
40 0 waitpid $pid, 0;
41 0 ▶ return 1 unless $?;
Branch: 1 branch
BranchTrueFalseTotal
unless $? 0 0 0
42 1 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 0 local $/;
44 0 Carp::croak( qq{$err\n}, <$output> );
45 }
46  
47 # Stolen from SVN::Notify.
48 0 ▶sub open_pipe {
Subroutine open_pipe: not called CC=4 SCAR=30.0
Pod documented
49 # Ignored; looks like docutils always emits UTF-8.
50 0 if (WIN32) {
51 my $cmd = q{"} . join(q{" "}, @_) . q{"|};
52 open my $fh, $cmd or die "Cannot fork: $!\n";
53 return $fh;
54 }
55  
56 0 my $pid = open my $fh, '-|';
57 0 ▶ die "Cannot fork: $!\n" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
58  
59 0 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 0 0 0
60 # Parent process, return the file handle.
61 0 return $fh;
62 } else {
63 # Child process. Execute the commands.
64 0 ▶ exec @_ or die "Cannot exec $_[0]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
exec @_ or die "Cannot exec $_[0]: $!\n" 0 0 0
65 # Not reached.
66 }
67 }
68  
69 1 1;
70 __END__
↑ Summary Markup/CommonMark.pm »