| 1 | package Proc::ShellSpawn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 550 | ▶ | BEGIN { *ProcSS:: = \*Proc::ShellSpawn:: } # JU3 (post-0.12, the user, 2026-11-15): the alias by which Large and Builtins call this module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Runs Proc::ShellSubset parse trees with posix_spawn(3), in the simplest scenario: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # this module is the only code that starts child processes, and it owns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # SIGCHLD while it runs. No fork in Perl: compound commands, pipelines of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # them, subshells, $( ), loops and background chains run in this process as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # continuations driven by one event loop. This is the shell layer only: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # loop and the starting of children are Proc::Spawner's, the ends and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # process nodes (with the continuation each runs when it ends) Proc::Spawner::Graph's. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Aim: what dash and bash do alike (the parsers reject what they do differently); where the two differ only at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # run time, as dash does (rule A5, doc/large-subset/large-subset-spec.md). Every program started is a child of this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Perl process, never a grandchild. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Process-wide state flipped for a while, so bullet-proof only in non-threaded execution: Perl's umask, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # set to the shell's while a redirection's file is opened (open_end); SIGINT, SIGQUIT and SIGPIPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # ignored while run() runs (ignoring_int); traps, set in %SIG while run() runs and put back after it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # (Proc::ShellSpawn::Large, b_trap); SIGCHLD between run() calls while background jobs remain (idle, K3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # and Proc::Spawner's own (umask in start, SIGCHLD in wait_until). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 550 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 557 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 556 | ▶ | use File::Glob (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 549 | ▶ | use Cwd (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 549 | ▶ | use Proc::Spawner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 570 | ▶ | use Proc::Spawner::Graph; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 549 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 547 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 547 | our $TRACE; *TRACE = \$Proc::Spawner::TRACE; # undef, or a code ref given one line per fd or process operation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 547 | our %PARSE = map +($_ => 1), qw(assign param_ops if while for case read empty); # options for Proc::ShellSubset and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # Proc::ShellSubset::Large | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # (empty, post4-0.04: a string with no command, or only comments, runs as nothing, status 0, as in both shells; also eval '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # The parser for run(STRING): run(STRING, parser => CODE), CODE->(TEXT) returning a tree or an error hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Default (EXPERIMENTAL, awaiting approval): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # the largest of Proc::ShellSubset::Large, Proc::ShellSubset, Proc::ShellSubset::Small that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # caller has loaded; if none is, Proc::ShellSubset is loaded. The executor itself loads no parser otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 569 | ▶ | sub default_parser { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_parser: called CC=4 SCAR=23.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 597 | ▶ | defined &Proc::ShellSubset::Large::parse ? sub { Proc::ShellSubset::Large::parse($_[0], %PARSE, @_[1 .. $#_]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | : defined &Proc::ShellSubset::parse ? sub { Proc::ShellSubset::parse($_[0], %PARSE) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | : defined &Proc::ShellSubset::Small::parse ? \&Proc::ShellSubset::Small::parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | : do { require Proc::ShellSubset; sub { Proc::ShellSubset::parse($_[0], %PARSE) } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=4.1
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 547 | our $NAME = 'sh'; # prefix of error messages, as sh's "$0" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # EXPERIMENTAL (item N9): with TRACE=dot, one Graphviz picture per event (a start, an exit, an end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # closed) as trace-001.dot, ... in the directory TRACE_DIR (default: the current one). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 547 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 715 | ▶ | sub tr_ { $TRACE->(join '', @_) if $TRACE } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tr_: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 547 | our $G = Proc::Spawner::Graph->new(dot => $DOT); # our children and our own reads and writes, now | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # ------------------------------------------------------------------ extension points (EXPERIMENTAL, awaiting approval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Handlers are named by fully qualified sub names, resolved (and their module loaded) at first use: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # a command node { ext => NAME, ... }, or one with a key of %KIND: NAME->(CONTEXT, NODE, TAIL, K) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # a command name in %CMD (or the shell's own table, for functions): NAME->(CONTEXT, ARGV, ENV, K, DATA) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # a Part [ext => NAME, ...] of a Word: NAME->(CONTEXT, PART, K) with K->(TEXT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Each calls K exactly once (or ends the shell with leave), maybe later, and never waits (D2). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 547 | our %KIND = map +($_ => "Proc::ShellSpawn::Large::x_$_"), qw(func export readonly local exec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 547 | our %CMD = (':' => ['Proc::ShellSpawn::b_colon'], exit => ['Proc::ShellSpawn::b_exit'], read => ['Proc::ShellSpawn::b_read'], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | (map +($_ => ['Proc::ShellSpawn::b_break']), qw(break continue)), # (JU2, post-0.12: a function each) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | (map +($_ => ["Proc::ShellSpawn::Large::b_$_"]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | qw(return shift set eval trap wait umask command getopts unset kill pwd)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | '.' => ['Proc::ShellSpawn::Large::b_dot'], (map +($_ => ['Proc::ShellSpawn::Large::b_test']), '[', 'test')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 547 | our $ONBUILTIN; # undef, or a code ref called (HANDLER, [ARGV], {SETTINGS}) for each command where no program runs: before a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # builtin or function runs (cd: x_cd; export, readonly, local: x_NAME, after), a command not found ('not found', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # 'denied'), settings alone (x_set, ARGV empty, after) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 547 | our %A4; # builtins left to sh: A4 (status 248) when one is named at run time | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # B2 of "Shell Corpus Gaps": the tables of command names, searched in order; a module adds its own with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # unshift @Proc::ShellSpawn::CMDS, \%MINE (Proc::ShellSpawn::Builtins does). %A4 stays last. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 547 | our @CMDS = (\%CMD, \%A4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1402 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 558 | ▶ | 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{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 547 | our $SIGNALLED; # after run(): the signal of 'kill ... $$' that ended the string, if any | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 547 | our %TRAPSAVE; # signals the trap builtin changed during run(), with their old settings | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 547 | our %SPECIAL = map +($_ => 1), qw(: break continue . eval exec exit export readonly return set shift times trap unset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 568 | ▶ | BEGIN { *handler = \&Proc::Spawner::Graph::handler } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 126 | ▶ | sub done { my ($k, $st) = @_; sub { $k->($st) } } # "then finish with status $st": for a call that takes what to do next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
done: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 40 | ▶ | sub fail { # stop this shell with $st, after the message $text if given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 47 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # ------------------------------------------------------------------ ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # The ends (Proc::Spawner::Graph) are what a context maps its fds to; each context holds the ends of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # its map, and the last release closes one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1639 | ▶ | sub own_fd { $G->parent_end(shift) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
own_fd: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1651 | ▶ | 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])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 17 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 10 | Proc::Spawner::__fd_cloexec(shift) == 0 } # fcntl F_GETFD (until 0.05: /proc/self/fdinfo, Linux only; RT #182479) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 163 | ▶ | sub new_pipe { $G->new_pipe } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_pipe: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # ------------------------------------------------------------------ paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # 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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # /x is the current drive's root; \ separates as / does; PATH is split at $Config{path_sep} (;, Proc::Spawner::path_split) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # and a command is looked up with the extensions of PATHEXT first; /dev/null is NUL. The shell's own directory keeps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # Perl's form (C:/x/y). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 547 | our $WIN = $Proc::Spawner::WIN; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 547 | ▶ | my $SEP = $WIN ? qr{[/\\]+} : qr{/+}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 595 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 630 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2572 | ▶ | sub path_in { # PATH from the shell's directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_in: called CC=6 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2572 | my ($c, $p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2579 | ▶ | return $p if $WIN ? $p =~ m{^[A-Za-z]:[/\\]|^[/\\]{2}} : $p =~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 73 | ▶ | return ($c->{sh}{cwd} =~ m{^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)} ? $1 : '') . $p if $WIN && $p =~ m{^[/\\]}; # (the drive, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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(^[/\\])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # or the UNC share) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 73 | "$c->{sh}{cwd}/$p" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 299 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | 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=26.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # is its sibling of that name, if that is a directory (profiles are usually siblings; not always: the registry's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # ProfileList has the real ones, a domain profile may be user.DOMAIN); else undef (~user stays as written) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | ▶ | my $d = ($up =~ s{[^/\\]+[/\\]*\z}{}r) . $n; -d $d ? $d : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 135 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # files_eq(A, B): do the two names mean the same file? The one place for this question (the user, 2026-11-14, JH3: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # device and inode numbers are a legacy way to tell, and the uses are not to be tied to it): where the shell starts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # (start_pwd), and test -ef and pwd -L of Proc::ShellSpawn::Programs, which loads this module for it only then. On the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # legacy systems: the same device and inode numbers. Where stat gives no usable numbers for one of the two (an inode of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # 0, as Perl on Windows gave before 5.34): paths_eq. On Windows (post-0.12, the user, 2026-11-16) the way Microsoft | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # documents: both opened, and the volume's serial number with the 128-bit file ID compared (the 64-bit file index where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # that is not there; Proc::Spawner::__win_same_file), the names made absolute first (Perl's directory, which a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # pseudo-process does not share with the process); only if that cannot tell, the rest. False if either does not exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 587 | ▶ | sub files_eq { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
files_eq: called CC=10 SCAR=27.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 563 | ▶ | my @a = stat $_[0] or return ''; my @b = stat $_[1] or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 563 | ▶ | if ($WIN && defined &Proc::Spawner::__win_same_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Proc::ShellSpawn::WIN and defined &Proc::Spawner::__win_same_file
MC/DC0%0/2
$Proc::ShellSpawn::WIN and defined &Proc::Spawner::__win_same_file
$Proc::ShellSpawn::WIN
defined &Proc::Spawner::__win_same_file
Truth table33%1/3
A and B
A= $Proc::ShellSpawn::WINB= defined &Proc::Spawner::__win_same_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 14 | require File::Spec; my $here = Cwd::getcwd(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 17 | my $r = Proc::Spawner::__win_same_file(map File::Spec->rel2abs($_, $here), @_[0, 1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 17 | ▶ | return $r ? 1 : '' if defined $r } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 577 | ▶ | $a[1] && $b[1] ? $a[0] == $b[0] && $a[1] == $b[1] : paths_eq(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$a[1] and $b[1]
$a[0] == $b[0] and $a[1] == $b[1]
MC/DC0%0/2
$a[1] and $b[1]
$a[1]
$b[1]
MC/DC50%1/2
$a[0] == $b[0] and $a[1] == $b[1]
$a[0] == $b[0]
$a[1] == $b[1]
Truth table33%1/3
A and B
A= $a[1]B= $b[1]
Truth table66%2/3
A and B
A= $a[0] == $b[0]B= $a[1] == $b[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub paths_eq { # the same path once symbolic links, '.' and '..' are resolved (Windows: without regard to case); two | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paths_eq: not called CC=4 SCAR=16.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 14 | my ($x, $y) = map Cwd::realpath($_), @_[0, 1]; # hard links to one file are not found the same this way | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 14 | ▶ | defined $x && defined $y && ($WIN ? lc $x eq lc $y : $x eq $y) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $x and defined $y
MC/DC0%0/2
defined $x and defined $y
defined $x
defined $y
Truth table33%1/3
A and B
A= defined $xB= defined $y
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 114 | ▶ | sub open_end { # an end on a file, or undef with $! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_end: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 128 | my ($c, $name, $op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 128 | my $path = path_in($c, os_path($name)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 114 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 113 | my $um = umask $c->{sh}{umask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 113 | my $ok = sysopen my $fh, $path, $Proc::Spawner::Graph::OPEN{$op}, 0666; my $err = $!; umask $um; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 127 | ▶ | $! = $err, return unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 110 | $G->file_end($fh, $op, $name) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # ------------------------------------------------------------------ contexts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # A context: what the commands run in it get. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # map => { CHILD_FD => end, or undef for closed }; fds not listed are ours, inherited as they are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # sh => the shell state: vars, exp(orted names), cwd, q ($?), bang ($!), qsub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # loops => [ { brk => K, cont => K, scope => [contexts] }, ... ] of the enclosing loops | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # shell => { exit => K, scope => [contexts] } for exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # held => 1 if this context holds its map's ends; released by release_ctx, once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 545 | my %LIVE; # each shell (context) not ended yet, weakly: a job's shell is released once its last process has started | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 842 | ▶ | sub derive { # a context with its own map, which it holds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
derive: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 856 | my ($c, $map, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 842 | my $d = { %$c, map => $map, held => 1, released => 0, root => !!$o{shell}, late => 0 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 842 | ▶ | if (my $k = $o{shell}) { # a new shell: copies of the state; exit and loops start afresh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 314 | my $sh = $c->{sh}; # leaving it releases every context made in it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 314 | $d->{sh} = { %$sh, main => $sh->{main} // $sh, vars => { %{$sh->{vars}} }, exp => { %{$sh->{exp}} }, args => [@{$sh->{args}}], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 328 | ▶ | opt => { %{$sh->{opt}} }, cmd => { %{$sh->{cmd}} }, ro => { %{$sh->{ro}} }, jobl => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 251 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | pend => [], twait => [], tbusy => 0, # the caught signals belong to the shell whose trap caught them (X19) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 314 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 321 | my $scope = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 328 | $d->{loops} = []; delete @$d{qw(frame cond)}; $d->{shell} = { scope => $scope, exit => shell_exit($d, $scope, $k) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 321 | weaken($LIVE{$d} = $d) } # (for the wait at exit, K5) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 842 | hold($_) for values %$map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 842 | ▶ | push @{ @{$d->{loops}} ? $d->{loops}[-1]{scope} : $d->{shell}{scope} }, $d; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 843 | $d } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 85 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 858 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 858 | my ($c, $scope, $k) = @_; my $id = "$c"; weaken($c); my $state = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 848 | ▶ | sub { my $st = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 846 | ▶ | return if $state == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 846 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 847 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | $state = 1; my $tc = { %$c, loops => [], held => 0, cond => undef, frame => undef }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | ▶ | return x_list($tc, $t, undef, sub { return if $state == 2; $state = 2; delete $LIVE{$id}; late($c); release_all($scope); $k->($st) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 860 | $state = 2; delete $LIVE{$id}; late($c); release_all($scope); $k->($st) } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 852 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1561 | ▶ | sub release_ctx { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
release_ctx: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1568 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 854 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 851 | $c->{released} = 1; release($_) for values %{$c->{map}} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1083 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # ------------------------------------------------------------------ the loop and the graph | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Proc::Spawner runs the loop; every continuation runs from its queue, one at a time, and never waits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Our children and our own reads and writes are nodes of the graph $G (Proc::Spawner::Graph); a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # child's node carries its continuation as on_exit ['Proc::ShellSpawn::resume', K]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 653 | ▶ | BEGIN { *defer = \&Proc::Spawner::defer; *hold = \&Proc::Spawner::Graph::hold; *release = \&Proc::Spawner::Graph::release } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 544 | ▶ | sub loop_until { Proc::Spawner::wait_until(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop_until: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1829 | ▶ | sub on_read { my ($e, $n, $cb) = @_; $G->perl_read($e, $n, sub { $cb->($_[1]) }) } # one read of end $e: $cb->(BYTES), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
on_read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # or undef at end of file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 862 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 280 | ▶ | sub status_of { # a wait status as sh's $? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_of: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 280 | my $w = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 280 | ▶ | $w & 127 ? 128 + ($w & 127) : $w >> 8 } # (by hand: Windows' POSIX has no WIFSIGNALED; Perl's $? is the same there) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # Background jobs left running when run() returns go on between calls too (idle, below); at exit we finish them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | my %JOBS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # As Perl's system: SIGINT and SIGQUIT are ignored here while commands run (a foreground child gets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # them back by sigdefault; a background child keeps them ignored, as POSIX asks of an asynchronous list). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 563 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | sub wait_all { idle(0); ignoring_int(sub { loop_until(sub { !%JOBS }) }) if %JOBS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
wait_all: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # At exit (post-0.12, K5, the user, 2026-11-15: "as shell"): the shells leave their background jobs running. Ours | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # starts every command of a job itself (no fork: a job's next command is started here when the one before ends), so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # it waits while it has anything left to do for a job: a command still to start, a read or write of its own, a call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # queued; then it exits, leaving the processes running, as the shells do. PROC_SHELLSPAWN_END, or $END_WAIT at run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # time (a stopgap until such choices are arguments of the API): MODE[:SECONDS], MODE shell (the default), all (wait | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # until every job has ended: before post-0.12), none (exit at once: the jobs' commands not yet started never start); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # SECONDS: wait at most that long (then as none). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 545 | ▶ | our $END_WAIT = $ENV{PROC_SHELLSPAWN_END} // 'shell'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"PROC_SHELLSPAWN_END"} // "shell"
MC/DC0%0/1
$ENV{"PROC_SHELLSPAWN_END"} // "shell"
$ENV{"PROC_SHELLSPAWN_END"}
Truth table50%1/2
A
A= $ENV{"PROC_SHELLSPAWN_END"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1095 | ▶ | sub end_wait_mode { my ($m, $s) = ($_[0] // '') =~ /\A(shell|all|none)?(?::(\d+(?:\.\d*)?))?\z/ or return; ($m // 'shell', $s) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end_wait_mode: called CC=4 SCAR=15.8
Pod
undocumented
Branch: 1 branch
Condition50%2/4
$_[0] // ""
$m // "shell"
MC/DC0%0/1
$_[0] // ""
$_[0]
MC/DC0%0/1
$m // "shell"
$m
Truth table50%1/2
A
A= $_[0]
Truth table50%1/2
A
A= $m
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 545 | ▶ | (end_wait_mode($END_WAIT))[0] // do { my $v = $END_WAIT; $END_WAIT = 'shell'; # (so that END does not complain again) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(end_wait_mode($Proc::ShellSpawn::END_WAIT))[0] // do {
my $v = $Proc::ShellSpawn::END_WAIT;
$Proc::ShellSpawn::END_WAIT = "shell";
die "PROC_SHELLSPAWN_END: '${v}' is not MODE[:SECONDS], MODE one of shell, all, none\n"
}
MC/DC0%0/2
(end_wait_mode($Proc::ShellSpawn::END_WAIT))[0] // do {
my $v = $Proc::ShellSpawn::END_WAIT;
$Proc::ShellSpawn::END_WAIT = "shell";
die "PROC_SHELLSPAWN_END: '${v}' is not MODE[:SECONDS], MODE one of shell, all, none\n"
}
(end_wait_mode($Proc::ShellSpawn::END_WAIT))[0]
do {
my $v = $Proc::ShellSpawn::END_WAIT;
$Proc::ShellSpawn::END_WAIT = "shell";
die "PROC_SHELLSPAWN_END: '${v}' is not MODE[:SECONDS], MODE one of shell, all, none\n"
}
Truth table33%1/3
A // B
A= (end_wait_mode($Proc::ShellSpawn::END_WAIT))[0]B= do {
my $v = $Proc::ShellSpawn::END_WAIT;
$Proc::ShellSpawn::END_WAIT = "shell";
die "PROC_SHELLSPAWN_END: '${v}' is not MODE[:SECONDS], MODE one of shell, all, none\n"
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | die "PROC_SHELLSPAWN_END: '$v' is not MODE[:SECONDS], MODE one of shell, all, none\n" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 12 | ▶ | sub settled { !grep(defined && !$_->{released}, values %LIVE) && !%{$G->{io}} && !Proc::Spawner::loop()->queued } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
settled: called CC=4 SCAR=18.9
Pod
undocumented
Condition33%3/9
grep((defined $_ && !$_->{'released'}), values %LIVE) || %{$Proc::ShellSpawn::G->{'io'};} || Proc::Spawner::loop()->queued
grep((defined $_ && !$_->{"released"}), values %LIVE) or %{$Proc::ShellSpawn::G->{"io"};}
defined $_ && !$_->{'released'}
MC/DC0%0/3
grep((defined $_ && !$_->{'released'}), values %LIVE) || %{$Proc::ShellSpawn::G->{'io'};} || Proc::Spawner::loop()->queued
grep((defined $_ && !$_->{"released"}), values %LIVE)
%{$Proc::ShellSpawn::G->{"io"};}
Proc::Spawner::loop()->queued
MC/DC0%0/2
defined $_ && !$_->{'released'}
defined $_
!$_->{'released'}
Truth table25%1/4
A or B || C
A= grep((defined $_ && !$_->{"released"}), values %LIVE)B= %{$Proc::ShellSpawn::G->{"io"};}C= Proc::Spawner::loop()->queued
Truth table33%1/3
A && not(B)
A= defined $_B= !$_->{'released'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 547 | ▶ | sub end_wait { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end_wait: called CC=5 SCAR=17.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 548 | my ($mode, $secs) = end_wait_mode($END_WAIT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 554 | ▶ | $mode //= 'shell', warn "Proc::ShellSpawn: \$END_WAIT '$END_WAIT' is not MODE[:SECONDS]; shell taken\n" unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$mode //= "shell"
MC/DC0%0/1
$mode //= "shell"
$mode
Truth table0%0/2
A
A= $mode
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 554 | ▶ | return if !%JOBS or $mode eq 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not %JOBS or $mode eq "none"
MC/DC50%1/2
not %JOBS or $mode eq "none"
not %JOBS
$mode eq "none"
Truth table66%2/3
not(A) or B
A= not %JOBSB= $mode eq "none"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | idle(0); ignoring_int(sub { Proc::Spawner::wait_until($mode eq 'all' ? sub { !%JOBS } : sub { !%JOBS || settled() }, $secs) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 554 | ▶ | END { local $?; end_wait() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Between run() calls (K3, the user's choice B, post-0.04): while background jobs remain, a deferred SIGCHLD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # handler moves them on when a child ends, whatever Perl is doing (a chain's next command starts at once). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Its cost, documented: the program's own sleep and select return early when a child ends, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # program's own $SIG{CHLD} is called by ours (a CODE handler; set afterwards, it replaces ours). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 547 | our $RUNNING = 0; # inside run(): the loop there does it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 547 | my ($IDLE_ON, $IDLE_OLD); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 556 | ▶ | sub idle_pass { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
idle_pass: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 546 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 10 | ignoring_int(\&Proc::Spawner::poll); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 10 | ▶ | idle(0) unless %JOBS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 562 | ▶ | sub idle { # 1: install the handler (if jobs remain), 0: put the previous one back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
idle: called CC=8 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 554 | my $on = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 554 | ▶ | return if $WIN; # (no SIGCHLD there: background jobs move on at the next run, wait or poll) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 554 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 10 | $IDLE_OLD = POSIX::SigAction->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my $a = POSIX::SigAction->new(sub { local ($?, $!); # (X55: the program's $? and $! stay as they were) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | idle_pass(); my $h = $IDLE_OLD && $IDLE_OLD->{HANDLER}; $h->(@_) if ref $h eq 'CODE' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 10 | POSIX::SigSet->new, POSIX::SA_RESTART()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 10 | $a->safe(1); # deferred: runs between Perl operations, never inside the signal (S2) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 10 | ▶ | POSIX::sigaction(POSIX::SIGCHLD(), $a, $IDLE_OLD) and $IDLE_ON = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 10 | ▶ | elsif (!$on && $IDLE_ON) { POSIX::sigaction(POSIX::SIGCHLD(), $IDLE_OLD); $IDLE_ON = 0 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $on and $IDLE_ON
MC/DC50%1/2
not $on and $IDLE_ON
not $on
$IDLE_ON
Truth table66%2/3
not(A) and B
A= not $onB= $IDLE_ON
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # ------------------------------------------------------------------ spawning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # Signals ignored when we were loaded stay ignored in children, as sh keeps the ones ignored on entry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # SIGFPE as Perl's own exec would pass it: Perl may ignore it for itself at startup, and puts back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # the disposition it found then (PERL_FPU_PRE_EXEC, PL_sigfpe_saved; fpe_at_exec() reads it). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 547 | my $FPE = Proc::Spawner::fpe_at_exec(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 547 | ▶ | our %IGN0 = map +($_ => 1), grep +($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1), keys %SIG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition87%7/8
($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1)
$SIG{$_} // ""
$_ ne "FPE" or $FPE == 1
MC/DC66%2/3
($SIG{$_} // '') eq 'IGNORE' && ($_ ne 'FPE' || $FPE == 1)
$SIG{$_}
$_ ne "FPE"
$FPE == 1
Truth table75%3/4
A && B or C
A= $SIG{$_}B= $_ ne "FPE"C= $FPE == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 219 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # in $then, so nothing started later overtakes the text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 219 | ▶ | 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 {
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 219 | my $e = $c->{map}{$fd}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 219 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 109 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 632 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 630 | my ($c, $fd, $t, $k) = @_; my $e = $c->{map}{$fd}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 630 | ▶ | return defer($k, undef) if $t eq ''; return defer($k, POSIX::EBADF()) unless $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 629 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # Programs run inside this process (Proc::ShellSpawn::Programs, after coreutils 9.4), by name (X21). Decision IP1 (the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # user, 2026-11-08: "when a well-debugged builtin is already present, use it. (By default; Configurable.)"): echo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # printf test [ true false, and since post-0.10 pwd (b_pwd runs it as 'pwd -L', X23), on every platform; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # PROC_SHELLSPAWN_INPROC changes the default (none: the programs; names: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # only these; all), and %INPROC can be changed at run time. A name with a '/' is always a program. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 547 | our @INPROC = qw(echo printf test [ true false pwd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | our %INPROC = map +($_ => 1), map $_ eq 'all' ? @INPROC : $_ eq 'none' ? () : $_, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 547 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # Whose echo the in-process echo is (decision EC1, the user, 2026-11-09): coreutils (the default; it heeds POSIXLY_CORRECT), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # dash or bash (their builtins, which do not); $ECHO can be changed at run time. The program echo (not in %INPROC) is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # affected. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 547 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 547 | ▶ | die "PROC_SHELLSPAWN_ECHO: '$ECHO' is none of coreutils, dash, bash\n" unless $ECHO =~ /\A(?:coreutils|dash|bash)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # (no directory) runs as $^X -MPARSER -MProc::ShellSpawn=sh -e0 -- ARGS, PARSER the largest parser loaded here (as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # default_parser), with this Perl's @INC; then sh_main below reads ARGS as sh does. PROC_SHELLSPAWN_SH (or $SH at run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # time): auto (the default: so when the command's PATH has no sh), perl (always), program (never). The text after -c is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # an argument: through the primitive system1 on Windows, Perl's own spawn drops a " from it, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # and splits it at blanks too if it has one (❰BUG❱ in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # Perl, doc/perl-win32-system-bugs.md, 1); not worked around. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 547 | ▶ | 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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 547 | ▶ | die "PROC_SHELLSPAWN_SH: '$SH' is none of auto, perl, program\n" unless $SH =~ /\A(?:auto|perl|program)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 315 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 306 | my ($c, $argv, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 306 | ▶ | 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])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 549 | ▶ | my ($parser) = grep { no strict 'refs'; defined &{"${_}::parse"} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | qw(Proc::ShellSubset::Large Proc::ShellSubset Proc::ShellSubset::Small); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 10 | ▶ | [$^X, (map "-I$_", grep !ref, @INC), '-M' . ($parser // 'Proc::ShellSubset'), '-MProc::ShellSpawn=sh', '-e0', '--', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$parser // "Proc::ShellSubset"
MC/DC0%0/1
$parser // "Proc::ShellSubset"
$parser
Truth table50%1/2
A
A= $parser
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | @$argv[1 .. $#$argv]] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1310 | ▶ | sub import { # use Proc::ShellSpawn 'sh': run as sh with @ARGV, then exit (SH1); with no list, nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1302 | ▶ | my ($pkg, @w) = @_; return unless @w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 12 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 12 | exit sh_main(@ARGV) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 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=47.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my @a = @_; my ($opt_c, $opt_s, $text, $name, %opt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 12 | ▶ | my $bad = sub { print STDERR "sh: $_[0]\n"; 2 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 12 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 96 | ▶ | shift @a; last if $1 eq '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 96 | for my $l (split //, $1) { # -c, -s; other letters as set takes them (-e, -u, -x, ...) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 12 | ▶ | $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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | : return $bad->("-$l: option not supported here (SH1)") } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if ($opt_c) { @a or return $bad->('-c requires an argument'); $text = shift @a; $name = shift @a } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 8 | ▶ | $name = shift @a; open my $f, '<', $name or return $bad->("0: cannot open $name: $!"); binmode $f; local $/; $text = <$f> } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 7 | ▶ | local $NAME = $name // 'sh'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$name // "sh"
MC/DC0%0/1
$name // "sh"
$name
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 7 | my ($st, $err) = run($text, args => \@a, arg0 => $NAME, opt => \%opt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 7 | ▶ | defined $st or print(STDERR "$NAME: outside the subset: $err->{error} at $err->{pos}\n"), return 255; # (as t/try.pl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 7 | ▶ | if (my $s = $SIGNALLED) { local $SIG{$s} = 'DEFAULT'; kill $s, $$; sleep 1 } # die by it, as sh would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 7 | $st } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # TEMPORARY WORKAROUND (post-0.10, BIN1; the user's follow-up (d) to WS1, "Replace them from %ENV (inventing suitable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # fallbacks)", marked temporary by the user, 2026-11-10): where cat, sort, grep and the like come from. The directories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # in PROC_SHELLSPAWN_BIN (split as PATH; 'none': none, since Windows has no empty variables) are searched before PATH, on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # any platform. Unset, on Windows: the first of Git for Windows' usr\bin (beside git.exe on PATH, or under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # %ProgramFiles%, %ProgramW6432%, %LOCALAPPDATA%\Programs), MSYS2's (%SystemDrive%\msys64\usr\bin) and Cygwin's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # (%SystemDrive%\cygwin64\bin) that has cat.exe; elsewhere none. Also on Windows, a program of the system's own (under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # %SystemRoot%) named sort, find, timeout or expand is never taken for the POSIX one: they differ. @BIN at run time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | our @BIN = !defined $ENV{PROC_SHELLSPAWN_BIN} ? ($WIN ? win_posix_bin() : ()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 547 | ▶ | : $ENV{PROC_SHELLSPAWN_BIN} eq 'none' ? () : Proc::Spawner::path_split($ENV{PROC_SHELLSPAWN_BIN}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 9 | ▶ | sub win_posix_bin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
win_posix_bin: called CC=5 SCAR=32.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | my $up = sub { $_[0] =~ s{[/\\][^/\\]+\z}{}r }; # the parent directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my @git = map { ($up->($_), $up->($up->($_))) } grep -f "$_\\git.exe", Proc::Spawner::path_split($ENV{PATH}); # Git\cmd, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # Git\mingw64\bin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | for my $d ((map "$_\\usr\\bin", @git), (map "$_\\Git\\usr\\bin", grep defined, @ENV{qw(ProgramFiles ProgramW6432)}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | (defined $ENV{LOCALAPPDATA} ? "$ENV{LOCALAPPDATA}\\Programs\\Git\\usr\\bin" : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | "$sd\\msys64\\usr\\bin", "$sd\\cygwin64\\bin") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | return $d if -f "$d\\cat.exe" } () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 547 | my %WINCLASH = map +($_ => 1), qw(sort find timeout expand); # Windows' own programs of these names are others (BIN1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | sub win_clash { my ($name, $p) = @_; my $r = $ENV{SystemRoot} // return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
win_clash: not called CC=3 SCAR=24.8
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | $WINCLASH{lc $name} && lc(substr($p, 0, length $r) =~ tr{/}{\\}r) eq lc($r =~ tr{/}{\\}r) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 322 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 322 | my ($c, $name, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 322 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 322 | ▶ | if (has_dir($name)) { -f path_in($c, "$name$_") and return "$name$_" for @ext; return $name } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 293 | my $denied; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 293 | for my $d (@BIN, path_list($path)) { for my $e (@ext) { # (@BIN: BIN1, a temporary workaround) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 2367 | ▶ | 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[/]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 2367 | ▶ | next unless -f path_in($c, $p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 278 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 278 | ▶ | return $p if -x _; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | ▶ | $denied //= $p } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$denied //= $p
MC/DC0%0/2
$denied //= $p
$denied
$p
Truth table0%0/3
A //= B
A= $deniedB= $p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 16 | ▶ | defined $denied ? (undef, 126, $denied) : (undef, 127) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 994 | ▶ | sub spawn { # starts @$argv with $map; $k->(STATUS) when it has ended; returns its process node or undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=29 SCAR=38.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 994 | my ($c, $map, $argv, $env, $k, $search) = @_; # $search: the PATH to look in, if not the command's own (command -p) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 994 | ▶ | 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: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # names only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 994 | ▶ | return inproc($c, $map, $argv, \%e, $k) if $INPROC{$argv->[0]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 306 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 308 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 308 | ▶ | $c->{sh}{hash}{$argv->[0]} = $path if defined $path && !defined $search && !has_dir($argv->[0]); # remembered, as dash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # (hash, type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 15 | ▶ | my $no = sub { # the command does not start: its message and the status, 127 (not found) or 126 ($why); with $log the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 23 | my ($st, $why, $log) = @_; # measuring hook is told too (no program runs) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 23 | ▶ | $ONBUILTIN->($st == 127 ? 'not found' : 'denied', $argv, {%$env}) if $log && $ONBUILTIN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$log and $Proc::ShellSpawn::ONBUILTIN
MC/DC0%0/2
$log and $Proc::ShellSpawn::ONBUILTIN
$log
$Proc::ShellSpawn::ONBUILTIN
Truth table66%2/3
A and B
A= $logB= $Proc::ShellSpawn::ONBUILTIN
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 307 | ▶ | cmd_msg($c, $map, "$argv->[0]: " . ($st == 127 ? 'not found' : $why), done($k, $st)) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 307 | ▶ | return $no->($st, 'Permission denied', 1) if !defined $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 295 | ▶ | return $no->(126, 'Permission denied', 1) # 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 _
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # or "Exec format error") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | if $WIN && -e path_in($c, $path) && (-d _ || !-x _); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 295 | my @envp = map "$_=$e{$_}", sort keys %e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 296 | ▶ | my %def = map +($_ => 1), grep !$IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{sh}{trap}{$_} // 1) ne '', # trap '' SIG: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition70%7/10
!$Proc::ShellSpawn::IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{'sh'}{'trap'}{$_} // 1) ne ''
not $Proc::ShellSpawn::IGN0{$_} and ($SIG{$_} // "") eq "IGNORE"
$SIG{$_} // ""
$c->{"sh"}{"trap"}{$_} // 1
MC/DC0%0/3
!$Proc::ShellSpawn::IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{'sh'}{'trap'}{$_} // 1) ne ''
not $Proc::ShellSpawn::IGN0{$_}
$SIG{$_}
$c->{"sh"}{"trap"}{$_}
Truth table50%2/4
not(A) and B && C
A= not $Proc::ShellSpawn::IGN0{$_}B= $SIG{$_}C= $c->{"sh"}{"trap"}{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # stays ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | keys %SIG, $FPE ? () : 'FPE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 296 | ▶ | delete @def{qw(INT QUIT)} if $c->{sh}{job}; # in the background: left ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | my @o = (sigdefault => [sort keys %def], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | $WIN ? () : (umask => $c->{sh}{umask}), on_exit => ['Proc::ShellSpawn::resume', $k], # (Windows: no umask) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 296 | ▶ | $c->{sh}{cwd} ne Cwd::getcwd() ? (chdir => $c->{sh}{cwd}) : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 296 | my $node = $G->start($path, $argv, \@envp, $map, @o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 295 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $node = $G->start('/bin/sh', ['sh', $path, @$argv[1 .. $#$argv]], \@envp, $map, @o) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 295 | ▶ | return $node if $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 4 | my $err = "$!"; # an fd of ours that is not open: the first one the child should have got | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 5 | ▶ | my ($bad) = grep !is_open($_), map $map->{$_} ? $map->{$_}{fd} : (), sort { $a <=> $b } keys %$map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 11 | ▶ | $st = $! == POSIX::ENOENT() ? 127 : 126; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 12 | ▶ | return msg($c, "$bad: Bad file descriptor", done($k, $st)) if defined $bad; # (a redirection failed: the shell's own fd 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 12 | $no->($st, $err) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 15 | ▶ | sub cmd_msg { # X47: a command that does not start: its message to the command's own fd 2 (2>log, 2>&1 | ...), as both shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_msg: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 23 | my ($c, $map, $text, $k) = @_; my @e = grep defined, values %$map; hold($_) for @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 15 | ▶ | msg({ %$c, map => $map }, $text, sub { release($_) for @e; $k->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 687 | ▶ | 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.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # write error on stdout, as coreutils: death by SIGPIPE (EPIPE, unless the shell ignores SIGPIPE for its children), else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # no more output, the message "NAME: write error: ..." at the end and status 1. Undef, as spawn for no process started. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 696 | my ($c, $map, $argv, $env, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 688 | require Proc::ShellSpawn::Programs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 688 | my $d = { %$c, map => $map }; hold($_) for values %$map; # (the caller releases its holds when spawn returns) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 687 | ▶ | $ONBUILTIN->('Proc::ShellSpawn::inproc', $argv, {%$env}) if $ONBUILTIN; # (measurement: no program runs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 687 | tr_("in-process: @$argv"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | my %opt = (cwd => $c->{sh}{cwd}, echo => $ECHO, isatty => sub { my $e = $map->{$_[0]}; $e && POSIX::isatty($e->{fd}) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=10.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 688 | ▶ | my ($out, $err, $st, $seq) = Proc::ShellSpawn::Programs->can($argv->[0] eq '[' ? 'test' : $argv->[0])->($argv, $env, \%opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 687 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 687 | ▶ | my $pipe_dfl = !$IGN0{PIPE} && ($c->{sh}{trap}{PIPE} // 1) ne ''; # (Windows: as POSIX, though it has no SIGPIPE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
!$Proc::ShellSpawn::IGN0{'PIPE'} && ($c->{'sh'}{'trap'}{'PIPE'} // 1) ne ''
$c->{"sh"}{"trap"}{"PIPE"} // 1
MC/DC0%0/2
!$Proc::ShellSpawn::IGN0{'PIPE'} && ($c->{'sh'}{'trap'}{'PIPE'} // 1) ne ''
!$Proc::ShellSpawn::IGN0{'PIPE'}
$c->{"sh"}{"trap"}{"PIPE"}
Truth table33%1/3
not(A) && B
A= !$Proc::ShellSpawn::IGN0{'PIPE'}B= $c->{"sh"}{"trap"}{"PIPE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 687 | my $werr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1313 | ▶ | loop_async(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 1313 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1313 | my $p = shift @seq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1313 | ▶ | if (!$p) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 684 | ▶ | release($_) for values %$map; return $k->($st) unless $werr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | local $! = $werr; return write_fd($d, 2, "$argv->[0]: write error" . ($werr > 0 ? ": $!" : '') . "\n", done($k, 1)) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 630 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 629 | ▶ | write_fd($d, $p->[0], $p->[1], sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 630 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 629 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | # the reason only when it failed in the final flush (close_stream: errno 0 after an earlier failure): the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # piece for stdout, short enough for one write of the buffer (glibc's: st_blksize, 4096 for a pipe) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 687 | $next->() }) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 687 | return } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 280 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # ------------------------------------------------------------------ redirections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # Applies @$redirs to a copy of $c's map: $k->(MAP, [opened ends]), or $k->() after a message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1476 | ▶ | sub redirect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redirect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 1476 | my ($c, $redirs, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1476 | my %m = %{$c->{map}}; my @opened; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1476 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1476 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1890 | ▶ | loop_async(sub { my $next = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1890 | ▶ | return $k->(\%m, \@opened) if $i > $#$redirs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 442 | my ($fd, $op, $w) = @{$redirs->[$i++]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 442 | ▶ | if ($op eq '<<') { # a here-document: Perl writes the expanded body into a pipe the command reads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # X50: expanded with the redirections so far (messages, $( )), and an error that would end the shell (set -u, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # ${x:?}, arithmetic) fails the redirection instead, as dash: the command does not run, status 2, the shell goes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # on (a special builtin's failed redirection still ends it) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | my $hc = { %$c, map => \%m, held => 0, loops => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 20 | ▶ | shell => { %{$c->{shell}}, exit => sub { release($_) for @opened; $k->() } } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 14 | ▶ | return expand_str($hc, $w, sub { my $body = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 14 | ▶ | my ($r, $wr) = new_pipe() or return $fail->("pipe: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 20 | ▶ | push @opened, $m{$fd} = $r; on_write($wr, $body, sub { release($wr) }); $next->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 422 | ▶ | 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 ">&"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 337 | ▶ | if ($w eq '-') { $m{$fd} = undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 330 | ▶ | elsif (exists $m{$w}) { defined $m{$w} ? ($m{$fd} = $m{$w}) : return $fail->("$w: Bad file descriptor") } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | elsif (visible($w)) { $m{$fd} = own_fd($w) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 3 | else { return $fail->("$w: Bad file descriptor") } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 334 | return $next->() } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 85 | ▶ | expand_str($c, $w, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 85 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 85 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 85 | ▶ | if (!$e) { # dash's wording | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 549 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 19 | ▶ | return $fail->(($op eq '<' ? 'cannot open' : 'cannot create') . " $name: $err") } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1476 | push @opened, $m{$fd} = $e; $next->() }) }) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # Runs $body->(CONTEXT, K2) with @$redirs applied, then $k->(STATUS); status 2 if they fail. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 378 | ▶ | sub with_redirs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
with_redirs: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 378 | my ($c, $redirs, $tail, $k, $body) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 378 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 31 | ▶ | redirect($c, $redirs, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 31 | ▶ | my ($m, $opened) = @_ or return defer($k, 2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 26 | my $d = derive($c, $m); release($_) for @$opened; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 31 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # ------------------------------------------------------------------ expansion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 1274 | ▶ | sub var { # also $0-$9 ${10}..., $#, $$, $@ and $* (joined by the first character of IFS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
var: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 1296 | my ($c, $n) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1274 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 13 | ▶ | $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 "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1249 | ▶ | : $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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 71 | ▶ | sub isset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isset: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 71 | my ($c, $n) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 3 | ▶ | $n =~ /^[1-9][0-9]*\z/ ? $n <= @{$sh->{args}} : $n =~ /^[@*]\z/ ? !!@{$sh->{args}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$n =~ /^[?#\$0]\z/ or defined $sh->{"vars"}{$n}
MC/DC100%2/2
$n =~ /^[?#\$0]\z/ or defined $sh->{"vars"}{$n}
$n =~ /^[?#\$0]\z/
defined $sh->{"vars"}{$n}
Truth table100%3/3
A or B
A= $n =~ /^[?#\$0]\z/B= defined $sh->{"vars"}{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 71 | ▶ | : $n eq '!' ? defined $sh->{bang} : $n =~ /^[?#\$0]\z/ || defined $sh->{vars}{$n} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 1167 | ▶ | sub getvar { # a value for $NAME, or undef after ending the shell (set -u) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getvar: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 1167 | my ($c, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1167 | ▶ | return fail($c, 2, "$n: parameter not set") if $c->{sh}{opt}{u} && $n !~ /^[@*!]\z/ && !isset($c, $n); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n)
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/
MC/DC66%2/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 table75%3/4
A and not(B) and not(C)
A= $c->{"sh"}{"opt"}{"u"}B= not $n =~ /^[\@*!]\z/C= not isset($c, $n)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1161 | var($c, $n) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 391 | ▶ | sub active { $_[0] =~ /(?:^|[^\\])(?:\\\\)*[*?\[]/ } # X52: an expansion's text has a pattern character no backslash escapes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
active: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # (else no pathname expansion: x\* stays x\*, as both shells) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 1930 | ▶ | sub glob_quote { (my $s = shift) =~ s/([\\*?\[\]{}~!^-])/\\$1/g; $s } # also ! ^ -: literal inside [...] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glob_quote: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 66 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 41 | my $p = shift; my $o = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 41 | ▶ | while ($p =~ /\G(?:(\\.)|(\[)|(.))/gcs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 149 | ▶ | if (!defined $2) { $o .= $+; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 22 | my $s = pos $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 22 | ▶ | if ($p =~ /\G([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]/gcs) { my ($n, $b) = ($1, $2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 19 | ▶ | if ("$n$b" =~ m{/}) { $o .= '\\['; pos($p) = $s } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 17 | ▶ | else { $b =~ s/\[:([a-z]+):\]/class_chars($1)/ge; $o .= ($n ? '[!' : '[') . "$b]" } } # [^...]: [!...] (rule E) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | else { $o .= '['; pos($p) = $s } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 41 | $o } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 547 | ▶ | my %CLASS = ( # X40: the classes in the C locale, as ranges [FROM, TO] and single characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne '/' && /[[:punct:]]/
MC/DC100%2/2
$_ ne '/' && /[[:punct:]]/
$_ ne '/'
/[[:punct:]]/
Truth table100%3/3
A && B
A= $_ ne '/'B= /[[:punct:]]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | alpha => [['a', 'z'], ['A', 'Z']], upper => [['A', 'Z']], lower => [['a', 'z']], digit => [['0', '9']], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | alnum => [['a', 'z'], ['A', 'Z'], ['0', '9']], xdigit => [['0', '9'], ['A', 'F'], ['a', 'f']], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | space => [" ", "\t", "\n", "\r", "\f", "\013"], blank => [" ", "\t"], cntrl => [["\x01", "\x1f"], "\x7f"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | print => [["\x20", "\x7e"]], graph => [["\x21", "\x7e"]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | punct => [grep $_ ne "/" && /[[:punct:]]/, map chr, 33 .. 126]); # (no / in a name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 31 | ▶ | sub class_chars { # X40: bsd_glob has no character classes: [:digit:] as its characters, in the C locale (as dash there; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_chars: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 5 | ▶ | my $n = shift; my $m = $CLASS{$n} or return "[:$n:]"; # in a UTF-8 locale other letters belong too, not here) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 4 | ▶ | join '', map { ref $_ ? quote_bracket($_->[0]) . '-' . quote_bracket($_->[1]) : quote_bracket($_) } @$m } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 41 | ▶ | sub quote_bracket { my $c = shift; $c =~ /[A-Za-z0-9]/ ? $c : "\\$c" } # a member of a bracket expression, for bsd_glob | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_bracket: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # A Word into fields: $k->([FIELD, ...]). $how: 'argv' splits and globs; 'str' gives one string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # A field under construction is a hash (JU1, post-0.12; before, an array by number): text, the field's text; pat, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # same as a glob pattern (quoted characters escaped); keep, true to keep the field even if it is empty (something quoted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # was in it); glob, true if it has an active glob character; gone, true when "$@" stood for no parameters (L1). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 702 | ▶ | sub fresh_field { +{ text => '', pat => '', keep => 0, glob => 0, gone => 0 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fresh_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 4400 | ▶ | sub expand { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 4371 | my ($c, $word, $how, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 4371 | ▶ | return $k->([$word]) unless ref $word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 659 | my @f; my $cur = fresh_field(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2015 | ▶ | my $add = sub { # text; $pat: its glob characters are active; $split: an unquoted expansion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=21 SCAR=30.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 2014 | my ($t, $pat, $split) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 2014 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 2014 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 373 | my ($ws, $nw) = map quotemeta, join('', $ifs =~ /[ \t\n]/g), join('', $ifs =~ /[^ \t\n]/g); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 373 | ▶ | my $d = $nw eq '' ? qr/[$ws]+/ : $ws eq '' ? qr/[$nw]/ : qr/[$ws]*[$nw][$ws]*|[$ws]+/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 373 | my @p = split /($d)/, $t, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 373 | for my $j (0 .. $#p) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 421 | ▶ | if ($j % 2) { # a delimiter: one with a non-blank IFS character ends a field even if it is empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 29 | ▶ | push @f, $cur if length $cur->{text} or $cur->{keep} or $nw ne '' && $p[$j] =~ /[$nw]/; $cur = fresh_field(); next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
length $cur->{"text"} or $cur->{"keep"} or $nw ne "" and $p[$j] =~ /[$nw]/
length $cur->{"text"} or $cur->{"keep"}
$nw ne "" and $p[$j] =~ /[$nw]/
MC/DC50%2/4
length $cur->{"text"} or $cur->{"keep"} or $nw ne "" and $p[$j] =~ /[$nw]/
length $cur->{"text"}
$cur->{"keep"}
$nw ne ""
$p[$j] =~ /[$nw]/
Truth table60%3/5
A or B or C and D
A= length $cur->{"text"}B= $cur->{"keep"}C= $nw ne ""D= $p[$j] =~ /[$nw]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 392 | ▶ | $cur->{text} .= $p[$j]; $cur->{pat} .= $p[$j]; $cur->{glob} ||= active($p[$j]) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$cur->{"glob"} ||= active($p[$j])
MC/DC100%2/2
$cur->{"glob"} ||= active($p[$j])
$cur->{"glob"}
active($p[$j])
Truth table100%3/3
A ||= B
A= $cur->{"glob"}B= active($p[$j])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 | ▶ | elsif ($split && $how eq 'argv') { $cur->{text} .= $t; $cur->{pat} .= $t; $cur->{glob} ||= active($t) } # IFS empty: no splitting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$split and $how eq "argv"
$cur->{"glob"} ||= active($t)
MC/DC100%2/2
$split and $how eq "argv"
$split
$how eq "argv"
MC/DC0%0/2
$cur->{"glob"} ||= active($t)
$cur->{"glob"}
active($t)
Truth table100%3/3
A and B
A= $splitB= $how eq "argv"
Truth table33%1/3
A ||= B
A= $cur->{"glob"}B= active($t)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1639 | ▶ | else { $cur->{text} .= $t; $cur->{pat} .= $pat ? $t : glob_quote($t); $cur->{glob} ||= $pat && $t =~ /[*?\[]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$cur->{"glob"} ||= $pat && $t =~ /[*?\[]/
$pat && $t =~ /[*?\[]/
MC/DC0%0/3
$cur->{"glob"} ||= $pat && $t =~ /[*?\[]/
$cur->{"glob"}
$pat
$t =~ /[*?\[]/
Truth table0%0/4
A ||= B && C
A= $cur->{"glob"}B= $patC= $t =~ /[*?\[]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 659 | ▶ | $cur->{keep} = 1 unless $pat } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 14 | ▶ | my $params = sub { # "$@" and "${@#p}": one field per parameter; none: the field goes, quotes or not (L1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 13 | ▶ | $cur->{gone} = 1 unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 659 | ▶ | for my $j (0 .. $#_) { if ($j) { push @f, $cur; $cur = fresh_field() } $add->($_[$j], 0) } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 659 | my @parts = @$word; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 2662 | ▶ | loop_async(sub { my $next = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=51 SCAR=40.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 2662 | ▶ | if ($i > $#parts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 636 | ▶ | push @f, $cur if length $cur->{text} or $cur->{keep} && !$cur->{gone} or $how ne 'argv'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
length $cur->{"text"} or $cur->{"keep"} and not $cur->{"gone"} or $how ne "argv"
length $cur->{"text"} or $cur->{"keep"} and not $cur->{"gone"}
$cur->{"keep"} and not $cur->{"gone"}
MC/DC75%3/4
length $cur->{"text"} or $cur->{"keep"} and not $cur->{"gone"} or $how ne "argv"
length $cur->{"text"}
$cur->{"keep"}
not $cur->{"gone"}
$how ne "argv"
Truth table66%4/6
A or B and not(C) or D
A= length $cur->{"text"}B= $cur->{"keep"}C= not $cur->{"gone"}D= $how ne "argv"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 636 | ▶ | return $k->([map $_->{text}, @f]) if $how ne 'argv'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | return $k->([map { # a pattern that matches nothing stays as it is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 588 | my ($t, $p, $g) = @$_{qw(text pat glob)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 617 | ▶ | 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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 617 | ▶ | my @m = $g && !$c->{sh}{opt}{f} ? sort { $a cmp $b } grep !m{(?:^|/)\.\.?\z}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | File::Glob::bsd_glob($base . slash_brackets($p), File::Glob::GLOB_QUOTE()) : (); # never . or .. (rule E, as bash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 617 | ▶ | s{^\Q$c->{sh}{cwd}\E/}{} for $base ? @m : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 617 | ▶ | @m ? @m : $t } @f]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 2026 | my $x = $parts[$i++]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2026 | ▶ | return $add->($x, 0), $next->() unless ref $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 1331 | my ($kind, @a) = @$x; (my $q = $kind) =~ s/^"//; my $split = $kind !~ /^"/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 1331 | ▶ | if ($kind eq '*') { $add->($a[0], 1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | elsif ($kind eq '~') { $add->($a[0] ne '' ? ($WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]" # ~ without HOME: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # from the password | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | : exists $c->{sh}{vars}{HOME} ? var($c, 'HOME') # file (G16); Windows: no user database, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 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])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 12 | ▶ | elsif ($kind eq '"$' && $a[0] eq '@' && $how eq 'argv') { $params->(@{$c->{sh}{args}}) } # "$@" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 1118 | ▶ | 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])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 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])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | elsif ($q eq '${') { # the word is expanded only if it is used, as in sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 59 | my ($n, $op, $w) = @a; my $v = var($c, $n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 59 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 59 | ▶ | if ($op =~ /^[%#]/) { # remove the smallest or largest matching suffix or prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 28 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 50 | ▶ | return pattern_re($c, $w, sub { my $re = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 42 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 55 | ▶ | for my $i (@i) { my ($cut, $keep) = $op =~ /%/ ? (substr($v, $i), substr($v, 0, $i)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | : (substr($v, 0, $i), substr($v, $i)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 143 | ▶ | return $keep if $cut =~ $re } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 35 | $v }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 35 | ▶ | 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 "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 12 | my @t = map $trim->($_), @{$c->{sh}{args}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 33 | ▶ | if ($kind eq '"${' && $n eq '@' && $how eq 'argv') { $params->(@t) } # "${@#p}": 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 4 | else { $add->(join(ifs1($c), @t), 0, $split) } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 24 | else { $add->($trim->($v), 0, $split) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 27 | $next->() }) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 31 | ▶ | my $word = $op =~ /[-=?]/ ? !$set : $set; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 31 | ▶ | unless ($word) { $add->($op =~ /[-=?]/ ? $v : '', 0, $split); return $next->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 40 | ▶ | return expand($c, $w, 'str', sub { my $t = $_[0][0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 27 | ▶ | return fail($c, 2, "$n: " . ($t ne '' ? $t : $op =~ /:/ ? 'parameter not set or null' : 'parameter not set')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | if $op =~ /\?/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 13 | ▶ | if ($op =~ /=/) { setvar($c, $n, $t) or return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 27 | ▶ | $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 =~ /[=?]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 8 | ▶ | return $add->($p, 0, 1), $more->() unless ref $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 2 | ▶ | return $add->($p->[1], 0), $more->() if $p->[0] eq "'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | elsif ($kind eq "'") { $add->($a[0], 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | elsif ($kind eq 'ext') { return handler($a[0])->($c, $x, sub { $add->(shift, 0, $split); $next->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 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=15.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 66 | ▶ | elsif ($q eq '$((') { my $v = arith($c, $a[0]); return unless defined $v; $add->($v, 0, $split) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 84 | ▶ | elsif ($q eq '$(') { return subst($c, $a[0], sub { $add->(shift, 0, $split); $next->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 48 | ▶ | 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 "{.."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 48 | else { die "Proc::ShellSpawn: unknown part '$kind'" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 659 | $next->() }) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 6309 | ▶ | sub loop_async { # JH1 (post-0.12, X60): $body->(NEXT) again each time it calls NEXT; it stops by not calling it. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop_async: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 6309 | my $body = shift; # NEXT called at once continues a plain loop (no recursion, however many steps finish at once); a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 7022 | ▶ | sub { my $resume = __SUB__; # NEXT called later (a program, a $( ) to wait for) resumes it from the event loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 7022 | while (1) { my ($now, $again) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 14484 | ▶ | $body->(sub { $now ? ($again = 1) : $resume->() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 6309 | ▶ | $now = 0; $again or return } }->(); return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1499 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1499 | my ($items, $body, $done) = @_; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1499 | ▶ | loop_async(sub { my $next = shift; return $done->() if $i > $#$items; $body->($items->[$i++], $next) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 873 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1483 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1483 | my ($c, $ws, $how, $k) = @_; my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1483 | ▶ | each_async($ws, sub { my ($w, $next) = @_; expand($c, $w, $how, sub { push @out, @{$_[0]}; $next->() }) }, sub { $k->(\@out) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 43 | ▶ | sub subst { # $( list ): $k->(OUTPUT without trailing newlines) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subst: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 36 | my ($c, $list, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | my ($r, $w) = new_pipe() or return msg($c, "pipe: $!", sub { $k->('') }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 36 | my ($out, $st, $eof) = (''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 36 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 36 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 1044 | ▶ | on_read($r, 65536, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 1044 | ▶ | return $eof = 1, release($r), $done->() unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 36 | $out .= $_[0]; on_read($r, 65536, __SUB__) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 36 | x_list($d, $list, [$d], $d->{shell}{exit}) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # $(( )): sh's integer arithmetic. undef (after a message, and leaving the shell) on error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 41 | ▶ | sub arith { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arith: called CC=8 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 41 | my ($c, $e) = @_; my $src = $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 41 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 41 | ▶ | return if $unset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 41 | my @t = $e =~ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | /\G\s*(0[xX][0-9a-fA-F]+|[0-9]+|[A-Za-z_][A-Za-z_0-9]*|<<=|>>=|<<|>>|<=|>=|==|!=|&&|\|\||[-+*\/%&^|]=|[-+*\/%<>&^|!~?:()=])/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 41 | ▶ | my $err = sub { fail($c, 2, "arithmetic expression: $_[0]: \"$src\""); undef }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 41 | ▶ | return $err->('syntax error') if $e !~ /\G\s*\z/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # JU4 (post-0.12): the two parsers are named functions over these variables, set with local for this call, as test's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | # parser is written (before: two closures calling each other, kept from a cycle by weak references, E21). Each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | # thread has its own interpreter, so its own copies of them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 41 | local our ($AC, @AT, $AP, $ABAD, $ADEAD, $ASKIP) = ($c, @t); $AP = 0; $ASKIP = 0; # $ASKIP: inside the side of && || ?: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 41 | ▶ | my $v = arith_expr(0); $ABAD //= 'syntax error' if $AP <= $#AT; # that is not taken | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$Proc::ShellSpawn::ABAD //= "syntax error"
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "syntax error"
$Proc::ShellSpawn::ABAD
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 41 | ▶ | return if $ADEAD; # a readonly variable: the shell is already ending | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 40 | ▶ | defined $ABAD ? $err->($ABAD) : $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 549 | ▶ | { use integer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 547 | my %bin = ('*' => 9, '/' => 9, '%' => 9, '+' => 8, '-' => 8, '<<' => 7, '>>' => 7, '<' => 6, '<=' => 6, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | '>' => 6, '>=' => 6, '==' => 5, '!=' => 5, '&' => 4, '^' => 3, '|' => 2, '&&' => 1, '||' => 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 547 | our ($AC, @AT, $AP, $ABAD, $ADEAD, $ASKIP); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 92 | ▶ | sub arith_unary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arith_unary: called CC=22 SCAR=36.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 92 | ▶ | my $x = $AT[$AP++] // return +($ABAD //= 'syntax error') && 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // (return ($Proc::ShellSpawn::ABAD //= "syntax error") && 0)
($Proc::ShellSpawn::ABAD //= 'syntax error') && 0
$Proc::ShellSpawn::ABAD //= "syntax error"
MC/DC100%1/1
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // (return ($Proc::ShellSpawn::ABAD //= "syntax error") && 0)
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++]
MC/DC0%0/1
($Proc::ShellSpawn::ABAD //= 'syntax error') && 0
($Proc::ShellSpawn::ABAD //= 'syntax error')
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "syntax error"
$Proc::ShellSpawn::ABAD
Truth table100%2/2
A
A= $Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++]
Truth table50%1/2
A
A= ($Proc::ShellSpawn::ABAD //= 'syntax error')
Truth table50%1/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 91 | ▶ | return -arith_unary() if $x eq '-'; return +arith_unary() if $x eq '+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 86 | ▶ | return !arith_unary() ? 1 : 0 if $x eq '!'; return ~arith_unary() if $x eq '~'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 86 | ▶ | if ($x eq '(') { my $v = arith_expr(0); ($AT[$AP++] // '') eq ')' or $ABAD //= 'syntax error'; return $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition25%1/4
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // ""
$Proc::ShellSpawn::ABAD //= "syntax error"
MC/DC0%0/1
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // ""
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++]
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "syntax error"
$Proc::ShellSpawn::ABAD
Truth table50%1/2
A
A= $Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++]
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 557 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 8 | ▶ | if ($x =~ /^[A-Za-z_]/) { my $v = var($AC, $x); $v = 0 if $v =~ /^\s*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 15 | ▶ | unless ($v =~ /^\s*[-+]?[0-9]+\s*\z/) { $ABAD //= "$x: not a number" unless $ASKIP; return 0 } # (X42: no Perl warning) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$Proc::ShellSpawn::ABAD //= "${x}: not a number"
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "${x}: not a number"
$Proc::ShellSpawn::ABAD
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 22 | return $v + 0 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 14 | ▶ | $ABAD //= 'syntax error'; 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$Proc::ShellSpawn::ABAD //= "syntax error"
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "syntax error"
$Proc::ShellSpawn::ABAD
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 92 | ▶ | sub arith_expr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arith_expr: called CC=40 SCAR=39.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 106 | my $min = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 106 | ▶ | if (!$min && ($AT[$AP] // '') =~ /^[A-Za-z_]/ && ($AT[$AP + 1] // '') =~ /^(?:<<|>>|[-+*\/%&^|])?=\z/) { # NAME op= EXPR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%8/10
not $min and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP] // "") =~ /^[A-Za-z_]/ and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]
not $min and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP] // "") =~ /^[A-Za-z_]/
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP] // ""
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP + 1] // ""
MC/DC33%1/3
not $min and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP] // "") =~ /^[A-Za-z_]/ and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]
not $min
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP]
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP + 1]
Truth table50%2/4
not(A) and B and C
A= not $minB= $Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP]C= $Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP + 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # right to left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 12 | my ($n, $op) = @AT[$AP, $AP + 1]; $AP += 2; my $r = arith_expr(0); $op =~ s/=\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 19 | ▶ | my $o = var($AC, $n); $o = 0 if $o =~ /^\s*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 12 | ▶ | ($op =~ m{^[/%]\z} && !$r) ? ($ABAD //= 'division by zero') : $op ne '' and $r = eval "\$o $op \$r"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition20%1/5
$op =~ m[^[/%]\z] and not $r
$Proc::ShellSpawn::ABAD //= "division by zero"
MC/DC0%0/2
$op =~ m[^[/%]\z] and not $r
$op =~ m[^[/%]\z]
not $r
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "division by zero"
$Proc::ShellSpawn::ABAD
Truth table33%1/3
A and not(B)
A= $op =~ m[^[/%]\z]B= not $r
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 12 | ▶ | $ASKIP or $ADEAD or setvar($AC, $n, $r) or $ADEAD = 1; return $r } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$Proc::ShellSpawn::ASKIP or $Proc::ShellSpawn::ADEAD or setvar($Proc::ShellSpawn::AC, $n, $r)
$Proc::ShellSpawn::ASKIP or $Proc::ShellSpawn::ADEAD
MC/DC33%1/3
$Proc::ShellSpawn::ASKIP or $Proc::ShellSpawn::ADEAD or setvar($Proc::ShellSpawn::AC, $n, $r)
$Proc::ShellSpawn::ASKIP
$Proc::ShellSpawn::ADEAD
setvar($Proc::ShellSpawn::AC, $n, $r)
Truth table50%2/4
A or B or C
A= $Proc::ShellSpawn::ASKIPB= $Proc::ShellSpawn::ADEADC= setvar($Proc::ShellSpawn::AC, $n, $r)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 102 | my $l = arith_unary(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 102 | ▶ | while (defined(my $op = $AT[$AP])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 57 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 8 | ▶ | $AP++; my $a = do { local $ASKIP = $ASKIP || !$l; arith_expr(0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$Proc::ShellSpawn::ASKIP || !$l
MC/DC0%0/2
$Proc::ShellSpawn::ASKIP || !$l
$Proc::ShellSpawn::ASKIP
!$l
Truth table33%1/3
A || not(B)
A= $Proc::ShellSpawn::ASKIPB= !$l
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 8 | ▶ | ($AT[$AP++] // '') eq ':' or $ABAD //= 'syntax error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // ""
$Proc::ShellSpawn::ABAD //= "syntax error"
MC/DC0%0/1
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // ""
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++]
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "syntax error"
$Proc::ShellSpawn::ABAD
Truth table50%1/2
A
A= $Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++]
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 8 | ▶ | my $b = do { local $ASKIP = $ASKIP || $l; arith_expr(0) }; $l = $l ? $a : $b; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Proc::ShellSpawn::ASKIP || $l
MC/DC0%0/2
$Proc::ShellSpawn::ASKIP || $l
$Proc::ShellSpawn::ASKIP
$l
Truth table33%1/3
A || B
A= $Proc::ShellSpawn::ASKIPB= $l
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 56 | ▶ | my $pr = $bin{$op}; last unless defined $pr && $pr >= $min; $AP++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 50 | ▶ | my $r = do { local $ASKIP = $ASKIP || ($op eq '&&' ? !$l : $op eq '||' ? $l : 0); arith_expr($pr + 1) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$Proc::ShellSpawn::ASKIP || ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
MC/DC100%2/2
$Proc::ShellSpawn::ASKIP || ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
$Proc::ShellSpawn::ASKIP
($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
Truth table100%3/3
A || B
A= $Proc::ShellSpawn::ASKIPB= ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 50 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 19 | ▶ | elsif ($op =~ m{^[/%]\z} && !$r) { $ABAD //= 'division by zero' unless $ASKIP; $l = 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$op =~ m[^[/%]\z] and not $r
$Proc::ShellSpawn::ABAD //= "division by zero"
MC/DC100%2/2
$op =~ m[^[/%]\z] and not $r
$op =~ m[^[/%]\z]
not $r
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "division by zero"
$Proc::ShellSpawn::ABAD
Truth table100%3/3
A and not(B)
A= $op =~ m[^[/%]\z]B= not $r
Truth table50%1/2
A
A= $Proc::ShellSpawn::ABAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 34 | ▶ | else { $l = eval "\$l $op \$r" ; $l = $l ? 1 : 0 if $op =~ /^[<>=!]=?\z|^[<>]\z/ } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 94 | $l } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | # ------------------------------------------------------------------ the tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | # x_*($c, NODE, $tail, $k): run NODE in context $c, then $k->(STATUS). $tail: the contexts to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | # release as soon as the last process NODE can start has started (undef: something may follow). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1023 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 881 | ▶ | sub x_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 889 | my ($c, $l, $tail, $k) = @_; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 2469 | ▶ | sub { my $st = shift; my $p = $c->{sh}{pend}; my $me = __SUB__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 8 | ▶ | return Proc::ShellSpawn::Large::run_pending($c, sub { $c->{sh}{q} = $st; $me->($st) }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 2461 | ▶ | if !$c->{intrap} && ($p && @$p || $c->{sh}{tbusy}); # X19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"}
$p and @$p or $c->{"sh"}{"tbusy"}
$p and @$p
MC/DC75%3/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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 2453 | ▶ | return defer($k, $st) if $i > $#$l; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 889 | ▶ | x_andor($c, $l->[$i++], $i > $#$l ? $tail : undef, $me) }->(0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 1698 | ▶ | sub x_andor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_andor: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 1698 | my ($c, $ao, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 1698 | ▶ | return x_bg($c, [@$ao[0 .. $#$ao - 1]], $k) if $ao->[-1] eq '&'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 1668 | my ($i, $ran) = (0, -1); my $cc = cond($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 3309 | ▶ | sub { my $st = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 3309 | ▶ | $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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 3309 | ▶ | if ($i > $#$ao) { # set -e: the last pipeline failed, not negated, not in a condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 1568 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 1562 | return defer($k, $st) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 1741 | my $p = $ao->[$ran = $i]; $i += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1668 | ▶ | x_pipeline($i > $#$ao ? $c : $cc, $p, $i > $#$ao ? $tail : undef, __SUB__) }->(0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 1732 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 30 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 30 | my ($c, $ao, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 30 | ▶ | my $null = open_end($c, '/dev/null', '<') or return msg($c, "/dev/null: $!", done($k, 2)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 38 | my $job = { pids => [] }; $JOBS{$job} = $job; push @{$c->{sh}{jobl}}, $job; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 30 | $job->{id} = ++$c->{sh}{jobs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 30 | ▶ | my $d = derive($c, { %{$c->{map}}, 0 => $null }, shell => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 20 | tr_("background job $job->{id}: done, status $_[0]"); delete $JOBS{$job}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 30 | release($null); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 30 | $d->{sh}{job} = $job; # shared by the job's shells: its first process becomes $! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 30 | x_andor($d, $ao, [$d], $d->{shell}{exit}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 30 | $c->{sh}{bang} = $job; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 30 | $c->{sh}{q} = 0; defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 1741 | ▶ | sub x_pipeline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_pipeline: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 1741 | my ($c, $p, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 1741 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 1741 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 1741 | ▶ | return x_cmd($c, $cmd[0], $tail, $kk) if @cmd == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 102 | my (@ends, @d, @st); my $left = @cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | 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.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 102 | for my $j (0 .. $#cmd) { # each element: a shell of its own, fds 0 and 1 on the pipes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 208 | my %m = %{$c->{map}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 208 | ▶ | $m{0} = $ends[$j - 1][0] if $j; $m{1} = $ends[$j][1] if $j < $#cmd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 208 | ▶ | my $done = sub { $st[$j] = shift; defer($kk, $st[-1]) unless --$left }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 208 | $d[$j] = derive($c, \%m, jobs => 1, shell => $done) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 102 | release($_) for map @$_, @ends; # the creator's holds: only the elements' remain | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 102 | x_cmd($d[$_], $cmd[$_], [$d[$_]], $d[$_]{shell}{exit}) for 0 .. $#cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 102 | after_start($tail) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 1881 | ▶ | sub x_cmd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_cmd: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 1881 | my ($c, $x, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 1881 | ▶ | $c->{sh}{vars}{LINENO} = $x->{line} if $x->{line}; # G8 (rule E, as bash): the line where the command starts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 1881 | ▶ | return x_simple($c, $x, $tail, $k) if $x->{argv}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 425 | ▶ | return with_redirs($c, $x->{redir}, undef, $k, sub { x_cd($_[0], $x, $_[2]) }) if exists $x->{cd}; # cd with redirections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # (post4-0.03) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 361 | ▶ | return with_redirs($c, $x->{redir}, undef, $k, sub { x_set($_[0], $x, $_[2]) }) if $x->{set}; # (D2: as dash, redirect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # first; failed: no setting, status 2; the values are expanded with the redirections in force; JH2, post-0.12) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 230 | ▶ | return handler('Proc::ShellSpawn::Large::x_rest')->($c, $x, $tail, $k) if exists $x->{rest}; # P1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 228 | ▶ | 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)))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 180 | ▶ | with_redirs($c, $x->{redir}, $tail, $k, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 180 | my ($c, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 180 | ▶ | if (my $l = $x->{group}) { return x_list($c, $l, $tail, $k) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 108 | ▶ | if (my $l = $x->{sub}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 40 | my $d = derive($c, { %{$c->{map}} }, shell => $k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 40 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 68 | ▶ | return x_if($c, $x->{if}, $tail, $k) if $x->{if}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 60 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 46 | ▶ | return x_for($c, $x, $k) if exists $x->{for}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 19 | ▶ | return x_case($c, $x, $tail, $k) if exists $x->{case}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | die "Proc::ShellSpawn: unknown command node" }) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 8 | ▶ | sub x_if { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_if: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 8 | my ($c, $arms, $tail, $k) = @_; my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 13 | ▶ | loop_async(sub { my $next = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 13 | ▶ | return defer($k, 0) if $i > $#$arms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 9 | ▶ | return x_list($c, $arms->[$i], $tail, $k) if $i == $#$arms; # else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 9 | my $then = $arms->[$i + 1]; $i += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 8 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 40 | ▶ | sub loop { # runs $iter->(CONTEXT, NEXT, END) per iteration, with break and continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 40 | my ($c, $k, $iter) = @_; my $st = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 40 | my $rec = { scope => [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 40 | my $lc = { %$c, loops => [@{$c->{loops}}, $rec] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 40 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 40 | ▶ | $rec->{brk} = sub { $end->(0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 109 | ▶ | sub { my $next = __SUB__; release_all($rec->{scope}); $rec->{scope} = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 40 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 14 | ▶ | sub x_while { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_while: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 14 | my ($c, $x, $k) = @_; my $until = exists $x->{until}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 43 | ▶ | loop($c, $k, sub { my ($c, $next, $end) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 43 | ▶ | x_list(cond($c), $x->{while} // $x->{until}, undef, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 14 | ▶ | ($_[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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 27 | ▶ | sub x_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_for: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 27 | my ($c, $x, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 26 | ▶ | expand_list($c, $x->{in} // [[['"$', '@']]], 'argv', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 26 | my @w = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 66 | ▶ | loop($c, $k, sub { my ($c, $next, $end) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 66 | ▶ | return $end->() unless @w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 19 | ▶ | sub x_case { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_case: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 19 | my ($c, $x, $tail, $k) = @_; my @in = @{$x->{in}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 18 | ▶ | expand_str($c, $x->{case}, sub { my $s = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 20 | ▶ | loop_async(sub { my $next = shift; return defer($k, 0) unless @in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 19 | my ($pats, $l) = splice @in, 0, 2; my @p = @$pats; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 320 | ▶ | loop_async(sub { my $again = shift; return $next->() unless @p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 19 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 345 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 345 | my ($c, $w, $k) = @_; # pattern is put together first, quoted text escaped, so that a bracket expression may span Parts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 345 | ▶ | my @parts = ref $w ? @$w : ($w); my $g = ''; my $i = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 708 | ▶ | loop_async(sub { my $next = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 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
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | if $i > $#parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 363 | my $x = $parts[$i++]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 363 | ▶ | return $g .= glob_quote($x), $next->() unless ref $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 44 | ▶ | if ($x->[0] eq '*') { $g .= $x->[1]; return $next->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 345 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 353 | ▶ | sub glob_re { # a glob pattern (quoted characters escaped with '\') as a regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glob_re: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 345 | my $g = shift; my $re = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 345 | ▶ | while ($g =~ /\G(?:(\*)|(\?)|\[([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]|\\(.)|(.))/gcs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 1465 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 345 | $re } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 13 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 13 | my ($neg, $b) = @_; my $o = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 13 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 13 | ▶ | '[' . ($neg ? '^' : '') . $o . ']' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 714 | ▶ | sub setvar { # 1, or 0 after ending the shell (a readonly variable, as dash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setvar: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 714 | my ($c, $n, $v) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 714 | ▶ | return do { fail($c, 2, "$n: is read only"); 0 } if $sh->{ro}{$n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 720 | ▶ | $sh->{exp}{$n} = 1 if $sh->{opt}{a}; $sh->{vars}{$n} = $v; 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 129 | ▶ | sub x_set { # NAME=value ... alone (with redirections: through with_redirs, in x_cmd; rule E: category effect) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_set: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 137 | my ($c, $x, $k) = @_; my @s = @{$x->{set}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 137 | delete $c->{sh}{qsub}; my %log; # the settings as made, for $ONBUILTIN (measurement) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 565 | ▶ | loop_async(sub { my $next = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 565 | ▶ | unless (@s) { $ONBUILTIN->('x_set', [], {%log}) if $ONBUILTIN; return defer($k, $c->{sh}{qsub} // 0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 430 | my ($n, $w) = splice @s, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 129 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 64 | ▶ | sub x_cd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_cd: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 64 | my ($c, $x, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 63 | ▶ | my $go = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=31 SCAR=35.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 71 | ▶ | my @f = @_; $ONBUILTIN->('x_cd', ['cd', ($x->{cd_p} ? '-P' : ()), @f], {}) if $ONBUILTIN; # (measurement) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 71 | ▶ | my $d = @f ? $f[0] : var($c, 'HOME'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 71 | ▶ | 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 '-'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 71 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 71 | ▶ | return msg($c, "cd: too many arguments", done($k, 1)) if $x->{cd_extra} || @f > 1; # as bash (rule E), also when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$x->{"cd_extra"} or @f > 1
MC/DC100%2/2
$x->{"cd_extra"} or @f > 1
$x->{"cd_extra"}
@f > 1
Truth table100%3/3
A or B
A= $x->{"cd_extra"}B= @f > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # an expansion gives the extra fields at run time (X54) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 59 | ▶ | return msg($c, "cd: HOME not set", done($k, 1)) if !@f && !isset($c, 'HOME'); # as bash (rule E; N4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@f or isset($c, "HOME")
MC/DC100%2/2
@f or isset($c, "HOME")
@f
isset($c, "HOME")
Truth table100%3/3
A or B
A= @fB= isset($c, "HOME")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 66 | ▶ | return defer($k, 0) if !@f && $d eq ''; # HOME empty: nothing, as both shells (X45) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @f and $d eq ""
MC/DC100%2/2
not @f and $d eq ""
not @f
$d eq ""
Truth table100%3/3
not(A) and B
A= not @fB= $d eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 57 | ▶ | if ($d =~ /^-/ && !$dash) { return msg($c, "cd: bad argument", done($k, 2)) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$d =~ /^-/ and not $dash
MC/DC50%1/2
$d =~ /^-/ and not $dash
$d =~ /^-/
not $dash
Truth table66%2/3
A and not(B)
A= $d =~ /^-/B= not $dash
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 64 | my $new = path_in($c, $d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 56 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | else { # (Windows: the drive or the //server/share stays in front) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 53 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 53 | ▶ | 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 "."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 61 | $new = $pre . '/' . join '/', @p } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 64 | ▶ | $new && -d $new && ($WIN || -x _) or return msg($c, "cd: can't cd to $d", done($k, 2)); # X44: and searchable, as both shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$new and -d $new and $Proc::ShellSpawn::WIN || -x _
$new and -d $new
$Proc::ShellSpawn::WIN or -x _
MC/DC75%3/4
$new and -d $new and $Proc::ShellSpawn::WIN || -x _
$new
-d $new
$Proc::ShellSpawn::WIN
-x _
Truth table80%4/5
A and B and C or D
A= $newB= -d $newC= $Proc::ShellSpawn::WIND= -x _
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 57 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 64 | ▶ | $dash ? put($c, 1, "$new\n", done($k, 0)) : defer($k, 0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 64 | ▶ | defined $x->{cd} ? expand($c, $x->{cd}, 'argv', sub { $go->(@{$_[0]}) }) : $go->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 1456 | ▶ | sub x_simple { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_simple: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 1456 | my ($c, $x, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 1456 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 1456 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 1456 | delete $c->{sh}{qsub}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 1456 | ▶ | my $settings = sub { # NAME=value before the command, left to right, each seeing the ones before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 1456 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 1777 | ▶ | loop_async(sub { my $again = shift; return $next->() unless @env; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 321 | my ($n, $w) = splice @env, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 321 | my $v = { %$c, sh => { %{$c->{sh}}, vars => { %{$c->{sh}{vars}}, %env } } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 321 | ▶ | expand_str($v, $w, sub { $env{$n} = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 1456 | ▶ | $c->{sh}{qsub} = $v->{sh}{qsub} if exists $v->{sh}{qsub}; $again->() }) }) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 1463 | ▶ | $settings->(sub { expand_list($c, $x->{argv}, 'argv', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 1443 | my @argv = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 1450 | ▶ | redirect($c, $x->{redir} // [], sub { # (JH2: one call; every word expanded to nothing, the redirections are still done) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 1443 | my ($m, $opened) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 1443 | ▶ | if (!$m) { return @argv && $SPECIAL{$argv[0]} ? leave($c, 2) : defer($k, 2) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@argv and $Proc::ShellSpawn::SPECIAL{$argv[0]}
MC/DC100%2/2
@argv and $Proc::ShellSpawn::SPECIAL{$argv[0]}
@argv
$Proc::ShellSpawn::SPECIAL{$argv[0]}
Truth table100%3/3
A and B
A= @argvB= $Proc::ShellSpawn::SPECIAL{$argv[0]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 1420 | ▶ | unless (@argv) { release($_) for @$opened; return defer($k, $c->{sh}{qsub} // 0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 1416 | ▶ | if (my $e = $c->{sh}{cmd}{$argv[0]} // ($x->{fn} ? ['Proc::ShellSpawn::Large::b_late'] : cmd_of($argv[0]))) { # a function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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]))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | # or a builtin, in this process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 502 | my $d = derive($c, $m); release($_) for @$opened; # a context holds its fds until it is done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 502 | ▶ | $ONBUILTIN->($e->[0], \@argv, {%env}) if $ONBUILTIN; # (measurement: doc/large-subset/tools/large-subset-builtins.pl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 502 | ▶ | if ($SPECIAL{$argv[0]}) { setvar($c, $_, $env{$_}) or return for sort keys %env; %env = () } # these settings stay | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 502 | ▶ | return handler($e->[0])->($d, \@argv, \%env, sub { release_ctx($d); $k->(@_) }, $e->[1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 914 | ▶ | @argv = printf_zero(@argv) if $argv[0] eq 'printf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 914 | my $node = spawn($c, $m, \@argv, \%env, $k); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 914 | ▶ | $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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 1456 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 40 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 33 | my @a = @_; # flag is undefined for them in C and POSIX); the program printf (coreutils) refuses it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | # (decision Z0, 2026-11-05) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 33 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 33 | ▶ | 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] =~ /^-/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 33 | $a[$i] =~ s{%(%|([-+ #0']*)(\*|[0-9]*)((?:\.(?:\*|[0-9]*))?)([a-zA-Z]))}{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 24 | my ($all, $fl, $w, $p, $cv) = ($1, $2, $3, $4, $5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 33 | @a } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 63 | ▶ | sub ok_num { # NV1 (the user, 2026-11-10; X42): an operand of exit, return, break, continue known only at run time is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ok_num: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # number as dash takes it: digits, maybe after +, at most 2^31-1, at least $min; else an error, status 2, as the shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 42 | ▶ | my ($v, $min) = @_; defined $v && $v =~ /^\+?[0-9]+\z/ && $v <= 2147483647 && $v >= $min } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $v and $v =~ /^\+?[0-9]+\z/ and $v <= 2147483647
defined $v and $v =~ /^\+?[0-9]+\z/
MC/DC33%1/3
defined $v and $v =~ /^\+?[0-9]+\z/ and $v <= 2147483647
defined $v
$v =~ /^\+?[0-9]+\z/
$v <= 2147483647
Truth table50%2/4
A and B and C
A= defined $vB= $v =~ /^\+?[0-9]+\z/C= $v <= 2147483647
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 13 | ▶ | sub b_colon { my ($c, $argv, $env, $k) = @_; defer($k, 0) } # : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_colon: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 18 | ▶ | sub b_exit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_exit: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 17 | my ($c, $argv, $env, $k) = @_; my (undef, @a) = @$argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 17 | ▶ | return leave($c, $c->{sh}{q}) unless @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 17 | ▶ | return fail($c, 2, "exit: Illegal number: $a[0]") unless ok_num($a[0], 0); # NV1 (X42): known only at run time, as the shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 16 | leave($c, $a[0] % 256) } # exit 1000: 232, as both shells (parser item P4) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 17 | ▶ | sub b_break { # break and continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_break: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 16 | my ($c, $argv, $env, $k) = @_; my ($n, @a) = @$argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 16 | ▶ | my $l = $c->{loops}; my $j = @a ? $a[0] : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 16 | ▶ | return fail($c, 2, "$n: Illegal number: $j") unless ok_num($j, 1); # NV1: 0, -1, x1 (bash goes on after 0: dash's way) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 16 | $j += 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 10 | release_all(map $_->{scope}, @$l[$#$l - $j + 1 .. $#$l]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 10 | ▶ | defer($l->[-$j]{$n eq 'break' ? 'brk' : 'cont'}) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 51 | ▶ | sub b_read { my ($c, $argv, $env, $k) = @_; my (undef, @a) = @$argv; read_line($c, $c->{map}, $env, \@a, $k) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | # read [-r] [-p PROMPT] NAME...: one line from fd 0, one byte at a time (later commands get the rest), split | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | # as sh does: IFS blanks around fields are dropped, one other IFS character ends a field, the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | # NAME gets the rest of the line; without -r a backslash protects the next character, and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | # backslash before the newline continues the line. Status 1 at end of file. The prompt of -p goes to fd 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | # and only when fd 0 is a terminal, as in both shells (P6). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 52 | ▶ | sub read_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_line: called CC=23 SCAR=31.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 58 | my ($c, $m, $env, $names, $k) = @_; my @a = @$names; my ($raw, $prompt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 51 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | # names may come from expansions (post-0.04): checked here, with dash's messages and status 2 (A5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 51 | ▶ | return msg($c, "read: arg count", done($k, 2)) unless @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 58 | ▶ | for (@a) { return msg($c, "read: $_: bad variable name", done($k, 2)) unless /^[A-Za-z_][A-Za-z0-9_]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 75 | ▶ | return handler("Proc::ShellSpawn::Large::unsupported")->($c, "the name '$_' in 'read'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | unless Proc::ShellSubset::settable($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 75 | ▶ | return msg($c, "read: $_: is read only", done($k, 2)) if $c->{sh}{ro}{$_} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 56 | ▶ | my $e = $m->{0} or return defer($k, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 55 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | # JC1 (post-0.12): the line is split by regular expressions (before: a character array walked by an index). $ws: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | # IFS blanks, $nws: the other IFS characters, both for a bracket expression (without -r never a backslash: none is left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | # unprotected), and either may be empty, so each expression is built for the case (a class that cannot match, under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | # '*+', makes Perl 5.38 panic); a unit: one character, or (without -r) a backslash with the character it protects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 55 | ▶ | my ($ws, $nws) = map { join '', map quotemeta, grep $raw || $_ ne '\\', @$_ } [$ifs =~ /[ \t\n]/g], [$ifs =~ /[^ \t\n]/g]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$raw || $_ ne '\\'
MC/DC0%0/2
$raw || $_ ne '\\'
$raw
$_ ne '\\'
Truth table66%2/3
A || B
A= $rawB= $_ ne '\\'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 55 | ▶ | my $W = length $ws ? qr/[$ws]*+/ : qr//; # IFS blanks, as many as there are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 55 | ▶ | my $sep = length $nws ? qr/$W(?:[$nws]$W)?/ : $W; # after a field: blanks, at most one other IFS character, blanks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 55 | ▶ | my $end = length $nws ? qr/$W(?:[$nws]$W)?\z/ : qr/$W\z/; # after the only field left: blanks, at most one such character, blanks (X61) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 55 | ▶ | my $unit = $raw ? qr/./s : qr/\\.|[^\\]/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 55 | ▶ | my $field = length "$ws$nws" ? qr/(?:(?![$ws$nws])$unit)*+/ : qr/(?:$unit)*+/; # units up to an unprotected IFS character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 55 | ▶ | my $val = sub { my $s = shift; $raw ? $s : $s =~ s/\\(.)/$1/gsr }; # a field's text: the protecting backslashes go | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 55 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 49 | ▶ | my $got = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 55 | my $eof = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 55 | ▶ | $line =~ s/(?<!\\)((?:\\\\)*)\\\z/$1/ unless $raw; # a lone backslash at the end of the input goes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 55 | $line =~ s/^$W//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 55 | for my $name (@a[0 .. $#a - 1]) { $line =~ s/^($field)$sep//; setvar($c, $name, $val->($1)) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | # the last name: the rest without its final blanks; a single trailing delimiter after the only field is dropped, as in dash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 48 | ▶ | $line =~ /^($field)$end/ or $line =~ /^((?:$unit)*?)$W\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 55 | setvar($c, $a[-1], $val->($1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 55 | ▶ | defer($k, $eof ? 1 : 0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 49 | ▶ | my $go = sub { on_read($e, 1, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 787 | my $b = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 787 | ▶ | return $got->(1) unless defined $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 779 | ▶ | if ($b eq "\n") { # continued if the line ends in an odd number of backslashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 42 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 2 | chop $line; return on_read($e, 1, __SUB__) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 55 | $line .= $b; on_read($e, 1, __SUB__) }) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 55 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | # ------------------------------------------------------------------ entry points | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 545 | ▶ | sub start_pwd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_pwd: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 546 | my $phys = Cwd::getcwd(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 546 | my $p = $ENV{PWD}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 546 | ▶ | return $p if defined $p && is_abs($p) && files_eq($p, '.'); # PWD from the environment, if it names where we are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $p and is_abs($p) and files_eq($p, ".")
defined $p and is_abs($p)
MC/DC33%1/3
defined $p and is_abs($p) and files_eq($p, ".")
defined $p
is_abs($p)
files_eq($p, ".")
Truth table50%2/4
A and B and C
A= defined $pB= is_abs($p)C= files_eq($p, ".")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 4 | $phys } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | # run(STRING or TREE, parser => CODE, interactive => 'nop' or 'dash', args => [$1 ...], arg0 => $0, opt => {e => 1, ...}): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # sh's status, or (undef, ERROR) if STRING is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # outside the subset. The parser also reads the text of eval, . and trap actions (with the aliases defined so far: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | # parser->(TEXT, aliases => {NAME => VALUE})). interactive: what history, fc, bind, help, compopt, logout and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | # set -o history do (B2): nothing (nop, the default; give the parser the same option) or as in dash (not found). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 547 | require Proc::ShellSpawn::Builtins; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | # The variables a shell starts with: %ENV's. On Windows Perl gives %ENV's names in upper case, so a shell started there | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | # would see only Z for an inherited z (X65). The names there (post-0.12, the user, 2026-11-15, A22 (a)): as the process's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | # environment block spells them, but PATH (Windows spells it Path; the shell needs PATH, as Cygwin makes it); the values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # from %ENV. PROC_SHELLSPAWN_ENVNAMES (or $Proc::ShellSpawn::ENV_NAMES before run): 'block', the default, or 'upper', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | # the names as %ENV gives them (A22 (b)), so that on Windows only an upper-case name reaches a shell of ours. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 545 | ▶ | our $ENV_NAMES = $ENV{PROC_SHELLSPAWN_ENVNAMES} // 'block'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"PROC_SHELLSPAWN_ENVNAMES"} // "block"
MC/DC0%0/1
$ENV{"PROC_SHELLSPAWN_ENVNAMES"} // "block"
$ENV{"PROC_SHELLSPAWN_ENVNAMES"}
Truth table50%1/2
A
A= $ENV{"PROC_SHELLSPAWN_ENVNAMES"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 545 | ▶ | die "PROC_SHELLSPAWN_ENVNAMES: '$ENV_NAMES' is neither block nor upper\n" unless $ENV_NAMES =~ /\A(?:block|upper)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 545 | ▶ | sub env_vars { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
env_vars: called CC=5 SCAR=21.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 546 | ▶ | return %ENV unless $WIN && $ENV_NAMES eq 'block' && defined &Proc::Spawner::__win_env_names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$Proc::ShellSpawn::WIN and $Proc::ShellSpawn::ENV_NAMES eq "block" and defined &Proc::Spawner::__win_env_names
$Proc::ShellSpawn::WIN and $Proc::ShellSpawn::ENV_NAMES eq "block"
MC/DC0%0/3
$Proc::ShellSpawn::WIN and $Proc::ShellSpawn::ENV_NAMES eq "block" and defined &Proc::Spawner::__win_env_names
$Proc::ShellSpawn::WIN
$Proc::ShellSpawn::ENV_NAMES eq "block"
defined &Proc::Spawner::__win_env_names
Truth table25%1/4
A and B and C
A= $Proc::ShellSpawn::WINB= $Proc::ShellSpawn::ENV_NAMES eq "block"C= defined &Proc::Spawner::__win_env_names
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 2 | my %name = map +(uc($_) => $_), Proc::Spawner::__win_env_names(); $name{PATH} = 'PATH'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 2 | ▶ | map +(($name{uc $_} // $_) => $ENV{$_}), keys %ENV } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$name{uc $_} // $_
MC/DC0%0/2
$name{uc $_} // $_
$name{uc $_}
$_
Truth table0%0/3
A // B
A= $name{uc $_}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 551 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=10 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 552 | ▶ | 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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 552 | ▶ | my $tree = ref $s ? $s : $parse->($s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 551 | ▶ | return (undef, $tree) if ref $tree eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 545 | my $cwd = start_pwd(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | # dash sets OPTIND and IFS when it starts (L3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 545 | my %env = env_vars(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | my $sh = { vars => { %env, PWD => $cwd, OPTIND => 1, IFS => " \t\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | PPID => $Proc::Spawner::WIN ? Proc::Spawner::__win_ppid() : getppid() }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | exp => { map +($_ => 1), keys %env, 'PWD' }, cwd => $cwd, q => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 546 | ▶ | parse => $parse, args => [@{$o{args} // []}], arg0 => $o{arg0}, pid => $$, opt => {%{$o{opt} // {}}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$o{"args"} // []
$o{"opt"} // {}
$o{"interactive"} // "nop"
MC/DC100%1/1
$o{"args"} // []
$o{"args"}
MC/DC0%0/1
$o{"opt"} // {}
$o{"opt"}
MC/DC0%0/1
$o{"interactive"} // "nop"
$o{"interactive"}
Truth table100%2/2
A
A= $o{"args"}
Truth table50%1/2
A
A= $o{"opt"}
Truth table50%1/2
A
A= $o{"interactive"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | cmd => {}, ro => {}, trap => {}, jobl => [], umask => umask, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 546 | ▶ | alias => {}, hash => {}, intext => 0, interactive => $o{interactive} // 'nop' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 546 | my $st; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 546 | ▶ | my $c = { sh => $sh, loops => [], map => { map +($_ => is_open($_) ? own_fd($_) : undef), 0 .. 2 } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 546 | ▶ | 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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 546 | ▶ | $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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 546 | local %TRAPSAVE = (); $SIGNALLED = undef; # signals the trap builtin changed: put back afterwards | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 546 | { local $RUNNING = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 546 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 546 | $SIG{$_} = $TRAPSAVE{$_} for keys %TRAPSAVE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 546 | %$c = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 546 | idle(1); idle_pass(); # K3 (B): background jobs move on between calls too | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 546 | $st } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 545 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||