| 1 | package Proc::ShellSpawn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Runs Proc::ShellSubset parse trees with posix_spawn(3), in the simplest scenario: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # this module is the only code that starts child processes, and it owns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # SIGCHLD while it runs. No fork in Perl: compound commands, pipelines of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # them, subshells, $( ), loops and background chains run in this process as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # continuations driven by one event loop. This is the shell layer only: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # loop and the starting of children are Proc::Spawner's, the ends and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # process nodes (with the continuation each runs when it ends) Proc::Spawner::Graph's. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Aim: what dash and bash do alike (the parsers reject what they do differently); where the two differ only at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # run time, as dash does (rule A5, doc/large-subset/large-subset-spec.md). Every program started is a child of this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Perl process, never a grandchild. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Process-wide state flipped for a while, so bullet-proof only in non-threaded execution: Perl's umask, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # set to the shell's while a redirection's file is opened (open_end); SIGINT, SIGQUIT and SIGPIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # ignored while run() runs (ignoring_int); traps, set in %SIG while run() runs and put back after it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # (Proc::ShellSpawn::Large, b_trap); SIGCHLD between run() calls while background jobs remain (idle, K3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # and Proc::Spawner's own (umask in start, SIGCHLD in wait_until). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 483 | ▶ | use strict; use warnings; use feature 'current_sub'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 483 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 483 | ▶ | use File::Glob (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 483 | ▶ | use Cwd (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 483 | ▶ | use Proc::Spawner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 483 | ▶ | use Proc::Spawner::Graph; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 483 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 481 | our $VERSION = '0.11'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 481 | our $TRACE; *TRACE = \$Proc::Spawner::TRACE; # undef, or a code ref given one line per fd or process operation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 481 | our %PARSE = map +($_ => 1), qw(assign param_ops if while for case read empty); # options for Proc::ShellSubset and Proc::ShellSubset::Large | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # (empty, post4-0.04: a string with no command, or only comments, runs as nothing, status 0, as in both shells; also eval '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # The parser for run(STRING): run(STRING, parser => CODE), CODE->(TEXT) returning a tree or an error hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Default (EXPERIMENTAL, awaiting approval): the largest of Proc::ShellSubset::Large, Proc::ShellSubset, Proc::ShellSubset::Small that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # caller has loaded; if none is, Proc::ShellSubset is loaded. The executor itself loads no parser otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 482 | ▶ | sub default_parser { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_parser: called CC=4 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 515 | ▶ | defined &Proc::ShellSubset::Large::parse ? sub { Proc::ShellSubset::Large::parse($_[0], %PARSE, @_[1 .. $#_]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | : defined &Proc::ShellSubset::parse ? sub { Proc::ShellSubset::parse($_[0], %PARSE) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | : defined &Proc::ShellSubset::Small::parse ? \&Proc::ShellSubset::Small::parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | : do { require Proc::ShellSubset; sub { Proc::ShellSubset::parse($_[0], %PARSE) } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=2.9
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 481 | our $NAME = 'sh'; # prefix of error messages, as sh's "$0" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # EXPERIMENTAL (item N9): with TRACE=dot, one Graphviz picture per event (a start, an exit, an end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # closed) as trace-001.dot, ... in the directory TRACE_DIR (default: the current one). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 481 | ▶ | our $DOT = ($ENV{TRACE} // '') eq 'dot' ? $ENV{TRACE_DIR} // '.' : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$ENV{"TRACE"} // ""
$ENV{"TRACE_DIR"} // "."
MC/DC0%0/1
$ENV{"TRACE"} // ""
$ENV{"TRACE"}
MC/DC0%0/1
$ENV{"TRACE_DIR"} // "."
$ENV{"TRACE_DIR"}
Truth table50%1/2
A
A= $ENV{"TRACE"}
Truth table0%0/2
A
A= $ENV{"TRACE_DIR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 656 | ▶ | sub tr_ { $TRACE->(join '', @_) if $TRACE } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tr_: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 481 | our $G = Proc::Spawner::Graph->new(dot => $DOT); # our children and our own reads and writes, now | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # ------------------------------------------------------------------ extension points (EXPERIMENTAL, awaiting approval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Handlers are named by fully qualified sub names, resolved (and their module loaded) at first use: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # a command node { ext => NAME, ... }, or one with a key of %KIND: NAME->(CONTEXT, NODE, TAIL, K) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # a command name in %CMD (or the shell's own table, for functions): NAME->(CONTEXT, ARGV, ENV, K, DATA) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # a Part [ext => NAME, ...] of a Word: NAME->(CONTEXT, PART, K) with K->(TEXT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Each calls K exactly once (or ends the shell with leave), maybe later, and never waits (D2). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 481 | our %KIND = map +($_ => "Proc::ShellSpawn::Large::x_$_"), qw(func export readonly local exec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 481 | our %CMD = ((map +($_ => ['Proc::ShellSpawn::builtin']), ':', qw(exit break continue read)), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | (map +($_ => ["Proc::ShellSpawn::Large::b_$_"]), qw(return shift set eval trap wait umask command getopts unset kill pwd)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | '.' => ['Proc::ShellSpawn::Large::b_dot'], (map +($_ => ['Proc::ShellSpawn::Large::b_test']), '[', 'test')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 481 | our $ONBUILTIN; # undef, or a code ref called (HANDLER, [ARGV], {SETTINGS}) for each command where no program runs: before a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # builtin or function runs (cd: x_cd; export, readonly, local: x_NAME, after), a command not found ('not found', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # 'denied'), settings alone (x_set, ARGV empty, after) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 481 | our %A4; # builtins left to sh: A4 (status 248) when one is named at run time | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # B2 of "Shell Corpus Gaps": the tables of command names, searched in order; a module adds its own with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # unshift @Proc::ShellSpawn::CMDS, \%MINE (Proc::ShellSpawn::Builtins does). %A4 stays last. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 481 | our @CMDS = (\%CMD, \%A4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1251 | ▶ | sub cmd_of { my $n = shift; for (@CMDS) { return $_->{$n} if exists $_->{$n} } undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_of: called CC=3 SCAR=11.0
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 480 | ▶ | sub a4 { $A4{$_} //= ['Proc::ShellSpawn::Large::b_unsupported'] for keys %Proc::ShellSubset::BI } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
a4: called CC=3 SCAR=11.0
Pod
undocumented
Condition100%2/2
$Proc::ShellSpawn::A4{$_} //= ["Proc::ShellSpawn::Large::b_unsupported"]
MC/DC100%1/1
$Proc::ShellSpawn::A4{$_} //= ["Proc::ShellSpawn::Large::b_unsupported"]
$Proc::ShellSpawn::A4{$_}
Truth table100%2/2
A
A= $Proc::ShellSpawn::A4{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 481 | our $SIGNALLED; # after run(): the signal of 'kill ... $$' that ended the string, if any | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 481 | our %TRAPSAVE; # signals the trap builtin changed during run(), with their old settings | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 481 | our %SPECIAL = map +($_ => 1), qw(: break continue . eval exec exit export readonly return set shift times trap unset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 483 | ▶ | BEGIN { *handler = \&Proc::Spawner::Graph::handler } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 26 | ▶ | sub fail { # stop this shell with $st, after the message $text if given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 26 | ▶ | my ($c, $st, $text) = @_; defined $text ? msg($c, $text, sub { leave($c, $st) }) : defer(\&leave, $c, $st); return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # ------------------------------------------------------------------ ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # The ends (Proc::Spawner::Graph) are what a context maps its fds to; each context holds the ends of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # its map, and the last release closes one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1428 | ▶ | sub own_fd { $G->parent_end(shift) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
own_fd: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1434 | ▶ | sub is_open { my $d = POSIX::dup($_[0]) // return 0; POSIX::close($d); 1 } # without touching its flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_open: called CC=2 SCAR=7.1
Pod
undocumented
Condition50%1/2
POSIX::dup($_[0]) // (return 0)
MC/DC0%0/1
POSIX::dup($_[0]) // (return 0)
POSIX::dup($_[0])
Truth table50%1/2
A
A= POSIX::dup($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | ▶ | sub visible { # open and not close-on-exec: an fd sh would have inherited (not ours, nor the caller's handles) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
visible: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 7 | Proc::Spawner::__fd_cloexec(shift) == 0 } # fcntl F_GETFD (until 0.05: /proc/self/fdinfo, Linux only; RT #182479) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 164 | ▶ | sub new_pipe { $G->new_pipe } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_pipe: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # ------------------------------------------------------------------ paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # POSIX, and Windows (post-0.10): there a path is absolute with a drive (C:/x, C:\x) or as a UNC name (//server/share); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # /x is the current drive's root; \ separates as / does; PATH is split at $Config{path_sep} (;, Proc::Spawner::path_split) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # and a command is looked up with the extensions of PATHEXT first; /dev/null is NUL. The shell's own directory keeps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Perl's form (C:/x/y). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 481 | our $WIN = $Proc::Spawner::WIN; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 481 | ▶ | my $SEP = $WIN ? qr{[/\\]+} : qr{/+}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 532 | ▶ | sub is_abs { $WIN ? $_[0] =~ m{^(?:[A-Za-z]:)?[/\\]} : $_[0] =~ m{^/} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_abs: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 575 | ▶ | sub has_dir { $WIN ? $_[0] =~ m{[/\\]} : $_[0] =~ m{/} } # a command name with a directory: no PATH lookup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_dir: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2320 | ▶ | sub path_in { # PATH from the shell's directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_in: called CC=6 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2318 | my ($c, $p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2320 | ▶ | return $p if $WIN ? $p =~ m{^[A-Za-z]:[/\\]|^[/\\]{2}} : $p =~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 48 | ▶ | return ($c->{sh}{cwd} =~ m{^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)} ? $1 : '') . $p if $WIN && $p =~ m{^[/\\]}; # (the drive, or the UNC share) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$Proc::ShellSpawn::WIN and $p =~ m(^[/\\])
MC/DC0%0/2
$Proc::ShellSpawn::WIN and $p =~ m(^[/\\])
$Proc::ShellSpawn::WIN
$p =~ m(^[/\\])
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= $p =~ m(^[/\\])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 48 | "$c->{sh}{cwd}/$p" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 264 | ▶ | sub path_list { Proc::Spawner::path_split(@_) } # a PATH value's directories (an empty one: the current directory, POSIX) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | sub win_home { # ~user on Windows (post-0.10, the user's follow-up (b) to WS1): one's own name is %USERPROFILE%; another | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
win_home: called CC=6 SCAR=32.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # is its sibling of that name, if that is a directory (profiles are usually siblings; not always: the registry's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # ProfileList has the real ones, a domain profile may be user.DOMAIN); else undef (~user stays as written) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my $n = shift; my $up = $ENV{USERPROFILE} // return; return if $n =~ /^\.\.?\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{"USERPROFILE"} // (return)
MC/DC0%0/1
$ENV{"USERPROFILE"} // (return)
$ENV{"USERPROFILE"}
Truth table0%0/2
A
A= $ENV{"USERPROFILE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | ▶ | return $up if lc $n eq lc($ENV{USERNAME} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{"USERNAME"} // ""
MC/DC0%0/1
$ENV{"USERNAME"} // ""
$ENV{"USERNAME"}
Truth table0%0/2
A
A= $ENV{"USERNAME"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | my $d = ($up =~ s{[^/\\]+[/\\]*\z}{}r) . $n; -d $d ? $d : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 107 | ▶ | sub os_path { my $p = shift; $WIN && $p eq '/dev/null' ? 'NUL' : $p } # a redirection's file name, as the system has it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
os_path: called CC=3 SCAR=13.1
Pod
undocumented
Branch: 1 branch
Condition33%1/3
$Proc::ShellSpawn::WIN and $p eq "/dev/null"
MC/DC0%0/2
$Proc::ShellSpawn::WIN and $p eq "/dev/null"
$Proc::ShellSpawn::WIN
$p eq "/dev/null"
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= $p eq "/dev/null"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 106 | ▶ | sub open_end { # an end on a file, or undef with $! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_end: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 107 | my ($c, $name, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 107 | my $path = path_in($c, os_path($name)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 107 | ▶ | return $! = POSIX::EEXIST(), undef if $op eq '>' && $c->{sh}{opt}{C} && -f $path; # set -C | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$op eq ">" and $c->{"sh"}{"opt"}{"C"} and -f $path
$op eq ">" and $c->{"sh"}{"opt"}{"C"}
MC/DC100%3/3
$op eq ">" and $c->{"sh"}{"opt"}{"C"} and -f $path
$op eq ">"
$c->{"sh"}{"opt"}{"C"}
-f $path
Truth table100%4/4
A and B and C
A= $op eq ">"B= $c->{"sh"}{"opt"}{"C"}C= -f $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 106 | my $um = umask $c->{sh}{umask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 106 | my $ok = sysopen my $fh, $path, $Proc::Spawner::Graph::OPEN{$op}, 0666; my $err = $!; umask $um; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 105 | ▶ | $! = $err, return unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 88 | $G->file_end($fh, $op, $name) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # ------------------------------------------------------------------ contexts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # A context: what the commands run in it get. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # map => { CHILD_FD => end, or undef for closed }; fds not listed are ours, inherited as they are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # sh => the shell state: vars, exp(orted names), cwd, q ($?), bang ($!), qsub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # loops => [ { brk => K, cont => K, scope => [contexts] }, ... ] of the enclosing loops | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # shell => { exit => K, scope => [contexts] } for exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # held => 1 if this context holds its map's ends; released by release_ctx, once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 756 | ▶ | sub derive { # a context with its own map, which it holds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
derive: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 758 | my ($c, $map, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 758 | my $d = { %$c, map => $map, held => 1, released => 0, root => !!$o{shell}, late => 0 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 758 | ▶ | if (my $k = $o{shell}) { # a new shell: copies of the state; exit and loops start afresh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 296 | my $sh = $c->{sh}; # leaving it releases every context made in it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 296 | $d->{sh} = { %$sh, main => $sh->{main} // $sh, vars => { %{$sh->{vars}} }, exp => { %{$sh->{exp}} }, args => [@{$sh->{args}}], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 294 | ▶ | opt => { %{$sh->{opt}} }, cmd => { %{$sh->{cmd}} }, ro => { %{$sh->{ro}} }, jobl => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 231 | ▶ | ljobs => $o{jobs} ? [@{$sh->{ljobs} // []}, @{$sh->{jobl}}] : [], # jobs listed in a pipeline or $( ) (rule E) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sh->{"ljobs"} // []
MC/DC100%1/1
$sh->{"ljobs"} // []
$sh->{"ljobs"}
Truth table100%2/2
A
A= $sh->{"ljobs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | pend => [], twait => [], tbusy => 0, # the caught signals belong to the shell whose trap caught them (X19) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 296 | ▶ | trap => { map +($_ => ''), grep $sh->{trap}{$_} eq '', keys %{$sh->{trap}} } }; # sh: only ignored traps stay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sh->{"main"} // $sh
MC/DC0%0/2
$sh->{"main"} // $sh
$sh->{"main"}
$sh
Truth table66%2/3
A // B
A= $sh->{"main"}B= $sh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 296 | my $scope = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 296 | $d->{loops} = []; delete @$d{qw(frame cond)}; $d->{shell} = { scope => $scope, exit => shell_exit($d, $scope, $k) } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 758 | hold($_) for values %$map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 758 | ▶ | push @{ @{$d->{loops}} ? $d->{loops}[-1]{scope} : $d->{shell}{scope} }, $d; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 756 | $d } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 58 | ▶ | sub leave { my ($c, $st) = @_; release_all(map $_->{scope}, @{$c->{loops}}); $c->{shell}{exit}->($st) } # exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 772 | ▶ | sub shell_exit { # the end of a shell: its EXIT trap first (once; an exit inside the trap ends it there) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shell_exit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 772 | my ($c, $scope, $k) = @_; weaken($c); my $state = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 773 | ▶ | sub { my $st = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 769 | ▶ | return if $state == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 769 | ▶ | my $a = $state == 0 && $c && delete $c->{sh}{trap}{EXIT}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$state == 0 && $c && delete $c->{'sh'}{'trap'}{'EXIT'}
$state == 0 and $c
MC/DC66%2/3
$state == 0 && $c && delete $c->{'sh'}{'trap'}{'EXIT'}
$state == 0
$c
delete $c->{'sh'}{'trap'}{'EXIT'}
Truth table75%3/4
A and B && C
A= $state == 0B= $cC= delete $c->{'sh'}{'trap'}{'EXIT'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 769 | ▶ | if (defined $a && $a ne '' and ref(my $t = $c->{sh}{parse}->($a, nolineno => 1)) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $a and $a ne "" and ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
defined $a and $a ne ""
MC/DC66%2/3
defined $a and $a ne "" and ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
defined $a
$a ne ""
ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
Truth table75%3/4
A and B and C
A= defined $aB= $a ne ""C= ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | $state = 1; my $tc = { %$c, loops => [], held => 0, cond => undef, frame => undef }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 12 | ▶ | return x_list($tc, $t, undef, sub { return if $state == 2; $state = 2; late($c); release_all($scope); $k->($st) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 772 | $state = 2; late($c); release_all($scope); $k->($st) } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 772 | ▶ | sub late { my $c = shift; release_ctx($c) if $c && $c->{late} } # the release a trap postponed (the trap is gone by now) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
late: called CC=3 SCAR=11.1
Pod
undocumented
Branch: 1 branch
Condition66%2/3
$c and $c->{"late"}
MC/DC50%1/2
$c and $c->{"late"}
$c
$c->{"late"}
Truth table66%2/3
A and B
A= $cB= $c->{"late"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1428 | ▶ | sub release_ctx { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
release_ctx: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1426 | ▶ | my $c = shift; return if !$c->{held} or $c->{released}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $c->{"held"} or $c->{"released"}
MC/DC50%1/2
not $c->{"held"} or $c->{"released"}
not $c->{"held"}
$c->{"released"}
Truth table66%2/3
not(A) or B
A= not $c->{"held"}B= $c->{"released"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 763 | ▶ | return $c->{late} = 1 if $c->{root} && ($c->{sh}{trap}{EXIT} // '') ne ''; # its EXIT trap still needs them (L5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$c->{"root"} and ($c->{"sh"}{"trap"}{"EXIT"} // "") ne ""
$c->{"sh"}{"trap"}{"EXIT"} // ""
MC/DC100%2/2
$c->{"root"} and ($c->{"sh"}{"trap"}{"EXIT"} // "") ne ""
$c->{"root"}
$c->{"sh"}{"trap"}{"EXIT"}
Truth table100%3/3
A and B
A= $c->{"root"}B= $c->{"sh"}{"trap"}{"EXIT"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 762 | $c->{released} = 1; release($_) for values %{$c->{map}} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 977 | ▶ | sub release_all { for my $s (@_) { release_ctx($_) for @$s; @$s = () } } # also breaks the cycles through the scopes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
release_all: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # ------------------------------------------------------------------ the loop and the graph | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # Proc::Spawner runs the loop; every continuation runs from its queue, one at a time, and never waits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Our children and our own reads and writes are nodes of the graph $G (Proc::Spawner::Graph); a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # child's node carries its continuation as on_exit ['Proc::ShellSpawn::resume', K]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 483 | ▶ | BEGIN { *defer = \&Proc::Spawner::defer; *hold = \&Proc::Spawner::Graph::hold; *release = \&Proc::Spawner::Graph::release } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 483 | ▶ | sub loop_until { Proc::Spawner::wait_until(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop_until: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1807 | ▶ | sub on_read { my ($e, $n, $cb) = @_; $G->perl_read($e, $n, sub { $cb->($_[1]) }) } # one read of end $e: $cb->(BYTES), or undef at end of file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
on_read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 768 | ▶ | sub on_write { my ($e, $bytes, $cb) = @_; $G->perl_write($e, $bytes, $cb) } # Perl writes BYTES to end $e without blocking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_write: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 272 | ▶ | sub status_of { # a wait status as sh's $? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_of: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 272 | my $w = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 266 | ▶ | $w & 127 ? 128 + ($w & 127) : $w >> 8 } # (by hand: Windows' POSIX has no WIFSIGNALED; Perl's $? is the same there) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # Background jobs left running when run() returns go on between calls too (idle, below); at exit we finish them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 481 | my %JOBS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # As Perl's system: SIGINT and SIGQUIT are ignored here while commands run (a foreground child gets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # them back by sigdefault; a background child keeps them ignored, as POSIX asks of an asynchronous list). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 492 | ▶ | sub ignoring_int { local @SIG{qw(INT QUIT PIPE)} = ('IGNORE') x 3; $_[0]->() } # PIPE: a here-document's reader may go away | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ignoring_int: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | ▶ | sub wait_all { idle(0); ignoring_int(sub { loop_until(sub { !%JOBS }) }) if %JOBS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
wait_all: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 482 | ▶ | END { local $?; wait_all() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Between run() calls (K3, the user's choice B, post-0.04): while background jobs remain, a deferred SIGCHLD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # handler moves them on when a child ends, whatever Perl is doing (a chain's next command starts at once). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Its cost, documented: the program's own sleep and select return early when a child ends, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # program's own $SIG{CHLD} is called by ours (a CODE handler; set afterwards, it replaces ours). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 481 | our $RUNNING = 0; # inside run(): the loop there does it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 481 | my ($IDLE_ON, $IDLE_OLD); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 479 | ▶ | sub idle_pass { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
idle_pass: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 479 | ▶ | return if $RUNNING || !%JOBS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Proc::ShellSpawn::RUNNING or not %JOBS
MC/DC50%1/2
$Proc::ShellSpawn::RUNNING or not %JOBS
$Proc::ShellSpawn::RUNNING
not %JOBS
Truth table66%2/3
A or not(B)
A= $Proc::ShellSpawn::RUNNINGB= not %JOBS
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 14 | ignoring_int(\&Proc::Spawner::poll); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 14 | ▶ | idle(0) unless %JOBS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 958 | ▶ | sub idle { # 1: install the handler (if jobs remain), 0: put the previous one back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
idle: called CC=8 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 958 | my $on = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 958 | ▶ | return if $WIN; # (no SIGCHLD there: background jobs move on at the next run, wait or poll) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 958 | ▶ | if ($on && %JOBS && !$IDLE_ON) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
$on and %JOBS and not $IDLE_ON
$on and %JOBS
MC/DC66%2/3
$on and %JOBS and not $IDLE_ON
$on
%JOBS
not $IDLE_ON
Truth table75%3/4
A and B and not(C)
A= $onB= %JOBSC= not $IDLE_ON
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 11 | $IDLE_OLD = POSIX::SigAction->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $a = POSIX::SigAction->new(sub { idle_pass(); my $h = $IDLE_OLD && $IDLE_OLD->{HANDLER}; $h->(@_) if ref $h eq 'CODE' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=19.2
Branch: 1 branch
Condition33%1/3
$IDLE_OLD && $IDLE_OLD->{'HANDLER'}
MC/DC0%0/2
$IDLE_OLD && $IDLE_OLD->{'HANDLER'}
$IDLE_OLD
$IDLE_OLD->{'HANDLER'}
Truth table33%1/3
A && B
A= $IDLE_OLDB= $IDLE_OLD->{'HANDLER'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 11 | POSIX::SigSet->new, POSIX::SA_RESTART()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 11 | $a->safe(1); # deferred: runs between Perl operations, never inside the signal (S2) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 11 | ▶ | POSIX::sigaction(POSIX::SIGCHLD(), $a, $IDLE_OLD) and $IDLE_ON = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 11 | ▶ | elsif (!$on && $IDLE_ON) { POSIX::sigaction(POSIX::SIGCHLD(), $IDLE_OLD); $IDLE_ON = 0 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $on and $IDLE_ON
MC/DC100%2/2
not $on and $IDLE_ON
not $on
$IDLE_ON
Truth table100%3/3
not(A) and B
A= not $onB= $IDLE_ON
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # ------------------------------------------------------------------ spawning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # Signals ignored when we were loaded stay ignored in children, as sh keeps the ones ignored on entry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # SIGFPE as Perl's own exec would pass it: Perl may ignore it for itself at startup, and puts back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # the disposition it found then (PERL_FPU_PRE_EXEC, PL_sigfpe_saved; fpe_at_exec() reads it). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 481 | my $FPE = Proc::Spawner::fpe_at_exec(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 481 | ▶ | my %IGN0 = map +($_ => 1), grep +($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1), keys %SIG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition62%5/8
($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1)
$SIG{$_} // ""
$_ ne "FPE" or $FPE == 1
MC/DC0%0/3
($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1)
$SIG{$_}
$_ ne "FPE"
$FPE == 1
Truth table50%2/4
A && B or C
A= $SIG{$_}B= $_ ne "FPE"C= $FPE == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 190 | ▶ | sub put { # Perl writes $t to the context's fd $fd, then $then->(); never waits (L10). Callers go on only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # in $then, so nothing started later overtakes the text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 190 | ▶ | my ($c, $fd, $t, $then) = @_; $then //= sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Condition33%1/3
$then //= sub {
}
MC/DC0%0/2
$then //= sub {
}
$then
sub {
}
Truth table33%1/3
A //= B
A= $thenB= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 190 | my $e = $c->{map}{$fd}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 190 | ▶ | $e ? do { hold($e); on_write($e, $t, sub { release($e); $then->() }) } : defer($then); return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 84 | ▶ | sub msg { my ($c, $text, $then) = @_; put($c, 2, "$NAME: $text\n", $then) } # an error message, to fd 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
msg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 566 | ▶ | sub write_fd { # as put, then $k->(ERRNO or undef): EBADF when the fd is closed (and there is something to write) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_fd: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 566 | my ($c, $fd, $t, $k) = @_; my $e = $c->{map}{$fd}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 566 | ▶ | return defer($k, undef) if $t eq ''; return defer($k, POSIX::EBADF()) unless $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 565 | ▶ | hold($e); on_write($e, $t, sub { my $err = $! + 0; release($e); $k->($err || undef) }); return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$err || undef
MC/DC100%1/1
$err || undef
$err
Truth table100%2/2
A
A= $err
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # Programs run inside this process (Proc::ShellSpawn::Programs, after coreutils 9.4), by name (X21). Decision IP1 (the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # user, 2026-11-08: "when a well-debugged builtin is already present, use it. (By default; Configurable.)"): echo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # printf test [ true false, and since post-0.10 pwd (b_pwd runs it as 'pwd -L', X23), on every platform; PROC_SHELLSPAWN_INPROC changes the default (none: the programs; names: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # only these; all), and %INPROC can be changed at run time. A name with a '/' is always a program. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 481 | our @INPROC = qw(echo printf test [ true false pwd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | our %INPROC = map +($_ => 1), map $_ eq 'all' ? @INPROC : $_ eq 'none' ? () : $_, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 481 | ▶ | split ' ', $ENV{PROC_SHELLSPAWN_INPROC} // 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$ENV{"PROC_SHELLSPAWN_INPROC"} // "all"
MC/DC100%1/1
$ENV{"PROC_SHELLSPAWN_INPROC"} // "all"
$ENV{"PROC_SHELLSPAWN_INPROC"}
Truth table100%2/2
A
A= $ENV{"PROC_SHELLSPAWN_INPROC"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Whose echo the in-process echo is (decision EC1, the user, 2026-11-09): coreutils (the default; it heeds POSIXLY_CORRECT), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # dash or bash (their builtins, which do not); $ECHO can be changed at run time. The program echo (not in %INPROC) is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # affected. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 481 | ▶ | our $ECHO = $ENV{PROC_SHELLSPAWN_ECHO} || 'coreutils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'PROC_SHELLSPAWN_ECHO'} || 'coreutils'
MC/DC100%1/1
$ENV{'PROC_SHELLSPAWN_ECHO'} || 'coreutils'
$ENV{'PROC_SHELLSPAWN_ECHO'}
Truth table100%2/2
A
A= $ENV{'PROC_SHELLSPAWN_ECHO'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 481 | ▶ | die "PROC_SHELLSPAWN_ECHO: '$ECHO' is none of coreutils, dash, bash\n" unless $ECHO =~ /\A(?:coreutils|dash|bash)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # sh as Perl with this module (post-0.10, SH1, the user's follow-up (c) to WS1: "Windows has no sh"): a command named sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # (no directory) runs as $^X -MPARSER -MProc::ShellSpawn=sh -e0 -- ARGS, PARSER the largest parser loaded here (as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # default_parser), with this Perl's @INC; then sh_main below reads ARGS as sh does. PROC_SHELLSPAWN_SH (or $SH at run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # time): auto (the default: so when the command's PATH has no sh), perl (always), program (never). The text after -c is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # an argument: through the primitive system1 on Windows, Perl's own spawn drops a " from it, and splits it at blanks too if it has one (❰BUG❱ in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # Perl, doc/perl-win32-system-bugs.md, 1); not worked around. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 481 | ▶ | our $SH = $ENV{PROC_SHELLSPAWN_SH} || 'auto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'PROC_SHELLSPAWN_SH'} || 'auto'
MC/DC100%1/1
$ENV{'PROC_SHELLSPAWN_SH'} || 'auto'
$ENV{'PROC_SHELLSPAWN_SH'}
Truth table100%2/2
A
A= $ENV{'PROC_SHELLSPAWN_SH'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 481 | ▶ | die "PROC_SHELLSPAWN_SH: '$SH' is none of auto, perl, program\n" unless $SH =~ /\A(?:auto|perl|program)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 280 | ▶ | sub sh_argv { # the argv of sh as Perl, or undef: run the program sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sh_argv: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 278 | my ($c, $argv, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 278 | ▶ | return if $argv->[0] ne 'sh' or $SH eq 'program' or $SH eq 'auto' && defined((find_cmd($c, 'sh', $path))[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program" or $Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0])
$argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program"
$Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0])
MC/DC75%3/4
$argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program" or $Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0])
$argv->[0] ne "sh"
$Proc::ShellSpawn::SH eq "program"
$Proc::ShellSpawn::SH eq "auto"
defined((find_cmd($c, "sh", $path))[0])
Truth table80%4/5
A or B or C and D
A= $argv->[0] ne "sh"B= $Proc::ShellSpawn::SH eq "program"C= $Proc::ShellSpawn::SH eq "auto"D= defined((find_cmd($c, "sh", $path))[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 483 | ▶ | my ($parser) = grep { no strict 'refs'; defined &{"${_}::parse"} } qw(Proc::ShellSubset::Large Proc::ShellSubset Proc::ShellSubset::Small); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 10 | ▶ | [$^X, (map "-I$_", grep !ref, @INC), '-M' . ($parser // 'Proc::ShellSubset'), '-MProc::ShellSpawn=sh', '-e0', '--', @$argv[1 .. $#$argv]] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$parser // "Proc::ShellSubset"
MC/DC0%0/1
$parser // "Proc::ShellSubset"
$parser
Truth table50%1/2
A
A= $parser
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1130 | ▶ | sub import { # use Proc::ShellSpawn 'sh': run as sh with @ARGV, then exit (SH1); with no list, nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1130 | ▶ | my ($pkg, @w) = @_; return unless @w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | die "Proc::ShellSpawn: only 'sh' can be imported\n" unless @w == 1 && $w[0] eq 'sh'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@w == 1 and $w[0] eq "sh"
MC/DC0%0/2
@w == 1 and $w[0] eq "sh"
@w == 1
$w[0] eq "sh"
Truth table0%0/3
A and B
A= @w == 1B= $w[0] eq "sh"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | exit sh_main(@ARGV) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | sub sh_main { # sh -c TEXT [NAME [ARGS]], sh FILE [ARGS], sh [-s] [ARGS] (the text from stdin): the exit status | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sh_main: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my @a = @_; my ($opt_c, $opt_s, $text, $name, %opt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my $bad = sub { print STDERR "sh: $_[0]\n"; 2 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | while (@a && $a[0] =~ /\A-(.+)\z/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@a and $a[0] =~ /\A-(.+)\z/s
MC/DC0%0/2
@a and $a[0] =~ /\A-(.+)\z/s
@a
$a[0] =~ /\A-(.+)\z/s
Truth table0%0/3
A and B
A= @aB= $a[0] =~ /\A-(.+)\z/s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | shift @a; last if $1 eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | for my $l (split //, $1) { # -c, -s; other letters as set takes them (-e, -u, -x, ...) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $l eq 'c' ? ($opt_c = 1) : $l eq 's' ? ($opt_s = 1) : $l =~ /\A[a-zA-Z]\z/ && $l ne 'o' && $l ne 'i' ? ($opt{$l} = 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/6
$l =~ /\A[a-zA-Z]\z/ and $l ne "o" and $l ne "i"
$l =~ /\A[a-zA-Z]\z/ and $l ne "o"
MC/DC0%0/3
$l =~ /\A[a-zA-Z]\z/ and $l ne "o" and $l ne "i"
$l =~ /\A[a-zA-Z]\z/
$l ne "o"
$l ne "i"
Truth table0%0/4
A and B and C
A= $l =~ /\A[a-zA-Z]\z/B= $l ne "o"C= $l ne "i"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | : return $bad->("-$l: option not supported here (SH1)") } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ($opt_c) { @a or return $bad->('-c requires an argument'); $text = shift @a; $name = shift @a } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ▶ | elsif (!$opt_s && @a) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $opt_s and @a
MC/DC0%0/2
not $opt_s and @a
not $opt_s
@a
Truth table0%0/3
not(A) and B
A= not $opt_sB= @a
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | $name = shift @a; open my $f, '<', $name or return $bad->("0: cannot open $name: $!"); binmode $f; local $/; $text = <$f> } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | else { binmode STDIN; local $/; $text = <STDIN> // '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
readline STDIN // ""
MC/DC0%0/1
readline STDIN // ""
readline STDIN
Truth table0%0/2
A
A= readline STDIN
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | local $NAME = $name // 'sh'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$name // "sh"
MC/DC0%0/1
$name // "sh"
$name
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my ($st, $err) = run($text, args => \@a, arg0 => $NAME, opt => \%opt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | defined $st or print(STDERR "$NAME: outside the subset: $err->{error} at $err->{pos}\n"), return 255; # (as t/try.pl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if (my $s = $SIGNALLED) { local $SIG{$s} = 'DEFAULT'; kill $s, $$; sleep 1 } # die by it, as sh would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $st } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # TEMPORARY WORKAROUND (post-0.10, BIN1; the user's follow-up (d) to WS1, "Replace them from %ENV (inventing suitable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # fallbacks)", marked temporary by the user, 2026-11-10): where cat, sort, grep and the like come from. The directories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # in PROC_SHELLSPAWN_BIN (split as PATH; 'none': none, since Windows has no empty variables) are searched before PATH, on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # any platform. Unset, on Windows: the first of Git for Windows' usr\bin (beside git.exe on PATH, or under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # %ProgramFiles%, %ProgramW6432%, %LOCALAPPDATA%\Programs), MSYS2's (%SystemDrive%\msys64\usr\bin) and Cygwin's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # (%SystemDrive%\cygwin64\bin) that has cat.exe; elsewhere none. Also on Windows, a program of the system's own (under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # %SystemRoot%) named sort, find, timeout or expand is never taken for the POSIX one: they differ. @BIN at run time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | our @BIN = !defined $ENV{PROC_SHELLSPAWN_BIN} ? ($WIN ? win_posix_bin() : ()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 481 | ▶ | : $ENV{PROC_SHELLSPAWN_BIN} eq 'none' ? () : Proc::Spawner::path_split($ENV{PROC_SHELLSPAWN_BIN}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub win_posix_bin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
win_posix_bin: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $sd = $ENV{SystemDrive} // 'C:'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"SystemDrive"} // "C:"
MC/DC0%0/1
$ENV{"SystemDrive"} // "C:"
$ENV{"SystemDrive"}
Truth table0%0/2
A
A= $ENV{"SystemDrive"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my $up = sub { $_[0] =~ s{[/\\][^/\\]+\z}{}r }; # the parent directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my @git = map { ($up->($_), $up->($up->($_))) } grep -f "$_\\git.exe", Proc::Spawner::path_split($ENV{PATH}); # Git\cmd, Git\mingw64\bin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | for my $d ((map "$_\\usr\\bin", @git), (map "$_\\Git\\usr\\bin", grep defined, @ENV{qw(ProgramFiles ProgramW6432)}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | (defined $ENV{LOCALAPPDATA} ? "$ENV{LOCALAPPDATA}\\Programs\\Git\\usr\\bin" : ()), "$sd\\msys64\\usr\\bin", "$sd\\cygwin64\\bin") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return $d if -f "$d\\cat.exe" } () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 480 | my %WINCLASH = map +($_ => 1), qw(sort find timeout expand); # Windows' own programs of these names are others (BIN1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | ▶ | sub win_clash { my ($name, $p) = @_; my $r = $ENV{SystemRoot} // return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
win_clash: called CC=3 SCAR=15.4
Pod
undocumented
Condition0%0/2
$ENV{"SystemRoot"} // (return 0)
MC/DC0%0/1
$ENV{"SystemRoot"} // (return 0)
$ENV{"SystemRoot"}
Truth table0%0/2
A
A= $ENV{"SystemRoot"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | $WINCLASH{lc $name} && lc(substr($p, 0, length $r) =~ tr{/}{\\}r) eq lc($r =~ tr{/}{\\}r) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 297 | ▶ | sub find_cmd { # the path to run for $name, or undef and the status (127, 126); Windows: PATHEXT's extensions first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_cmd: called CC=18 SCAR=35.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 294 | my ($c, $name, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 294 | ▶ | my @ext = ($WIN ? (grep length, split /;/, $c->{sh}{vars}{PATHEXT} // '.COM;.EXE;.BAT;.CMD') : (), ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$c->{"sh"}{"vars"}{"PATHEXT"} // ".COM;.EXE;.BAT;.CMD"
MC/DC0%0/1
$c->{"sh"}{"vars"}{"PATHEXT"} // ".COM;.EXE;.BAT;.CMD"
$c->{"sh"}{"vars"}{"PATHEXT"}
Truth table0%0/2
A
A= $c->{"sh"}{"vars"}{"PATHEXT"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 296 | ▶ | if (has_dir($name)) { -f path_in($c, "$name$_") and return "$name$_" for @ext; return $name } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 280 | my $denied; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 280 | for my $d (@BIN, path_list($path)) { for my $e (@ext) { # (@BIN: BIN1, a temporary workaround) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 2138 | ▶ | my $p = ($d eq '' ? '.' : $d) . ($WIN && $d =~ /\\/ && $d !~ m{/} ? '\\' : '/') . "$name$e"; # (Windows: as PATH writes it) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$Proc::ShellSpawn::WIN and $d =~ /\\/ and not $d =~ m[/]
$Proc::ShellSpawn::WIN and $d =~ /\\/
MC/DC0%0/3
$Proc::ShellSpawn::WIN and $d =~ /\\/ and not $d =~ m[/]
$Proc::ShellSpawn::WIN
$d =~ /\\/
not $d =~ m[/]
Truth table25%1/4
A and B and not(C)
A= $Proc::ShellSpawn::WINB= $d =~ /\\/C= not $d =~ m[/]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2136 | ▶ | next unless -f path_in($c, $p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 252 | ▶ | next if $WIN && win_clash($name, $p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Proc::ShellSpawn::WIN and win_clash($name, $p)
MC/DC0%0/2
$Proc::ShellSpawn::WIN and win_clash($name, $p)
$Proc::ShellSpawn::WIN
win_clash($name, $p)
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= win_clash($name, $p)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 255 | ▶ | return $p if -x _; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 3 | ▶ | $denied //= $p } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$denied //= $p
MC/DC0%0/2
$denied //= $p
$denied
$p
Truth table0%0/3
A //= B
A= $deniedB= $p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 15 | ▶ | defined $denied ? (undef, 126, $denied) : (undef, 127) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 897 | ▶ | sub spawn { # starts @$argv with $map; $k->(STATUS) when it has ended; returns its process node or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=34 SCAR=40.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 900 | my ($c, $map, $argv, $env, $k, $search) = @_; # $search: the PATH to look in, if not the command's own (command -p) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 900 | ▶ | my %e = (%{$c->{sh}{vars}}{grep $c->{sh}{exp}{$_} && /^[A-Za-z_][A-Za-z_0-9]*\z/, keys %{$c->{sh}{vars}}}, %$env); # as dash: names only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$c->{'sh'}{'exp'}{$_} && /^[A-Za-z_][A-Za-z_0-9]*\z/
MC/DC50%1/2
$c->{'sh'}{'exp'}{$_} && /^[A-Za-z_][A-Za-z_0-9]*\z/
$c->{'sh'}{'exp'}{$_}
/^[A-Za-z_][A-Za-z_0-9]*\z/
Truth table66%2/3
A && B
A= $c->{'sh'}{'exp'}{$_}B= /^[A-Za-z_][A-Za-z_0-9]*\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 897 | ▶ | return inproc($c, $map, $argv, \%e, $k) if $INPROC{$argv->[0]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 280 | ▶ | if (my $a = sh_argv($c, $argv, $search // $e{PATH})) { $argv = $a; undef $search } # sh as Perl (SH1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$search // $e{"PATH"}
MC/DC0%0/2
$search // $e{"PATH"}
$search
$e{"PATH"}
Truth table33%1/3
A // B
A= $searchB= $e{"PATH"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 278 | ▶ | my ($path, $st, $what) = find_cmd($c, $argv->[0], $search // $e{PATH}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$search // $e{"PATH"}
MC/DC0%0/2
$search // $e{"PATH"}
$search
$e{"PATH"}
Truth table33%1/3
A // B
A= $searchB= $e{"PATH"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 278 | ▶ | $c->{sh}{hash}{$argv->[0]} = $path if defined $path && !defined $search && !has_dir($argv->[0]); # remembered, as dash (hash, type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $path and not defined $search and not has_dir($argv->[0])
defined $path and not defined $search
MC/DC66%2/3
defined $path and not defined $search and not has_dir($argv->[0])
defined $path
not defined $search
not has_dir($argv->[0])
Truth table75%3/4
A and not(B) and not(C)
A= defined $pathB= not defined $searchC= not has_dir($argv->[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 280 | ▶ | if (!defined $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 8 | ▶ | $ONBUILTIN->($st == 127 ? 'not found' : 'denied', $argv, {%$env}) if $ONBUILTIN; # (measurement: no program runs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 8 | ▶ | return msg($c, $st == 127 ? "$argv->[0]: not found" : "$argv->[0]: Permission denied", sub { $k->($st) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 272 | ▶ | if ($WIN && -e path_in($c, $path) && (-d _ || !-x _)) { # Windows runs neither: as sh says it (CreateProcess: not found, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition22%2/9
$Proc::ShellSpawn::WIN and -e path_in($c, $path) and -d _ || !-x(_)
$Proc::ShellSpawn::WIN and -e path_in($c, $path)
-d _ or not -x _
MC/DC0%0/4
$Proc::ShellSpawn::WIN and -e path_in($c, $path) and -d _ || !-x(_)
$Proc::ShellSpawn::WIN
-e path_in($c, $path)
-d _
not -x _
Truth table20%1/5
A and B and C or not(D)
A= $Proc::ShellSpawn::WINB= -e path_in($c, $path)C= -d _D= not -x _
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | ▶ | $ONBUILTIN->('denied', $argv, {%$env}) if $ONBUILTIN; # or "Exec format error") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | ▶ | return msg($c, "$argv->[0]: Permission denied", sub { $k->(126) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 272 | my @envp = map "$_=$e{$_}", sort keys %e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 272 | ▶ | my %def = map +($_ => 1), grep !$IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{sh}{trap}{$_} // 1) ne '', # trap '' SIG: stays ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition70%7/10
!$IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{'sh'}{'trap'}{$_} // 1) ne ''
not $IGN0{$_} and ($SIG{$_} // "") eq "IGNORE"
$SIG{$_} // ""
$c->{"sh"}{"trap"}{$_} // 1
MC/DC0%0/3
!$IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{'sh'}{'trap'}{$_} // 1) ne ''
not $IGN0{$_}
$SIG{$_}
$c->{"sh"}{"trap"}{$_}
Truth table50%2/4
not(A) and B && C
A= not $IGN0{$_}B= $SIG{$_}C= $c->{"sh"}{"trap"}{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | keys %SIG, $FPE ? () : 'FPE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 272 | ▶ | delete @def{qw(INT QUIT)} if $c->{sh}{job}; # in the background: left ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | my @o = (sigdefault => [sort keys %def], $WIN ? () : (umask => $c->{sh}{umask}), on_exit => ['Proc::ShellSpawn::resume', $k], # (Windows: no umask) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 270 | ▶ | $c->{sh}{cwd} ne Cwd::getcwd() ? (chdir => $c->{sh}{cwd}) : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 272 | my $node = $G->start($path, $argv, \@envp, $map, @o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 270 | ▶ | if (!$node && !$WIN && $! == POSIX::ENOEXEC()) { # a script without #!: sh runs it with sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $node || $Proc::ShellSpawn::WIN and $! == 8
$node || $Proc::ShellSpawn::WIN
MC/DC0%0/3
not $node || $Proc::ShellSpawn::WIN and $! == 8
$node
$Proc::ShellSpawn::WIN
$! == 8
Truth table50%2/4
not(A || B) and C
A= $nodeB= $Proc::ShellSpawn::WINC= $! == 8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $node = $G->start('/bin/sh', ['sh', $path, @$argv[1 .. $#$argv]], \@envp, $map, @o) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 270 | ▶ | return $node if $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 4 | my $err = "$!"; # an fd of ours that is not open: the first one the child should have got | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | ▶ | my ($bad) = grep !is_open($_), map $map->{$_} ? $map->{$_}{fd} : (), sort { $a <=> $b } keys %$map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | $st = $! == POSIX::ENOENT() ? 127 : 126; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | ▶ | msg($c, defined $bad ? "$bad: Bad file descriptor" : $st == 127 ? "$argv->[0]: not found" : "$argv->[0]: $err", sub { $k->($st) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 619 | ▶ | sub inproc { # a program of %INPROC, run here: its output and messages in the program's order, then $k->(STATUS). A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inproc: called CC=7 SCAR=20.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # write error on stdout, as coreutils: death by SIGPIPE (EPIPE, unless the shell ignores SIGPIPE for its children), else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # no more output, the message "NAME: write error: ..." at the end and status 1. Undef, as spawn for no process started. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 620 | my ($c, $map, $argv, $env, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 620 | require Proc::ShellSpawn::Programs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 620 | my $d = { %$c, map => $map }; hold($_) for values %$map; # (the caller releases its holds when spawn returns) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 620 | ▶ | $ONBUILTIN->('Proc::ShellSpawn::inproc', $argv, {%$env}) if $ONBUILTIN; # (measurement: no program runs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 620 | tr_("in-process: @$argv"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 620 | ▶ | my %opt = (cwd => $c->{sh}{cwd}, echo => $ECHO, isatty => sub { my $e = $map->{$_[0]}; $e && POSIX::isatty($e->{fd}) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 620 | ▶ | my ($out, $err, $st, $seq) = Proc::ShellSpawn::Programs->can($argv->[0] eq '[' ? 'test' : $argv->[0])->($argv, $env, \%opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 620 | ▶ | my @seq = grep length $_->[1], @{$seq // [[2, $err], [1, $out]]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$seq // [[2, $err], [1, $out]]
MC/DC100%1/1
$seq // [[2, $err], [1, $out]]
$seq
Truth table100%2/2
A
A= $seq
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 620 | ▶ | my $pipe_dfl = !$IGN0{PIPE} && ($c->{sh}{trap}{PIPE} // 1) ne ''; # (Windows: as POSIX, though it has no SIGPIPE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
!$IGN0{'PIPE'} && ($c->{'sh'}{'trap'}{'PIPE'} // 1) ne ''
$c->{"sh"}{"trap"}{"PIPE"} // 1
MC/DC0%0/2
!$IGN0{'PIPE'} && ($c->{'sh'}{'trap'}{'PIPE'} // 1) ne ''
!$IGN0{'PIPE'}
$c->{"sh"}{"trap"}{"PIPE"}
Truth table33%1/3
not(A) && B
A= !$IGN0{'PIPE'}B= $c->{"sh"}{"trap"}{"PIPE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 619 | my $werr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1180 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1181 | my $next = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1181 | my $p = shift @seq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1180 | ▶ | if (!$p) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 616 | ▶ | release($_) for values %$map; return $k->($st) unless $werr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | ▶ | local $! = $werr; return write_fd($d, 2, "$argv->[0]: write error" . ($werr > 0 ? ": $!" : '') . "\n", sub { $k->(1) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 565 | ▶ | return $next->() if $p->[0] == 1 && $werr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p->[0] == 1 and $werr
MC/DC0%0/2
$p->[0] == 1 and $werr
$p->[0] == 1
$werr
Truth table66%2/3
A and B
A= $p->[0] == 1B= $werr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 566 | ▶ | write_fd($d, $p->[0], $p->[1], sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 564 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 564 | ▶ | if ($e && $p->[0] == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$e and $p->[0] == 1
MC/DC50%1/2
$e and $p->[0] == 1
$e
$p->[0] == 1
Truth table66%2/3
A and B
A= $eB= $p->[0] == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | ▶ | if ($e == POSIX::EPIPE() && $pipe_dfl) { release($_) for values %$map; return $k->(128 + 13) } # (SIGPIPE: 13) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$e == 32 and $pipe_dfl
MC/DC50%1/2
$e == 32 and $pipe_dfl
$e == 32
$pipe_dfl
Truth table66%2/3
A and B
A= $e == 32B= $pipe_dfl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # the reason only when it failed in the final flush (close_stream: errno 0 after an earlier failure): the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # piece for stdout, short enough for one write of the buffer (glibc's: st_blksize, 4096 for a pipe) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | ▶ | $werr = !grep($_->[0] == 1, @seq) && length $p->[1] <= 4096 ? $e : -1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not grep(($_->[0] == 1), @seq) and length $p->[1] <= 4096
MC/DC0%0/2
not grep(($_->[0] == 1), @seq) and length $p->[1] <= 4096
not grep(($_->[0] == 1), @seq)
length $p->[1] <= 4096
Truth table33%1/3
not(A) and B
A= not grep(($_->[0] == 1), @seq)B= length $p->[1] <= 4096
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 619 | $next->() }) }->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 621 | return } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 269 | ▶ | sub resume { my ($g, $node, $w, $k) = @_; $k->(defined $w ? status_of($w) : 1) } # on_exit of our children | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resume: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # ------------------------------------------------------------------ redirections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # Applies @$redirs to a copy of $c's map: $k->(MAP, [opened ends]), or $k->() after a message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1324 | ▶ | sub redirect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redirect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1327 | my ($c, $redirs, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1327 | my %m = %{$c->{map}}; my @opened; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1324 | ▶ | my $fail = sub { msg({ map => \%m }, shift, sub { release($_) for @opened; $k->() }) }; # through the redirections so far | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1324 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1428 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1429 | ▶ | return $k->(\%m, \@opened) if $i > $#$redirs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 126 | my ($fd, $op, $w) = @{$redirs->[$i++]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 127 | ▶ | if ($op eq '<<') { # a here-document: Perl writes the expanded body into a pipe the command reads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 12 | my $next = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 12 | ▶ | return expand_str($c, $w, sub { my $body = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 12 | ▶ | my ($r, $wr) = new_pipe() or return $fail->("pipe: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 12 | ▶ | push @opened, $m{$fd} = $r; on_write($wr, $body, sub { release($wr) }); $next->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 114 | ▶ | if ($op eq '<&' or $op eq '>&') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$op eq "<&" or $op eq ">&"
MC/DC100%2/2
$op eq "<&" or $op eq ">&"
$op eq "<&"
$op eq ">&"
Truth table100%3/3
A or B
A= $op eq "<&"B= $op eq ">&"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 37 | ▶ | if ($w eq '-') { $m{$fd} = undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 30 | ▶ | elsif (exists $m{$w}) { defined $m{$w} ? ($m{$fd} = $m{$w}) : return $fail->("$w: Bad file descriptor") } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | elsif (visible($w)) { $m{$fd} = own_fd($w) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 4 | else { return $fail->("$w: Bad file descriptor") } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 34 | return __SUB__->() } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 77 | my $next = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 77 | ▶ | expand_str($c, $w, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 77 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 77 | ▶ | my $e = $name ne '' && open_end($c, $name, $op); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$name ne '' && open_end($c, $name, $op)
MC/DC100%2/2
$name ne '' && open_end($c, $name, $op)
$name ne ''
open_end($c, $name, $op)
Truth table100%3/3
A && B
A= $name ne ''B= open_end($c, $name, $op)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 78 | ▶ | if (!$e) { # dash's wording | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 483 | ▶ | my $err = $name eq '' || $!{ENOENT} ? ($op eq '<' ? 'No such file' : 'Directory nonexistent') : "$!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 2 branches
Condition100%3/3
$name eq "" or $!{"ENOENT"}
MC/DC100%2/2
$name eq "" or $!{"ENOENT"}
$name eq ""
$!{"ENOENT"}
Truth table100%3/3
A or B
A= $name eq ""B= $!{"ENOENT"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 19 | ▶ | return $fail->(($op eq '<' ? 'cannot open' : 'cannot create') . " $name: $err") } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 1324 | push @opened, $m{$fd} = $e; $next->() }) }->() } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # Runs $body->(CONTEXT, K2) with @$redirs applied, then $k->(STATUS); status 2 if they fail. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 219 | ▶ | sub with_redirs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with_redirs: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 219 | my ($c, $redirs, $tail, $k, $body) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 219 | ▶ | return $body->($c, $tail, $k) unless $redirs && @$redirs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$redirs and @$redirs
MC/DC50%1/2
$redirs and @$redirs
$redirs
@$redirs
Truth table66%2/3
A and B
A= $redirsB= @$redirs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 25 | ▶ | redirect($c, $redirs, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 25 | ▶ | my ($m, $opened) = @_ or return defer($k, 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 22 | my $d = derive($c, $m); release($_) for @$opened; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 25 | ▶ | $body->($d, [$d, @{$tail // []}], sub { release_ctx($d); $k->(@_) }) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Condition100%2/2
$tail // []
MC/DC100%1/1
$tail // []
$tail
Truth table100%2/2
A
A= $tail
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # ------------------------------------------------------------------ expansion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 574 | ▶ | sub var { # also $0-$9 ${10}..., $#, $$, $@ and $* (joined by the first character of IFS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
var: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 574 | my ($c, $n) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 574 | ▶ | return $n ? $sh->{args}[$n - 1] // '' : $sh->{arg0} // 'sh' if $n =~ /^[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition75%3/4
$sh->{"args"}[$n - 1] // ""
$sh->{"arg0"} // "sh"
MC/DC100%1/1
$sh->{"args"}[$n - 1] // ""
$sh->{"args"}[$n - 1]
MC/DC0%0/1
$sh->{"arg0"} // "sh"
$sh->{"arg0"}
Truth table100%2/2
A
A= $sh->{"args"}[$n - 1]
Truth table50%1/2
A
A= $sh->{"arg0"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 12 | ▶ | $n eq '?' ? $sh->{q} : $n eq '!' ? ($sh->{bang} // {})->{first} // '' : $n eq '#' ? scalar @{$sh->{args}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$n eq "\@" or $n eq "*"
MC/DC100%2/2
$n eq "\@" or $n eq "*"
$n eq "\@"
$n eq "*"
Truth table100%3/3
A or B
A= $n eq "\@"B= $n eq "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 549 | ▶ | : $n eq '$' ? $sh->{pid} : $n eq '@' || $n eq '*' ? join(ifs1($c), @{$sh->{args}}) : $sh->{vars}{$n} // '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
+($sh->{"bang"} // {})->{"first"} // ""
$sh->{"bang"} // {}
$sh->{"vars"}{$n} // ""
MC/DC100%1/1
+($sh->{"bang"} // {})->{"first"} // ""
$sh->{"bang"}
MC/DC100%1/1
$sh->{"vars"}{$n} // ""
$sh->{"vars"}{$n}
Truth table100%2/2
A
A= $sh->{"bang"}
Truth table100%2/2
A
A= $sh->{"vars"}{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 18 | ▶ | sub ifs1 { my $i = $_[0]{sh}{vars}{IFS}; defined $i ? substr($i, 0, 1) : ' ' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ifs1: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 53 | ▶ | sub isset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isset: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 53 | my ($c, $n) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | ▶ | $n =~ /^[1-9][0-9]*\z/ ? $n <= @{$sh->{args}} : $n =~ /^[@*]\z/ ? !!@{$sh->{args}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$n =~ /^[?#\$0]\z/ or defined $sh->{"vars"}{$n}
MC/DC50%1/2
$n =~ /^[?#\$0]\z/ or defined $sh->{"vars"}{$n}
$n =~ /^[?#\$0]\z/
defined $sh->{"vars"}{$n}
Truth table66%2/3
A or B
A= $n =~ /^[?#\$0]\z/B= defined $sh->{"vars"}{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 53 | ▶ | : $n eq '!' ? defined $sh->{bang} : $n =~ /^[?#\$0]\z/ || defined $sh->{vars}{$n} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 475 | ▶ | sub getvar { # a value for $NAME, or undef after ending the shell (set -u) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getvar: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 475 | my ($c, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 475 | ▶ | return fail($c, 2, "$n: parameter not set") if $c->{sh}{opt}{u} && $n !~ /^[@*!]\z/ && !isset($c, $n); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n)
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/
MC/DC33%1/3
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n)
$c->{"sh"}{"opt"}{"u"}
not $n =~ /^[\@*!]\z/
not isset($c, $n)
Truth table50%2/4
A and not(B) and not(C)
A= $c->{"sh"}{"opt"}{"u"}B= not $n =~ /^[\@*!]\z/C= not isset($c, $n)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 473 | var($c, $n) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 642 | ▶ | sub glob_quote { (my $s = shift) =~ s/([\\*?\[\]{}~!^-])/\\$1/g; $s } # also ! ^ -: literal inside [...] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glob_quote: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 43 | ▶ | sub slash_brackets { # for bsd_glob: a bracket expression with a '/' is none, its '[' literal (both shells); [^...] as [!...] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slash_brackets: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 36 | my $p = shift; my $o = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 36 | ▶ | while ($p =~ /\G(?:(\\.)|(\[)|(.))/gcs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 150 | ▶ | if (!defined $2) { $o .= $+; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 15 | my $s = pos $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 15 | ▶ | if ($p =~ /\G([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]/gcs) { my ($n, $b) = ($1, $2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 12 | ▶ | if ("$n$b" =~ m{/}) { $o .= '\\['; pos($p) = $s } else { $o .= ($n ? '[!' : '[') . "$b]" } } # [^...]: [!...] (rule E) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 10 | else { $o .= '['; pos($p) = $s } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 36 | $o } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # A Word into fields: $k->([FIELD, ...]). $how: 'argv' splits and globs; 'str' gives one string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # A field under construction is [TEXT, PATTERN, KEEP]: PATTERN is the text for globbing, with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # quoted characters escaped, or undef if nothing in it may glob. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 3359 | ▶ | sub expand { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 3359 | my ($c, $word, $how, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 3359 | ▶ | return $k->([$word]) unless ref $word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # a field: [TEXT, GLOB PATTERN (quoted characters escaped), KEEP even if empty, HAS ACTIVE GLOB CHARS] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 555 | my @f; my $cur = ['', '', 0, 0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 969 | ▶ | my $add = sub { # text; $pat: its glob characters are active; $split: an unquoted expansion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=21 SCAR=30.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 969 | my ($t, $pat, $split) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 969 | ▶ | my $ifs = $c->{sh}{vars}{IFS} // " \t\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$c->{"sh"}{"vars"}{"IFS"} // " \t\n"
MC/DC0%0/1
$c->{"sh"}{"vars"}{"IFS"} // " \t\n"
$c->{"sh"}{"vars"}{"IFS"}
Truth table50%1/2
A
A= $c->{"sh"}{"vars"}{"IFS"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 969 | ▶ | if ($split && $how eq 'argv' && $ifs ne '') { # split at IFS characters (L2); the pieces may glob | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$split and $how eq "argv" and $ifs ne ""
$split and $how eq "argv"
MC/DC100%3/3
$split and $how eq "argv" and $ifs ne ""
$split
$how eq "argv"
$ifs ne ""
Truth table100%4/4
A and B and C
A= $splitB= $how eq "argv"C= $ifs ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 313 | my ($ws, $nw) = map quotemeta, join('', $ifs =~ /[ \t\n]/g), join('', $ifs =~ /[^ \t\n]/g); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 313 | ▶ | my $d = $nw eq '' ? qr/[$ws]+/ : $ws eq '' ? qr/[$nw]/ : qr/[$ws]*[$nw][$ws]*|[$ws]+/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 313 | my @p = split /($d)/, $t, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 313 | for my $j (0 .. $#p) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 349 | ▶ | if ($j % 2) { # a delimiter: one with a non-blank IFS character ends a field even if it is empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 23 | ▶ | push @f, $cur if length $cur->[0] or $cur->[2] or $nw ne '' && $p[$j] =~ /[$nw]/; $cur = ['', '', 0, 0]; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
length $cur->[0] or $cur->[2] or $nw ne "" and $p[$j] =~ /[$nw]/
length $cur->[0] or $cur->[2]
$nw ne "" and $p[$j] =~ /[$nw]/
MC/DC50%2/4
length $cur->[0] or $cur->[2] or $nw ne "" and $p[$j] =~ /[$nw]/
length $cur->[0]
$cur->[2]
$nw ne ""
$p[$j] =~ /[$nw]/
Truth table60%3/5
A or B or C and D
A= length $cur->[0]B= $cur->[2]C= $nw ne ""D= $p[$j] =~ /[$nw]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 326 | ▶ | $cur->[0] .= $p[$j]; $cur->[1] .= $p[$j]; $cur->[3] ||= $p[$j] =~ /[*?\[]/ } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$cur->[3] ||= $p[$j] =~ /[*?\[]/
MC/DC100%2/2
$cur->[3] ||= $p[$j] =~ /[*?\[]/
$cur->[3]
$p[$j] =~ /[*?\[]/
Truth table100%3/3
A ||= B
A= $cur->[3]B= $p[$j] =~ /[*?\[]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 2 | ▶ | elsif ($split && $how eq 'argv') { $cur->[0] .= $t; $cur->[1] .= $t; $cur->[3] ||= $t =~ /[*?\[]/ } # IFS empty: no splitting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$split and $how eq "argv"
$cur->[3] ||= $t =~ /[*?\[]/
MC/DC100%2/2
$split and $how eq "argv"
$split
$how eq "argv"
MC/DC0%0/2
$cur->[3] ||= $t =~ /[*?\[]/
$cur->[3]
$t =~ /[*?\[]/
Truth table100%3/3
A and B
A= $splitB= $how eq "argv"
Truth table33%1/3
A ||= B
A= $cur->[3]B= $t =~ /[*?\[]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 654 | ▶ | else { $cur->[0] .= $t; $cur->[1] .= $pat ? $t : glob_quote($t); $cur->[3] ||= $pat && $t =~ /[*?\[]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$cur->[3] ||= $pat && $t =~ /[*?\[]/
$pat && $t =~ /[*?\[]/
MC/DC0%0/3
$cur->[3] ||= $pat && $t =~ /[*?\[]/
$cur->[3]
$pat
$t =~ /[*?\[]/
Truth table0%0/4
A ||= B && C
A= $cur->[3]B= $patC= $t =~ /[*?\[]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 555 | ▶ | $cur->[2] = 1 unless $pat } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 555 | my @parts = @$word; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1513 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=54 SCAR=41.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1513 | ▶ | if ($i > $#parts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 538 | ▶ | push @f, $cur if length $cur->[0] or $cur->[2] && !$cur->[4] or $how ne 'argv'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
length $cur->[0] or $cur->[2] and not $cur->[4] or $how ne "argv"
length $cur->[0] or $cur->[2] and not $cur->[4]
$cur->[2] and not $cur->[4]
MC/DC75%3/4
length $cur->[0] or $cur->[2] and not $cur->[4] or $how ne "argv"
length $cur->[0]
$cur->[2]
not $cur->[4]
$how ne "argv"
Truth table66%4/6
A or B and not(C) or D
A= length $cur->[0]B= $cur->[2]C= not $cur->[4]D= $how ne "argv"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 538 | ▶ | return $k->([map $_->[0], @f]) if $how ne 'argv'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | return $k->([map { # a pattern that matches nothing stays as it is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 501 | my ($t, $p, undef, $g) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 524 | ▶ | my $base = !$g || is_abs($p) || $c->{sh}{cwd} eq Cwd::getcwd() ? '' : glob_quote($c->{sh}{cwd}) . '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $g or is_abs($p) or $c->{"sh"}{"cwd"} eq Cwd::getcwd()
not $g or is_abs($p)
MC/DC100%3/3
not $g or is_abs($p) or $c->{"sh"}{"cwd"} eq Cwd::getcwd()
not $g
is_abs($p)
$c->{"sh"}{"cwd"} eq Cwd::getcwd()
Truth table100%4/4
not(A) or B or C
A= not $gB= is_abs($p)C= $c->{"sh"}{"cwd"} eq Cwd::getcwd()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 524 | ▶ | my @m = $g && !$c->{sh}{opt}{f} ? sort { $a cmp $b } grep !m{(?:^|/)\.\.?\z}, File::Glob::bsd_glob($base . slash_brackets($p), File::Glob::GLOB_QUOTE()) : (); # never . or .. (rule E, as bash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$g and not $c->{"sh"}{"opt"}{"f"}
MC/DC100%2/2
$g and not $c->{"sh"}{"opt"}{"f"}
$g
not $c->{"sh"}{"opt"}{"f"}
Truth table100%3/3
A and not(B)
A= $gB= not $c->{"sh"}{"opt"}{"f"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 524 | ▶ | s{^\Q$c->{sh}{cwd}\E/}{} for $base ? @m : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 524 | ▶ | @m ? @m : $t } @f]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 975 | my $x = $parts[$i++]; my $next = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 975 | ▶ | return $add->($x, 0), $next->() unless ref $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 629 | my ($kind, @a) = @$x; (my $q = $kind) =~ s/^"//; my $split = $kind !~ /^"/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 629 | ▶ | if ($kind eq '*') { $add->($a[0], 1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | elsif ($kind eq '~') { $add->($a[0] ne '' ? ($WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]" # ~ without HOME: from the password | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | : exists $c->{sh}{vars}{HOME} ? var($c, 'HOME') # file (G16); Windows: no user database, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 5 | ▶ | : ($WIN ? $ENV{USERPROFILE} : (getpwuid $<)[7]) // '~', 0) } # USERPROFILE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition75%3/4
($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]"
($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7]) // "~"
MC/DC100%1/1
($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]"
($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7])
MC/DC0%0/1
($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7]) // "~"
($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7])
Truth table100%2/2
A
A= ($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7])
Truth table50%1/2
A
A= ($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | ▶ | elsif ($kind eq '"$' && $a[0] eq '@' && $how eq 'argv') { # "$@": one field per parameter | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$kind eq "\"\$" and $a[0] eq "\@" and $how eq "argv"
$kind eq "\"\$" and $a[0] eq "\@"
MC/DC66%2/3
$kind eq "\"\$" and $a[0] eq "\@" and $how eq "argv"
$kind eq "\"\$"
$a[0] eq "\@"
$how eq "argv"
Truth table75%3/4
A and B and C
A= $kind eq "\"\$"B= $a[0] eq "\@"C= $how eq "argv"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 12 | ▶ | my @p = @{$c->{sh}{args}}; $cur->[4] = 1 unless @p; # none: the field goes, quotes or not (L1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 12 | ▶ | for my $j (0 .. $#p) { if ($j) { push @f, $cur; $cur = ['', '', 0, 0] } $add->($p[$j], 0) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 434 | ▶ | elsif ($q eq '$') { my $v = getvar($c, $a[0]) // return; $add->($v, 0, $split) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
getvar($c, $a[0]) // (return)
MC/DC100%1/1
getvar($c, $a[0]) // (return)
getvar($c, $a[0])
Truth table100%2/2
A
A= getvar($c, $a[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 12 | ▶ | elsif ($q eq '${#') { my $v = getvar($c, $a[0]) // return; $add->(length $v, 0, $split) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
getvar($c, $a[0]) // (return)
MC/DC0%0/1
getvar($c, $a[0]) // (return)
getvar($c, $a[0])
Truth table50%1/2
A
A= getvar($c, $a[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | elsif ($q eq '${') { # the word is expanded only if it is used, as in sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 51 | my ($n, $op, $w) = @a; my $v = var($c, $n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 51 | ▶ | my $set = isset($c, $n) && ($op !~ /:/ || $v ne ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
isset($c, $n) && (!($op =~ /:/) || $v ne '')
not $op =~ /:/ or $v ne ""
MC/DC100%3/3
isset($c, $n) && (!($op =~ /:/) || $v ne '')
isset($c, $n)
not $op =~ /:/
$v ne ""
Truth table100%4/4
A && not(B) or C
A= isset($c, $n)B= not $op =~ /:/C= $v ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 51 | ▶ | if ($op =~ /^[%#]/) { # remove the smallest or largest matching suffix or prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 21 | ▶ | getvar($c, $n) // return; # set -u (L4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
getvar($c, $n) // (return)
MC/DC100%1/1
getvar($c, $n) // (return)
getvar($c, $n)
Truth table100%2/2
A
A= getvar($c, $n)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 20 | ▶ | return pattern_re($c, $w, sub { my $re = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 27 | ▶ | my $trim = sub { my $v = shift; my @i = 0 .. length $v; @i = reverse @i if $op =~ /^(?:%|##)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 27 | ▶ | for my $i (@i) { my ($cut, $keep) = $op =~ /%/ ? (substr($v, $i), substr($v, 0, $i)) : (substr($v, 0, $i), substr($v, $i)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 87 | ▶ | return $keep if $cut =~ $re } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 20 | $v }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 20 | ▶ | if ($n eq '@' || $n eq '*') { # G4 (rule E, as bash): from each parameter, then as $@ or $* would be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n eq "\@" or $n eq "*"
MC/DC100%2/2
$n eq "\@" or $n eq "*"
$n eq "\@"
$n eq "*"
Truth table100%3/3
A or B
A= $n eq "\@"B= $n eq "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 4 | my @t = map $trim->($_), @{$c->{sh}{args}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 4 | ▶ | if ($kind eq '"${' && $n eq '@' && $how eq 'argv') { # "${@#p}": one field per parameter, as "$@" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$kind eq "\"\${" and $n eq "\@" and $how eq "argv"
$kind eq "\"\${" and $n eq "\@"
MC/DC66%2/3
$kind eq "\"\${" and $n eq "\@" and $how eq "argv"
$kind eq "\"\${"
$n eq "\@"
$how eq "argv"
Truth table75%3/4
A and B and C
A= $kind eq "\"\${"B= $n eq "\@"C= $how eq "argv"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | ▶ | $cur->[4] = 1 unless @t; for my $j (0 .. $#t) { if ($j) { push @f, $cur; $cur = ['', '', 0, 0] } $add->($t[$j], 0) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | else { $add->(join(ifs1($c), @t), 0, $split) } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 16 | else { $add->($trim->($v), 0, $split) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 20 | $next->() }) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 30 | ▶ | my $word = $op =~ /[-=?]/ ? !$set : $set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 30 | ▶ | unless ($word) { $add->($op =~ /[-=?]/ ? $v : '', 0, $split); return $next->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 18 | ▶ | return expand($c, $w, 'str', sub { my $t = $_[0][0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 18 | ▶ | return fail($c, 2, "$n: " . ($t ne '' ? $t : $op =~ /:/ ? 'parameter not set or null' : 'parameter not set')) if $op =~ /\?/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 13 | ▶ | if ($op =~ /=/) { setvar($c, $n, $t) or return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 26 | ▶ | $add->($t, 0, $split); $next->() }) if !$split || $op =~ /[=?]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $split or $op =~ /[=?]/
MC/DC100%2/2
not $split or $op =~ /[=?]/
not $split
$op =~ /[=?]/
Truth table100%3/3
not(A) or B
A= not $splitB= $op =~ /[=?]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 8 | ▶ | return each_async(ref $w ? $w : [$w], sub { my ($p, $more) = @_; # unquoted: strings are split, ["'", text] is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 8 | ▶ | return $add->($p, 0, 1), $more->() unless ref $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 2 | ▶ | return $add->($p->[1], 0), $more->() if $p->[0] eq "'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | expand($c, [$p], 'str', sub { $add->($_[0][0], 0, $p->[0] !~ /^"/); $more->() }) }, $next) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | elsif ($kind eq "'") { $add->($a[0], 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | elsif ($kind eq 'ext') { return handler($a[0])->($c, $x, sub { $add->(shift, 0, $split); $next->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | ▶ | elsif ($q eq '$((' && ref $a[0]) { # with $( ), `...` or ${#NAME} inside (parser item P2): those first, then the text | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$q eq "\$((" and ref $a[0]
MC/DC0%0/2
$q eq "\$((" and ref $a[0]
$q eq "\$(("
ref $a[0]
Truth table66%2/3
A and B
A= $q eq "\$(("B= ref $a[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return expand_str($c, $a[0], sub { my $v = arith($c, shift); return unless defined $v; $add->($v, 0, $split); $next->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 39 | ▶ | elsif ($q eq '$((') { my $v = arith($c, $a[0]); return unless defined $v; $add->($v, 0, $split) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 33 | ▶ | elsif ($q eq '$(') { return subst($c, $a[0], sub { $add->(shift, 0, $split); $next->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | elsif ($kind eq '{' || $kind eq '{..') { die "Proc::ShellSpawn: brace expansion is not implemented" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$kind eq "{" or $kind eq "{.."
MC/DC0%0/2
$kind eq "{" or $kind eq "{.."
$kind eq "{"
$kind eq "{.."
Truth table0%0/3
A or B
A= $kind eq "{"B= $kind eq "{.."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | else { die "Proc::ShellSpawn: unknown part '$kind'" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 555 | $next->() }->() } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 15 | ▶ | sub each_async { # $body->(ITEM, NEXT) for each item in turn (each may finish later), then $done->() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
each_async: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 15 | my ($items, $body, $done) = @_; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 15 | ▶ | sub { my $next = __SUB__; return $done->() if $i > $#$items; $body->($items->[$i++], $next) }->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 235 | ▶ | sub expand_str { my ($c, $w, $k) = @_; expand($c, $w, 'str', sub { $k->($_[0][0]) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
expand_str: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1334 | ▶ | sub expand_list { # several words, one after another (each may see the effect of the one before) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 1334 | my ($c, $ws, $how, $k) = @_; my @out; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1345 | ▶ | sub { my $next = __SUB__; # a loop while words expand at once (no deep recursion); a $( ) resumes it later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1345 | ▶ | while ($i <= $#$ws) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 3064 | my ($now, $done) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 3061 | ▶ | expand($c, $ws->[$i++], $how, sub { push @out, @{$_[0]}; $now ? $done = 1 : $next->() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 3064 | ▶ | $now = 0; $done or return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1337 | $k->(\@out) }->() } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 33 | ▶ | sub subst { # $( list ): $k->(OUTPUT without trailing newlines) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subst: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 33 | my ($c, $list, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | my ($r, $w) = new_pipe() or return msg($c, "pipe: $!", sub { $k->('') }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 33 | my ($out, $st, $eof) = (''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 33 | ▶ | my $done = sub { return unless $eof && defined $st; $c->{sh}{qsub} = $st; $k->($out =~ tr/\0//dr =~ s/\n+\z//r) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%3/3
$eof and defined $st
MC/DC100%2/2
$eof and defined $st
$eof
defined $st
Truth table100%3/3
A and B
A= $eofB= defined $st
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 33 | ▶ | my $d = derive($c, { %{$c->{map}}, 1 => $w }, jobs => 1, shell => sub { $st = shift; $done->() }); release($w); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1033 | ▶ | on_read($r, 65536, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1033 | ▶ | return $eof = 1, release($r), $done->() unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 33 | $out .= $_[0]; on_read($r, 65536, __SUB__) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 33 | x_list($d, $list, [$d], $d->{shell}{exit}) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | # $(( )): sh's integer arithmetic. undef (after a message, and leaving the shell) on error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 39 | ▶ | sub arith { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arith: called CC=8 SCAR=21.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 39 | my ($c, $e) = @_; my $src = $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 39 | ▶ | my $unset; $e =~ s/\$\{?([A-Za-z_][A-Za-z_0-9]*|[0-9]+|[?!#\$])\}?/getvar($c, $1) \/\/ ($unset = '0')/ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
getvar($c, $1) // ($unset = 0)
MC/DC0%0/1
getvar($c, $1) // ($unset = 0)
getvar($c, $1)
Truth table50%1/2
A
A= getvar($c, $1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 39 | ▶ | return if $unset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 39 | my @t = $e =~ /\G\s*(0[xX][0-9a-fA-F]+|[0-9]+|[A-Za-z_][A-Za-z_0-9]*|<<=|>>=|<<|>>|<=|>=|==|!=|&&|\|\||[-+*\/%&^|]=|[-+*\/%<>&^|!~?:()=])/gc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 39 | ▶ | my $err = sub { fail($c, 2, "arithmetic expression: $_[0]: \"$src\""); undef }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 39 | ▶ | return $err->('syntax error') if $e !~ /\G\s*\z/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 39 | my $p = 0; my $bad; local our $skip = 0; # $skip: inside the side of && || ?: that is not taken | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 483 | ▶ | use integer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 39 | my %bin = ('*' => 9, '/' => 9, '%' => 9, '+' => 8, '-' => 8, '<<' => 7, '>>' => 7, '<' => 6, '<=' => 6, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | '>' => 6, '>=' => 6, '==' => 5, '!=' => 5, '&' => 4, '^' => 3, '|' => 2, '&&' => 1, '||' => 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 39 | my ($expr, $unary); # weak (below): the two parsers call each other, and strong references would form a cycle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 88 | ▶ | my $unary_s = $unary = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=22 SCAR=37.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 88 | ▶ | my $x = $t[$p++] // return +($bad //= 'syntax error') && 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$t[$p++] // (return ($bad //= "syntax error") && 0)
($bad //= 'syntax error') && 0
$bad //= "syntax error"
MC/DC100%1/1
$t[$p++] // (return ($bad //= "syntax error") && 0)
$t[$p++]
MC/DC0%0/1
($bad //= 'syntax error') && 0
($bad //= 'syntax error')
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table100%2/2
A
A= $t[$p++]
Truth table50%1/2
A
A= ($bad //= 'syntax error')
Truth table50%1/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 87 | ▶ | return -$unary->() if $x eq '-'; return +$unary->() if $x eq '+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 82 | ▶ | return !$unary->() ? 1 : 0 if $x eq '!'; return ~$unary->() if $x eq '~'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 82 | ▶ | if ($x eq '(') { my $v = $expr->(0); ($t[$p++] // '') eq ')' or $bad //= 'syntax error'; return $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition25%1/4
$t[$p++] // ""
$bad //= "syntax error"
MC/DC0%0/1
$t[$p++] // ""
$t[$p++]
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table50%1/2
A
A= $t[$p++]
Truth table0%0/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 483 | ▶ | return do { no warnings 'portable'; $x =~ /^0[xX]/ ? hex $x : $x =~ /^0/ ? oct $x : $x } if $x =~ /^[0-9]/; # 64-bit, as dash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 8 | ▶ | if ($x =~ /^[A-Za-z_]/) { my $v = var($c, $x); $v = 0 if $v =~ /^\s*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 8 | ▶ | $v =~ /^\s*[-+]?[0-9]+\s*\z/ or $skip or $bad //= "$x: not a number"; return $v + 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$v =~ /^\s*[-+]?[0-9]+\s*\z/ or $Proc::ShellSpawn::skip
$bad //= "${x}: not a number"
MC/DC0%0/2
$v =~ /^\s*[-+]?[0-9]+\s*\z/ or $Proc::ShellSpawn::skip
$v =~ /^\s*[-+]?[0-9]+\s*\z/
$Proc::ShellSpawn::skip
MC/DC0%0/1
$bad //= "${x}: not a number"
$bad
Truth table33%1/3
A or B
A= $v =~ /^\s*[-+]?[0-9]+\s*\z/B= $Proc::ShellSpawn::skip
Truth table0%0/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | $bad //= 'syntax error'; 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$bad //= "syntax error"
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table0%0/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 39 | my $dead; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 91 | ▶ | my $expr_s = $expr = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=40 SCAR=39.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 88 | my $min = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 88 | ▶ | if (!$min && ($t[$p] // '') =~ /^[A-Za-z_]/ && ($t[$p + 1] // '') =~ /^(?:<<|>>|[-+*\/%&^|])?=\z/) { # NAME op= EXPR, right to left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%8/10
not $min and ($t[$p] // "") =~ /^[A-Za-z_]/ and ($t[$p + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]
not $min and ($t[$p] // "") =~ /^[A-Za-z_]/
$t[$p] // ""
$t[$p + 1] // ""
MC/DC33%1/3
not $min and ($t[$p] // "") =~ /^[A-Za-z_]/ and ($t[$p + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]
not $min
$t[$p]
$t[$p + 1]
Truth table50%2/4
not(A) and B and C
A= not $minB= $t[$p]C= $t[$p + 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 5 | my ($n, $op) = @t[$p, $p + 1]; $p += 2; my $r = $expr->(0); $op =~ s/=\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 5 | ▶ | my $o = var($c, $n); $o = 0 if $o =~ /^\s*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 5 | ▶ | ($op =~ m{^[/%]\z} && !$r) ? ($bad //= 'division by zero') : $op ne '' and $r = eval "\$o $op \$r"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition20%1/5
$op =~ m[^[/%]\z] and not $r
$bad //= "division by zero"
MC/DC0%0/2
$op =~ m[^[/%]\z] and not $r
$op =~ m[^[/%]\z]
not $r
MC/DC0%0/1
$bad //= "division by zero"
$bad
Truth table33%1/3
A and not(B)
A= $op =~ m[^[/%]\z]B= not $r
Truth table0%0/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 5 | ▶ | $skip or $dead or setvar($c, $n, $r) or $dead = 1; return $r } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$Proc::ShellSpawn::skip or $dead or setvar($c, $n, $r)
$Proc::ShellSpawn::skip or $dead
MC/DC33%1/3
$Proc::ShellSpawn::skip or $dead or setvar($c, $n, $r)
$Proc::ShellSpawn::skip
$dead
setvar($c, $n, $r)
Truth table50%2/4
A or B or C
A= $Proc::ShellSpawn::skipB= $deadC= setvar($c, $n, $r)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 83 | my $l = $unary->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 83 | ▶ | while (defined(my $op = $t[$p])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 48 | ▶ | if ($op eq '?' && $min <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$op eq "?" and $min <= 0
MC/DC50%1/2
$op eq "?" and $min <= 0
$op eq "?"
$min <= 0
Truth table66%2/3
A and B
A= $op eq "?"B= $min <= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | ▶ | $p++; my $a = do { local $skip = $skip || !$l; $expr->(0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$Proc::ShellSpawn::skip || !$l
MC/DC0%0/2
$Proc::ShellSpawn::skip || !$l
$Proc::ShellSpawn::skip
!$l
Truth table33%1/3
A || not(B)
A= $Proc::ShellSpawn::skipB= !$l
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | ▶ | ($t[$p++] // '') eq ':' or $bad //= 'syntax error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$t[$p++] // ""
$bad //= "syntax error"
MC/DC0%0/1
$t[$p++] // ""
$t[$p++]
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table50%1/2
A
A= $t[$p++]
Truth table0%0/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 1 | ▶ | my $b = do { local $skip = $skip || $l; $expr->(0) }; $l = $l ? $a : $b; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Proc::ShellSpawn::skip || $l
MC/DC0%0/2
$Proc::ShellSpawn::skip || $l
$Proc::ShellSpawn::skip
$l
Truth table33%1/3
A || B
A= $Proc::ShellSpawn::skipB= $l
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 47 | ▶ | my $pr = $bin{$op}; last unless defined $pr && $pr >= $min; $p++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $pr and $pr >= $min
MC/DC100%2/2
defined $pr and $pr >= $min
defined $pr
$pr >= $min
Truth table100%3/3
A and B
A= defined $prB= $pr >= $min
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 41 | ▶ | my $r = do { local $skip = $skip || ($op eq '&&' ? !$l : $op eq '||' ? $l : 0); $expr->($pr + 1) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$Proc::ShellSpawn::skip || ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
MC/DC100%2/2
$Proc::ShellSpawn::skip || ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
$Proc::ShellSpawn::skip
($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
Truth table100%3/3
A || B
A= $Proc::ShellSpawn::skipB= ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 41 | ▶ | if ($op eq '&&') { $l = $l && $r ? 1 : 0 } elsif ($op eq '||') { $l = $l || $r ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition66%4/6
$l and $r
$l or $r
MC/DC0%0/2
$l and $r
$l
$r
MC/DC0%0/2
$l or $r
$l
$r
Truth table66%2/3
A and B
A= $lB= $r
Truth table66%2/3
A or B
A= $lB= $r
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 11 | ▶ | elsif ($op =~ m{^[/%]\z} && !$r) { $bad //= 'division by zero' unless $skip; $l = 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$op =~ m[^[/%]\z] and not $r
$bad //= "division by zero"
MC/DC100%2/2
$op =~ m[^[/%]\z] and not $r
$op =~ m[^[/%]\z]
not $r
MC/DC0%0/1
$bad //= "division by zero"
$bad
Truth table100%3/3
A and not(B)
A= $op =~ m[^[/%]\z]B= not $r
Truth table50%1/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 29 | ▶ | else { $l = eval "\$l $op \$r" ; $l = $l ? 1 : 0 if $op =~ /^[<>=!]=?\z|^[<>]\z/ } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 39 | $l }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 483 | ▶ | no integer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 39 | weaken($expr); weaken($unary); # $expr_s and $unary_s keep them alive until arith returns | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 39 | ▶ | my $v = $expr->(0); $bad //= 'syntax error' if $p <= $#t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$bad //= "syntax error"
MC/DC0%0/1
$bad //= "syntax error"
$bad
Truth table0%0/2
A
A= $bad
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 39 | ▶ | return if $dead; # a readonly variable: the shell is already ending | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 38 | ▶ | defined $bad ? $err->($bad) : $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # ------------------------------------------------------------------ the tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # x_*($c, NODE, $tail, $k): run NODE in context $c, then $k->(STATUS). $tail: the contexts to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # release as soon as the last process NODE can start has started (undef: something may follow). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 932 | ▶ | sub after_start { release_ctx($_) for @{$_[0] // []} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
after_start: called CC=3 SCAR=11.0
Pod
undocumented
Condition100%2/2
$_[0] // []
MC/DC100%1/1
$_[0] // []
$_[0]
Truth table100%2/2
A
A= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 792 | ▶ | sub x_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 792 | my ($c, $l, $tail, $k) = @_; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 2184 | ▶ | sub { my $st = shift; my $p = $c->{sh}{pend}; my $me = __SUB__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 2180 | ▶ | return Proc::ShellSpawn::Large::run_pending($c, sub { $c->{sh}{q} = $st; $me->($st) }) if !$c->{intrap} && ($p && @$p || $c->{sh}{tbusy}); # X19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition77%7/9
not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"}
$p and @$p or $c->{"sh"}{"tbusy"}
$p and @$p
MC/DC50%2/4
not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"}
not $c->{"intrap"}
$p
@$p
$c->{"sh"}{"tbusy"}
Truth table66%4/6
not(A) and B and C or D
A= not $c->{"intrap"}B= $pC= @$pD= $c->{"sh"}{"tbusy"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 2178 | ▶ | return defer($k, $st) if $i > $#$l; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 792 | ▶ | x_andor($c, $l->[$i++], $i > $#$l ? $tail : undef, $me) }->(0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1503 | ▶ | sub x_andor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_andor: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1500 | my ($c, $ao, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 1500 | ▶ | return x_bg($c, [@$ao[0 .. $#$ao - 1]], $k) if $ao->[-1] eq '&'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 1475 | my ($i, $ran) = (0, -1); my $cc = cond($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 2935 | ▶ | sub { my $st = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 2935 | ▶ | $i += 2 while $i > 0 && $i <= $#$ao && ($ao->[$i - 1] eq '&&') != ($st == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$i > 0 and $i <= $ao->$#* and ($$ao[$i - 1] eq "&&") != ($st == 0)
$i > 0 and $i <= $ao->$#*
MC/DC100%3/3
$i > 0 and $i <= $ao->$#* and ($$ao[$i - 1] eq "&&") != ($st == 0)
$i > 0
$i <= $ao->$#*
($$ao[$i - 1] eq "&&") != ($st == 0)
Truth table100%4/4
A and B and C
A= $i > 0B= $i <= $ao->$#*C= ($$ao[$i - 1] eq "&&") != ($st == 0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 2936 | ▶ | if ($i > $#$ao) { # set -e: the last pipeline failed, not negated, not in a condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1399 | ▶ | return leave($c, $st) if $st && $c->{sh}{opt}{e} && !$c->{cond} && $ran == $#$ao && ref $ao->[-1][0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#* and ref $ao->[-1][0]
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#*
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"}
$st and $c->{"sh"}{"opt"}{"e"}
MC/DC80%4/5
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#* and ref $ao->[-1][0]
$st
$c->{"sh"}{"opt"}{"e"}
not $c->{"cond"}
$ran == $ao->$#*
ref $ao->[-1][0]
Truth table83%5/6
A and B and not(C) and D and E
A= $stB= $c->{"sh"}{"opt"}{"e"}C= not $c->{"cond"}D= $ran == $ao->$#*E= ref $ao->[-1][0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 1393 | return defer($k, $st) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1539 | my $p = $ao->[$ran = $i]; $i += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1475 | ▶ | x_pipeline($i > $#$ao ? $c : $cc, $p, $i > $#$ao ? $tail : undef, __SUB__) }->(0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1523 | ▶ | sub cond { +{ %{$_[0]}, cond => 1, held => 0 } } # a context whose commands do not trigger set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cond: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 28 | ▶ | sub x_bg { # chain & : its own shell and job, fd 0 from /dev/null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_bg: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 30 | my ($c, $ao, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 30 | ▶ | my $null = open_end($c, '/dev/null', '<') or return msg($c, "/dev/null: $!", sub { $k->(2) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 30 | my $job = { pids => [] }; $JOBS{$job} = $job; push @{$c->{sh}{jobl}}, $job; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 30 | $job->{id} = ++$c->{sh}{jobs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 30 | ▶ | my $d = derive($c, { %{$c->{map}}, 0 => $null }, shell => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 30 | tr_("background job $job->{id}: done, status $_[0]"); delete $JOBS{$job}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 30 | ▶ | $job->{st} = shift; $_->() for splice @{$job->{waiters} // []} }); # for the wait builtin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$job->{"waiters"} // []
MC/DC100%1/1
$job->{"waiters"} // []
$job->{"waiters"}
Truth table100%2/2
A
A= $job->{"waiters"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 30 | release($null); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 30 | $d->{sh}{job} = $job; # shared by the job's shells: its first process becomes $! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 30 | x_andor($d, $ao, [$d], $d->{shell}{exit}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 28 | $c->{sh}{bang} = $job; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 30 | $c->{sh}{q} = 0; defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 1540 | ▶ | sub x_pipeline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_pipeline: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 1540 | my ($c, $p, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 1540 | ▶ | my @cmd = @$p; my $neg = !ref $cmd[0] && shift @cmd; $c = cond($c) if $neg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
!ref($cmd[0]) && shift @cmd
MC/DC50%1/2
!ref($cmd[0]) && shift @cmd
!ref($cmd[0])
shift @cmd
Truth table66%2/3
not(A) && B
A= !ref($cmd[0])B= shift @cmd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 1537 | ▶ | my $kk = sub { my $st = $neg ? ($_[0] ? 0 : 1) : $_[0]; $c->{sh}{q} = $st; $k->($st) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 1537 | ▶ | return x_cmd($c, $cmd[0], $tail, $kk) if @cmd == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 96 | my (@ends, @d, @st); my $left = @cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 96 | ▶ | for (1 .. $#cmd) { push @ends, [new_pipe()]; @{$ends[-1]} or return msg($c, "pipe: $!", sub { $kk->(2) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 96 | for my $j (0 .. $#cmd) { # each element: a shell of its own, fds 0 and 1 on the pipes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 196 | my %m = %{$c->{map}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 196 | ▶ | $m{0} = $ends[$j - 1][0] if $j; $m{1} = $ends[$j][1] if $j < $#cmd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 196 | ▶ | my $done = sub { $st[$j] = shift; defer($kk, $st[-1]) unless --$left }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 196 | $d[$j] = derive($c, \%m, jobs => 1, shell => $done) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 99 | release($_) for map @$_, @ends; # the creator's holds: only the elements' remain | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 99 | x_cmd($d[$_], $cmd[$_], [$d[$_]], $d[$_]{shell}{exit}) for 0 .. $#cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 99 | after_start($tail) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 1670 | ▶ | sub x_cmd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_cmd: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1670 | my ($c, $x, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 1670 | ▶ | $c->{sh}{vars}{LINENO} = $x->{line} if $x->{line}; # G8 (rule E, as bash): the line where the command starts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 1670 | ▶ | return x_simple($c, $x, $tail, $k) if $x->{argv}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 366 | ▶ | return with_redirs($c, $x->{redir}, undef, $k, sub { x_cd($_[0], $x, $_[2]) }) if exists $x->{cd}; # cd with redirections (post4-0.03) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 319 | ▶ | return x_set($c, $x, $k) if $x->{set}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 216 | ▶ | return handler('Proc::ShellSpawn::Large::x_rest')->($c, $x, $tail, $k) if exists $x->{rest}; # P1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 214 | ▶ | if (my ($h) = $x->{ext} // map $KIND{$_}, grep exists $x->{$_}, sort keys %KIND) { return handler($h)->($c, $x, $tail, $k) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$x->{"ext"} // map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
MC/DC50%1/2
$x->{"ext"} // map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
$x->{"ext"}
map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
Truth table66%2/3
A // B
A= $x->{"ext"}B= map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 169 | ▶ | with_redirs($c, $x->{redir}, $tail, $k, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 169 | my ($c, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 169 | ▶ | if (my $l = $x->{group}) { return x_list($c, $l, $tail, $k) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 101 | ▶ | if (my $l = $x->{sub}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 37 | my $d = derive($c, { %{$c->{map}} }, shell => $k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 37 | ▶ | return x_list($d, $l, [$d, @{$tail // []}], $d->{shell}{exit}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$tail // []
MC/DC100%1/1
$tail // []
$tail
Truth table100%2/2
A
A= $tail
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 64 | ▶ | return x_if($c, $x->{if}, $tail, $k) if $x->{if}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 57 | ▶ | return x_while($c, $x, $k) if $x->{while} || $x->{until}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$x->{"while"} or $x->{"until"}
MC/DC100%2/2
$x->{"while"} or $x->{"until"}
$x->{"while"}
$x->{"until"}
Truth table100%3/3
A or B
A= $x->{"while"}B= $x->{"until"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 44 | ▶ | return x_for($c, $x, $k) if exists $x->{for}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 17 | ▶ | return x_case($c, $x, $tail, $k) if exists $x->{case}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | die "Proc::ShellSpawn: unknown command node" }) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 7 | ▶ | sub x_if { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_if: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 7 | my ($c, $arms, $tail, $k) = @_; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 11 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 11 | ▶ | return defer($k, 0) if $i > $#$arms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 8 | ▶ | return x_list($c, $arms->[$i], $tail, $k) if $i == $#$arms; # else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 8 | my $then = $arms->[$i + 1]; $i += 2; my $next = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 7 | ▶ | x_list(cond($c), $arms->[$i - 2], undef, sub { $_[0] ? $next->() : x_list($c, $then, $tail, $k) }) }->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 39 | ▶ | sub loop { # runs $iter->(CONTEXT, NEXT, END) per iteration, with break and continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 39 | my ($c, $k, $iter) = @_; my $st = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 39 | my $rec = { scope => [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 39 | my $lc = { %$c, loops => [@{$c->{loops}}, $rec] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 39 | ▶ | my $end = sub { release_all($rec->{scope}); delete @$rec{qw(brk cont)}; defer($k, @_ ? shift : $st) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 39 | ▶ | $rec->{brk} = sub { $end->(0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 106 | ▶ | sub { my $next = __SUB__; release_all($rec->{scope}); $rec->{scope} = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 39 | ▶ | $rec->{cont} = sub { $st = 0; $next->() }; $iter->($lc, sub { $st = shift; defer($next) }, $end) }->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 13 | ▶ | sub x_while { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_while: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 13 | my ($c, $x, $k) = @_; my $until = exists $x->{until}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 40 | ▶ | loop($c, $k, sub { my ($c, $next, $end) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 40 | ▶ | x_list(cond($c), $x->{while} // $x->{until}, undef, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 13 | ▶ | ($_[0] == 0) != $until ? x_list($c, $x->{do}, undef, $next) : $end->() }) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$x->{"while"} // $x->{"until"}
MC/DC0%0/2
$x->{"while"} // $x->{"until"}
$x->{"while"}
$x->{"until"}
Truth table66%2/3
A // B
A= $x->{"while"}B= $x->{"until"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 27 | ▶ | sub x_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_for: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 27 | my ($c, $x, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 26 | ▶ | expand_list($c, $x->{in} // [[['"$', '@']]], 'argv', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 26 | my @w = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 66 | ▶ | loop($c, $k, sub { my ($c, $next, $end) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 66 | ▶ | return $end->() unless @w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 27 | ▶ | setvar($c, $x->{for}, shift @w) or return; x_list($c, $x->{do}, undef, $next) }) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$x->{"in"} // [[["\"\$", "\@"]]]
MC/DC0%0/1
$x->{"in"} // [[["\"\$", "\@"]]]
$x->{"in"}
Truth table50%1/2
A
A= $x->{"in"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 17 | ▶ | sub x_case { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_case: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 17 | my ($c, $x, $tail, $k) = @_; my @in = @{$x->{in}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 16 | ▶ | expand_str($c, $x->{case}, sub { my $s = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 17 | ▶ | sub { return defer($k, 0) unless @in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 17 | my ($pats, $l) = splice @in, 0, 2; my $next = __SUB__; my @p = @$pats; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 18 | ▶ | sub { return $next->() unless @p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 17 | my $again = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 17 | ▶ | pattern_re($c, shift @p, sub { $s =~ $_[0] ? x_list($c, $l, $tail, $k) : $again->() }) }->() }->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 37 | ▶ | sub pattern_re { # a case (or ${N%p}) pattern as a regex anchored at both ends: quoted parts literal. The whole | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pattern_re: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 37 | my ($c, $w, $k) = @_; # pattern is put together first, quoted text escaped, so that a bracket expression may span Parts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 37 | ▶ | my @parts = ref $w ? @$w : ($w); my $g = ''; my $i = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 89 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | return $k->(eval { my $re = glob_re($g); qr/\A$re\z/s } // do { (my $t = $g) =~ s/\\(.)/$1/gs; qr/\A\Q$t\E\z/s }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
eval {
do {
my $re = glob_re($g);
qr/\A$re\z/s
}
} // do {
(my $t = $g) =~ s/\\(.)/$1/gs;
qr/\A\Q$t\E\z/s
}
MC/DC0%0/2
eval {
do {
my $re = glob_re($g);
qr/\A$re\z/s
}
} // do {
(my $t = $g) =~ s/\\(.)/$1/gs;
qr/\A\Q$t\E\z/s
}
eval {
do {
my $re = glob_re($g);
qr/\A$re\z/s
}
}
do {
(my $t = $g) =~ s/\\(.)/$1/gs;
qr/\A\Q$t\E\z/s
}
Truth table33%1/3
A // B
A= eval {
do {
my $re = glob_re($g);
qr/\A$re\z/s
}
}B= do {
(my $t = $g) =~ s/\\(.)/$1/gs;
qr/\A\Q$t\E\z/s
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | if $i > $#parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 52 | my $x = $parts[$i++]; my $next = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 52 | ▶ | return $g .= glob_quote($x), $next->() unless ref $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 35 | ▶ | if ($x->[0] eq '*') { $g .= $x->[1]; return $next->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 37 | ▶ | expand($c, [$x], 'str', sub { $g .= $x->[0] =~ /^"/ ? glob_quote($_[0][0]) : $_[0][0]; $next->() }) }->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 37 | ▶ | sub glob_re { # a glob pattern (quoted characters escaped with '\') as a regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glob_re: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 37 | my $g = shift; my $re = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 37 | ▶ | while ($g =~ /\G(?:(\*)|(\?)|\[([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]|\\(.)|(.))/gcs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 56 | ▶ | $re .= defined $1 ? '.*' : defined $2 ? '.' : defined $4 ? bracket_re($3, $4) : quotemeta($5 // $6) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$5 // $6
MC/DC100%2/2
$5 // $6
$5
$6
Truth table100%3/3
A // B
A= $5B= $6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 37 | $re } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 12 | ▶ | sub bracket_re { # the members of a bracket expression: classes and ranges kept, every other character literal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bracket_re: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 12 | my ($neg, $b) = @_; my $o = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 12 | ▶ | while ($b =~ /\G(?:(\[:[a-z]+:\])|\\(.)|(-)|(.))/gcs) { $o .= defined $1 ? $1 : defined $3 ? '-' : quotemeta($2 // $4) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$2 // $4
MC/DC0%0/2
$2 // $4
$2
$4
Truth table66%2/3
A // B
A= $2B= $4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 12 | ▶ | '[' . ($neg ? '^' : '') . $o . ']' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 356 | ▶ | sub setvar { # 1, or 0 after ending the shell (a readonly variable, as dash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setvar: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 356 | my ($c, $n, $v) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 356 | ▶ | return do { fail($c, 2, "$n: is read only"); 0 } if $sh->{ro}{$n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 354 | ▶ | $sh->{exp}{$n} = 1 if $sh->{opt}{a}; $sh->{vars}{$n} = $v; 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 107 | ▶ | sub x_set { # NAME=value ... alone, or with redirections (D2: as dash, redirect first; failed: no setting, status 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_set: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 107 | my ($c, $x, $k) = @_; my @s = @{$x->{set}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 6 | ▶ | return redirect($c, $x->{redir}, sub { my ($m, $opened) = @_ or return defer($k, 2); # the values are expanded with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 4 | my $d = derive($c, $m); release($_) for @$opened; # the redirections in force | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 107 | ▶ | x_set($d, { set => $x->{set} }, sub { release_ctx($d); $k->(@_) }) }) if $x->{redir}; # (rule E: category effect) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 101 | delete $c->{sh}{qsub}; my %log; # the settings as made, for $ONBUILTIN (measurement) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 202 | ▶ | sub { unless (@s) { $ONBUILTIN->('x_set', [], {%log}) if $ONBUILTIN; return defer($k, $c->{sh}{qsub} // 0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 2 branches
Condition100%2/2
$c->{"sh"}{"qsub"} // 0
MC/DC100%1/1
$c->{"sh"}{"qsub"} // 0
$c->{"sh"}{"qsub"}
Truth table100%2/2
A
A= $c->{"sh"}{"qsub"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 103 | my ($n, $w) = splice @s, 0, 2; my $next = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 101 | ▶ | expand_str($c, $w, sub { $log{$n} = $_[0]; setvar($c, $n, shift) or return; $next->() }) }->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 47 | ▶ | sub x_cd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_cd: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 47 | my ($c, $x, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 46 | ▶ | my $go = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=28 SCAR=36.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 46 | ▶ | my @f = @_; $ONBUILTIN->('x_cd', ['cd', ($x->{cd_p} ? '-P' : ()), @f], {}) if $ONBUILTIN; # (measurement) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 46 | ▶ | my $d = @f ? $f[0] : var($c, 'HOME'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 46 | ▶ | my $dash = @f == 1 && $d eq '-' and $d = var($c, 'OLDPWD'); # cd -: back, and print where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@f == 1 && $d eq '-'
MC/DC100%2/2
@f == 1 && $d eq '-'
@f == 1
$d eq '-'
Truth table100%3/3
A && B
A= @f == 1B= $d eq '-'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 46 | ▶ | return defer($k, 0) if @f == 1 && $d eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@f == 1 and $d eq ""
MC/DC0%0/2
@f == 1 and $d eq ""
@f == 1
$d eq ""
Truth table66%2/3
A and B
A= @f == 1B= $d eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 46 | ▶ | return msg($c, "cd: too many arguments", sub { $k->(1) }) if $x->{cd_extra}; # as bash (rule E) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 45 | ▶ | return msg($c, "cd: HOME not set", sub { $k->(1) }) if !@f && ($d // '') eq ''; # as bash (rule E; N4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition80%4/5
not @f and ($d // "") eq ""
$d // ""
MC/DC50%1/2
not @f and ($d // "") eq ""
not @f
$d
Truth table66%2/3
not(A) and B
A= not @fB= $d
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | if (@f > 1 or $d =~ /^-/ && !$dash) { return msg($c, "cd: bad argument", sub { $k->(2) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.3
Branch: 1 branch
Condition33%2/6
@f > 1 or $d =~ /^-/ and not $dash
$d =~ /^-/ and not $dash
MC/DC0%0/3
@f > 1 or $d =~ /^-/ and not $dash
@f > 1
$d =~ /^-/
not $dash
Truth table25%1/4
A or B and not(C)
A= @f > 1B= $d =~ /^-/C= not $dash
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 44 | my $new = path_in($c, $d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 44 | ▶ | if ($x->{cd_p}) { $new = -d $new && Cwd::realpath($new) } # cd -P: symbolic links resolved, '..' physical (P6) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-d $new && Cwd::realpath($new)
MC/DC50%1/2
-d $new && Cwd::realpath($new)
-d $new
Cwd::realpath($new)
Truth table66%2/3
A && B
A= -d $newB= Cwd::realpath($new)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | else { # (Windows: the drive or the //server/share stays in front) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 41 | ▶ | my ($pre, $rest) = $WIN && $new =~ m{^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*)}s ? ($1 =~ tr{\\}{/}r, $2) : ('', $new); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Proc::ShellSpawn::WIN and $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
MC/DC0%0/2
$Proc::ShellSpawn::WIN and $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
$Proc::ShellSpawn::WIN
$new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 41 | ▶ | my @p; for (split $SEP, $rest) { next if $_ eq '' or $_ eq '.'; $_ eq '..' ? pop @p : push @p, $_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$_ eq "" or $_ eq "."
MC/DC50%1/2
$_ eq "" or $_ eq "."
$_ eq ""
$_ eq "."
Truth table66%2/3
A or B
A= $_ eq ""B= $_ eq "."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 41 | $new = $pre . '/' . join '/', @p } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 44 | ▶ | $new && -d $new or return msg($c, "cd: can't cd to $d", sub { $k->(2) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition100%3/3
$new and -d $new
MC/DC100%2/2
$new and -d $new
$new
-d $new
Truth table100%3/3
A and B
A= $newB= -d $new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 38 | ▶ | setvar($c, OLDPWD => $c->{sh}{cwd}) && setvar($c, PWD => $new) or return; $c->{sh}{cwd} = $new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) and setvar($c, "PWD", $new)
MC/DC0%0/2
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) and setvar($c, "PWD", $new)
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"})
setvar($c, "PWD", $new)
Truth table33%1/3
A and B
A= setvar($c, "OLDPWD", $c->{"sh"}{"cwd"})B= setvar($c, "PWD", $new)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 47 | ▶ | $dash ? put($c, 1, "$new\n", sub { $k->(0) }) : defer($k, 0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 47 | ▶ | defined $x->{cd} ? expand($c, $x->{cd}, 'argv', sub { $go->(@{$_[0]}) }) : $go->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 1304 | ▶ | sub x_simple { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_simple: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 1307 | my ($c, $x, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 1307 | ▶ | $k = sub { leave($c, shift) } if $x->{exec}; # exec cmd: then the shell ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 1307 | ▶ | my @env = @{$x->{env} // []}; my %env; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$x->{"env"} // []
MC/DC100%1/1
$x->{"env"} // []
$x->{"env"}
Truth table100%2/2
A
A= $x->{"env"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 1304 | delete $c->{sh}{qsub}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 1307 | ▶ | my $settings = sub { # NAME=value before the command, left to right, each seeing the ones before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 1304 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 1323 | ▶ | sub { return $next->() unless @env; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 19 | my ($n, $w) = splice @env, 0, 2; my $again = __SUB__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 19 | my $v = { %$c, sh => { %{$c->{sh}}, vars => { %{$c->{sh}{vars}}, %env } } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 1307 | ▶ | expand_str($v, $w, sub { $env{$n} = shift; $c->{sh}{qsub} = $v->{sh}{qsub} if exists $v->{sh}{qsub}; $again->() }) }->() }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 1307 | ▶ | $settings->(sub { expand_list($c, $x->{argv}, 'argv', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 1294 | my @argv = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 10 | ▶ | return redirect($c, $x->{redir} // [], sub { # every word expanded to nothing: the redirections are still done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 1291 | ▶ | my ($m, $opened) = @_ or return defer($k, 2); release($_) for @$opened; defer($k, $c->{sh}{qsub} // 0) }) unless @argv; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition75%3/4
$x->{"redir"} // []
$c->{"sh"}{"qsub"} // 0
MC/DC0%0/1
$x->{"redir"} // []
$x->{"redir"}
MC/DC100%1/1
$c->{"sh"}{"qsub"} // 0
$c->{"sh"}{"qsub"}
Truth table50%1/2
A
A= $x->{"redir"}
Truth table100%2/2
A
A= $c->{"sh"}{"qsub"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 1284 | ▶ | redirect($c, $x->{redir} // [], sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=16 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 1287 | my ($m, $opened) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1284 | ▶ | if (!$m) { return $SPECIAL{$argv[0]} ? leave($c, 2) : defer($k, 2) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 1270 | ▶ | if (my $e = $c->{sh}{cmd}{$argv[0]} // ($x->{fn} ? ['Proc::ShellSpawn::Large::b_late'] : cmd_of($argv[0]))) { # a function or a builtin, in this process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$c->{"sh"}{"cmd"}{$argv[0]} // ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
MC/DC100%2/2
$c->{"sh"}{"cmd"}{$argv[0]} // ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
$c->{"sh"}{"cmd"}{$argv[0]}
($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
Truth table100%3/3
A // B
A= $c->{"sh"}{"cmd"}{$argv[0]}B= ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 436 | my $d = derive($c, $m); release($_) for @$opened; # a context holds its fds until it is done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 436 | ▶ | $ONBUILTIN->($e->[0], \@argv, {%env}) if $ONBUILTIN; # (measurement: doc/large-subset/tools/large-subset-builtins.pl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 436 | ▶ | if ($SPECIAL{$argv[0]}) { setvar($c, $_, $env{$_}) or return for sort keys %env; %env = () } # these settings stay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 439 | ▶ | return handler($e->[0])->($d, \@argv, \%env, sub { release_ctx($d); $k->(@_) }, $e->[1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 837 | ▶ | @argv = printf_zero(@argv) if $argv[0] eq 'printf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 837 | my $node = spawn($c, $m, \@argv, \%env, $k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 834 | ▶ | $c->{sh}{job}{first} //= $node->{pid} if $node && $c->{sh}{job}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$node and $c->{"sh"}{"job"}
$c->{"sh"}{"job"}{"first"} //= $node->{"pid"}
MC/DC100%2/2
$node and $c->{"sh"}{"job"}
$node
$c->{"sh"}{"job"}
MC/DC0%0/2
$c->{"sh"}{"job"}{"first"} //= $node->{"pid"}
$c->{"sh"}{"job"}{"first"}
$node->{"pid"}
Truth table100%3/3
A and B
A= $nodeB= $c->{"sh"}{"job"}
Truth table66%2/3
A //= B
A= $c->{"sh"}{"job"}{"first"}B= $node->{"pid"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 1307 | ▶ | release($_) for @$opened; after_start($tail) }) }) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$x->{"redir"} // []
MC/DC100%1/1
$x->{"redir"} // []
$x->{"redir"}
Truth table100%2/2
A
A= $x->{"redir"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 32 | ▶ | sub printf_zero { # the 0 flag of %s, %c, %b dropped from printf's format, as both shells (glibc's printf(3) ignores it; the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
printf_zero: called CC=7 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 32 | my @a = @_; # flag is undefined for them in C and POSIX); the program printf (coreutils) refuses it (decision Z0, 2026-11-05) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 32 | ▶ | my $i = ($a[1] // '') eq '--' ? 2 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$a[1] // ""
MC/DC0%0/1
$a[1] // ""
$a[1]
Truth table50%1/2
A
A= $a[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 32 | ▶ | return @a unless defined $a[$i] && $a[$i] !~ /^-/; # printf -v ...: the program's, as decided (Q2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $a[$i] and not $a[$i] =~ /^-/
MC/DC0%0/2
defined $a[$i] and not $a[$i] =~ /^-/
defined $a[$i]
not $a[$i] =~ /^-/
Truth table33%1/3
A and not(B)
A= defined $a[$i]B= not $a[$i] =~ /^-/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 32 | $a[$i] =~ s{%(%|([-+ #0']*)(\*|[0-9]*)((?:\.(?:\*|[0-9]*))?)([a-zA-Z]))}{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 24 | my ($all, $fl, $w, $p, $cv) = ($1, $2, $3, $4, $5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 24 | ▶ | defined $cv && $cv =~ /^[scb]\z/ ? '%' . ($fl =~ tr/0//dr) . $w . $p . $cv : "%$all" }ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cv and $cv =~ /^[scb]\z/
MC/DC100%2/2
defined $cv and $cv =~ /^[scb]\z/
defined $cv
$cv =~ /^[scb]\z/
Truth table100%3/3
A and B
A= defined $cvB= $cv =~ /^[scb]\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 32 | @a } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 88 | ▶ | sub builtin { # : exit break continue read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
builtin: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 88 | my ($c, $argv, $env, $k) = @_; my $m = $c->{map}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 88 | my ($n, @a) = @$argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 88 | ▶ | return defer($k, 0) if $n eq ':'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 79 | ▶ | return leave($c, @a ? $a[0] % 256 : $c->{sh}{q}) if $n eq 'exit'; # exit 1000: 232, as both shells (parser item P4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 65 | ▶ | if ($n eq 'break' || $n eq 'continue') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n eq "break" or $n eq "continue"
MC/DC100%2/2
$n eq "break" or $n eq "continue"
$n eq "break"
$n eq "continue"
Truth table100%3/3
A or B
A= $n eq "break"B= $n eq "continue"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 16 | ▶ | my $l = $c->{loops}; my $j = @a ? $a[0] : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 16 | ▶ | return leave($c, 0) if $j > @$l; # the loop is outside this subshell: it ends the subshell, as dash (rule E, post-0.04) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 10 | release_all(map $_->{scope}, @$l[$#$l - $j + 1 .. $#$l]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 10 | ▶ | return defer($l->[-$j]{$n eq 'break' ? 'brk' : 'cont'}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 49 | ▶ | if ($n eq 'read') { return read_line($c, $m, $env, \@a, $k) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | die "Proc::ShellSpawn: builtin $n" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # read [-r] [-p PROMPT] NAME...: one line from fd 0, one byte at a time (later commands get the rest), split | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # as sh does: IFS blanks around fields are dropped, one other IFS character ends a field, the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # NAME gets the rest of the line; without -r a backslash protects the next character, and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # backslash before the newline continues the line. Status 1 at end of file. The prompt of -p goes to fd 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # and only when fd 0 is a terminal, as in both shells (P6). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 49 | ▶ | sub read_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_line: called CC=17 SCAR=28.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 49 | my ($c, $m, $env, $names, $k) = @_; my @a = @$names; my ($raw, $prompt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 49 | ▶ | while (@a && $a[0] =~ /^-(r*)(p?)\z/ && "$1$2" ne '') { shift @a; $raw ||= $1 ne ''; $prompt = shift @a if $2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition77%7/9
@a and $a[0] =~ /^-(r*)(p?)\z/ and "$1$2" ne ""
@a and $a[0] =~ /^-(r*)(p?)\z/
$raw ||= $1 ne ""
MC/DC33%1/3
@a and $a[0] =~ /^-(r*)(p?)\z/ and "$1$2" ne ""
@a
$a[0] =~ /^-(r*)(p?)\z/
"$1$2" ne ""
MC/DC100%2/2
$raw ||= $1 ne ""
$raw
$1 ne ""
Truth table50%2/4
A and B and C
A= @aB= $a[0] =~ /^-(r*)(p?)\z/C= "$1$2" ne ""
Truth table100%3/3
A ||= B
A= $rawB= $1 ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | # names may come from expansions (post-0.04): checked here, with dash's messages and status 2 (A5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | return msg($c, "read: arg count", sub { $k->(2) }) unless @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 49 | ▶ | for (@a) { return msg($c, "read: $_: bad variable name", sub { $k->(2) }) unless /^[A-Za-z_][A-Za-z0-9_]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 66 | ▶ | return handler("Proc::ShellSpawn::Large::unsupported")->($c, "the name '$_' in 'read'") unless Proc::ShellSubset::settable($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 66 | ▶ | return msg($c, "read: $_: is read only", sub { $k->(2) }) if $c->{sh}{ro}{$_} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 47 | ▶ | my $e = $m->{0} or return defer($k, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 46 | ▶ | my $ifs = $env->{IFS} // $c->{sh}{vars}{IFS} // " \t\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
($env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}) // " \t\n"
$env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}
MC/DC0%0/2
($env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}) // " \t\n"
$env->{"IFS"}
$c->{"sh"}{"vars"}{"IFS"}
Truth table66%2/3
A // B
A= $env->{"IFS"}B= $c->{"sh"}{"vars"}{"IFS"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 46 | my %ws = map +($_ => 1), grep /[ \t\n]/, split //, $ifs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 46 | my %nw = map +($_ => 1), grep !/[ \t\n]/, split //, $ifs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 46 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 46 | ▶ | my $got = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=26 SCAR=32.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 46 | my $eof = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 46 | my @ch; # [character, protected by a backslash] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 46 | ▶ | if ($raw) { @ch = map [$_, 0], split //, $line } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 42 | ▶ | else { push @ch, defined $1 ? [$1, 1] : [$2, 0] while $line =~ /\G(?:\\(.)|([^\\]))/gs } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 46 | ▶ | my $isws = sub { !$_[0][1] && $ws{$_[0][0]} }; my $isnw = sub { !$_[0][1] && $nw{$_[0][0]} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 46 | ▶ | my $i = 0; $i++ while $i < @ch && $isws->($ch[$i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i < @ch and &$isws($ch[$i])
MC/DC100%2/2
$i < @ch and &$isws($ch[$i])
$i < @ch
&$isws($ch[$i])
Truth table100%3/3
A and B
A= $i < @chB= &$isws($ch[$i])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 46 | for my $j (0 .. $#a) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 64 | ▶ | if ($j == $#a) { # the rest; a single trailing delimiter after the only field is dropped, as in dash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 46 | ▶ | my @r = @ch[$i .. $#ch]; pop @r while @r && $isws->($r[-1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@r and &$isws($r[-1])
MC/DC100%2/2
@r and &$isws($r[-1])
@r
&$isws($r[-1])
Truth table100%3/3
A and B
A= @rB= &$isws($r[-1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 46 | ▶ | if (@r && $isnw->($r[-1]) && !grep $isws->($_) || $isnw->($_), @r[0 .. $#r - 1]) { pop @r; pop @r while @r && $isws->($r[-1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition58%7/12
@r and &$isnw($r[-1]) and not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
@r and &$isnw($r[-1])
&$isws($_) || &$isnw($_)
@r and &$isws($r[-1])
MC/DC66%2/3
@r and &$isnw($r[-1]) and not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
@r
&$isnw($r[-1])
not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
MC/DC0%0/2
&$isws($_) || &$isnw($_)
&$isws($_)
&$isnw($_)
MC/DC0%0/2
@r and &$isws($r[-1])
@r
&$isws($r[-1])
Truth table75%3/4
A and B and not(C)
A= @rB= &$isnw($r[-1])C= not grep((&$isws($_) || &$isnw($_)), @r[0 .. $#r - 1])
Truth table33%1/3
A || B
A= &$isws($_)B= &$isnw($_)
Truth table33%1/3
A and B
A= @rB= &$isws($r[-1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 46 | setvar($c, $a[$j], join '', map $_->[0], @r); last } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 18 | ▶ | my $f = ''; $f .= $ch[$i++][0] while $i < @ch && !$isws->($ch[$i]) && !$isnw->($ch[$i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$i < @ch and not &$isws($ch[$i]) and not &$isnw($ch[$i])
$i < @ch and not &$isws($ch[$i])
MC/DC100%3/3
$i < @ch and not &$isws($ch[$i]) and not &$isnw($ch[$i])
$i < @ch
not &$isws($ch[$i])
not &$isnw($ch[$i])
Truth table100%4/4
A and not(B) and not(C)
A= $i < @chB= not &$isws($ch[$i])C= not &$isnw($ch[$i])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 18 | setvar($c, $a[$j], $f); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 18 | ▶ | $i++ while $i < @ch && $isws->($ch[$i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i < @ch and &$isws($ch[$i])
MC/DC100%2/2
$i < @ch and &$isws($ch[$i])
$i < @ch
&$isws($ch[$i])
Truth table100%3/3
A and B
A= $i < @chB= &$isws($ch[$i])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 18 | ▶ | if ($i < @ch && $isnw->($ch[$i])) { $i++; $i++ while $i < @ch && $isws->($ch[$i]) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
$i < @ch and &$isnw($ch[$i])
$i < @ch and &$isws($ch[$i])
MC/DC100%2/2
$i < @ch and &$isnw($ch[$i])
$i < @ch
&$isnw($ch[$i])
MC/DC50%1/2
$i < @ch and &$isws($ch[$i])
$i < @ch
&$isws($ch[$i])
Truth table100%3/3
A and B
A= $i < @chB= &$isnw($ch[$i])
Truth table66%2/3
A and B
A= $i < @chB= &$isws($ch[$i])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 46 | ▶ | defer($k, $eof ? 1 : 0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 46 | ▶ | my $go = sub { on_read($e, 1, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 773 | my $b = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 773 | ▶ | return $got->(1) unless defined $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 765 | ▶ | if ($b eq "\n") { # continued if the line ends in an odd number of backslashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 38 | ▶ | return $got->(0) if $raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
MC/DC0%0/2
$raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
$raw
($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
Truth table66%2/3
A or B
A= $rawB= ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | chop $line; return on_read($e, 1, __SUB__) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 46 | $line .= $b; on_read($e, 1, __SUB__) }) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 46 | ▶ | defined $prompt && $e->{fh} && -t $e->{fh} ? put($c, 2, $prompt, $go) : $go->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $prompt and $e->{"fh"} and -t $e->{"fh"}
defined $prompt and $e->{"fh"}
MC/DC0%0/3
defined $prompt and $e->{"fh"} and -t $e->{"fh"}
defined $prompt
$e->{"fh"}
-t $e->{"fh"}
Truth table50%2/4
A and B and C
A= defined $promptB= $e->{"fh"}C= -t $e->{"fh"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # ------------------------------------------------------------------ entry points | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 476 | ▶ | sub start_pwd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_pwd: called CC=5 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 474 | my $phys = Cwd::getcwd(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 476 | my $p = $ENV{PWD}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 476 | ▶ | return $p if defined $p && is_abs($p) && (stat $p)[1] && join(':', (stat $p)[0, 1]) eq join(':', (stat '.')[0, 1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $p and is_abs($p) and (stat $p)[1] and join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
defined $p and is_abs($p) and (stat $p)[1]
defined $p and is_abs($p)
MC/DC0%0/4
defined $p and is_abs($p) and (stat $p)[1] and join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
defined $p
is_abs($p)
(stat $p)[1]
join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
Truth table20%1/5
A and B and C and D
A= defined $pB= is_abs($p)C= (stat $p)[1]D= join(":", (stat $p)[0, 1]) eq join(":", (stat ".")[0, 1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 2 | $phys } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # run(STRING or TREE, parser => CODE, interactive => 'nop' or 'dash', args => [$1 ...], arg0 => $0, opt => {e => 1, ...}): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | # sh's status, or (undef, ERROR) if STRING is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | # outside the subset. The parser also reads the text of eval, . and trap actions (with the aliases defined so far: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | # parser->(TEXT, aliases => {NAME => VALUE})). interactive: what history, fc, bind, help, compopt, logout and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | # set -o history do (B2): nothing (nop, the default; give the parser the same option) or as in dash (not found). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 480 | require Proc::ShellSpawn::Builtins; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 482 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=10 SCAR=24.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 482 | ▶ | my ($s, %o) = @_; my $parse = $o{parser} // default_parser(); a4(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$o{"parser"} // default_parser()
MC/DC0%0/2
$o{"parser"} // default_parser()
$o{"parser"}
default_parser()
Truth table33%1/3
A // B
A= $o{"parser"}B= default_parser()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 482 | ▶ | my $tree = ref $s ? $s : $parse->($s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 482 | ▶ | return (undef, $tree) if ref $tree eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 476 | my $cwd = start_pwd(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # dash sets OPTIND and IFS when it starts (L3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | my $sh = { vars => { %ENV, PWD => $cwd, OPTIND => 1, IFS => " \t\n", PPID => $Proc::Spawner::WIN ? Proc::Spawner::__win_ppid() : getppid() }, exp => { map +($_ => 1), keys %ENV, 'PWD' }, cwd => $cwd, q => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 476 | ▶ | parse => $parse, args => [@{$o{args} // []}], arg0 => $o{arg0}, pid => $$, opt => {%{$o{opt} // {}}}, cmd => {}, ro => {}, trap => {}, jobl => [], umask => umask, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$o{"args"} // []
$o{"opt"} // {}
$o{"interactive"} // "nop"
MC/DC0%0/1
$o{"args"} // []
$o{"args"}
MC/DC0%0/1
$o{"opt"} // {}
$o{"opt"}
MC/DC0%0/1
$o{"interactive"} // "nop"
$o{"interactive"}
Truth table50%1/2
A
A= $o{"args"}
Truth table50%1/2
A
A= $o{"opt"}
Truth table50%1/2
A
A= $o{"interactive"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 476 | ▶ | alias => {}, hash => {}, intext => 0, interactive => $o{interactive} // 'nop' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 476 | my $st; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 476 | ▶ | my $c = { sh => $sh, loops => [], map => { map +($_ => is_open($_) ? own_fd($_) : undef), 0 .. 2 } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 476 | ▶ | my $scope = []; $c->{shell} = { scope => $scope, exit => shell_exit($c, $scope, sub { $st //= shift }) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Condition33%1/3
$st //= shift()
MC/DC0%0/2
$st //= shift()
$st
shift()
Truth table33%1/3
A //= B
A= $stB= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 476 | ▶ | $sh->{die} = sub { $st //= shift }; # kill ... $$ (Proc::ShellSpawn::Large::b_kill): the whole string ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=10.5
Condition0%0/3
$st //= shift()
MC/DC0%0/2
$st //= shift()
$st
shift()
Truth table0%0/3
A //= B
A= $stB= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 476 | local %TRAPSAVE = (); $SIGNALLED = undef; # signals the trap builtin changed: put back afterwards | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 476 | { local $RUNNING = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 476 | ▶ | ignoring_int(sub { x_list($c, $tree, undef, $c->{shell}{exit}); loop_until(sub { defined $st }) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 476 | $SIG{$_} = $TRAPSAVE{$_} for keys %TRAPSAVE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 476 | %$c = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 476 | idle(1); idle_pass(); # K3 (B): background jobs move on between calls too | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 476 | $st } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 480 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||