| 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
Condition33%1/3
-f $path and -x $path
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
| |||||||||||||||||||||||||||||
| 20 | 0 | $cli = $path; | |||||||||||||||||||||||||||
| 21 | 0 | last EXE; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | unless ($cli) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | # Not reached. | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||