lib/Proc/ShellSpawn.pm

filter: Statementstmt 96.2% 1101 / 1144 Branchbran 77.2% 578 / 748 Conditioncond 66.1% 409 / 618 MC/DCmcdc 43.2% 147 / 340 Subroutinesub 93.6% 205 / 219 Podpod 0.0% 0 / 98 totaltotal 77.0% 2440 / 3167 CC 619 SCAR 29.3
CC
619
Cov
83%
sh_main
116.8
__ANON__
57.9
arith_expr
53.1
CRAP 18.7
« blib/lib/Proc/Spawner/Loop/Win32.pm ↑ Summary lib/Proc/Spawner/Loop/POSIX.pm »
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
BranchTrueFalseTotal
defined &Proc::ShellSubset::Large::parse ? : 557 0 557
defined &Proc::ShellSubset::parse ? : 0 0 0
defined &Proc::ShellSubset::Small::parse ? : 0 0 0
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
BranchTrueFalseTotal
($ENV{'TRACE'} // '') eq 'dot' ? : 0 548 548
Condition25%1/4
$ENV{"TRACE"} // ""
l!l
0548
$ENV{"TRACE_DIR"} // "."
l!l
00
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"}
Aresult
11
00
Truth table0%0/2
A
A= $ENV{"TRACE_DIR"}
Aresult
11
00
45  
46 715 ▶sub tr_ { $TRACE->(join '', @_) if $TRACE }
Subroutine tr_: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::TRACE 0 715 715
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
BranchTrueFalseTotal
if exists $_->{$n} 469 3199 3668
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"]
l!l
65027200
MC/DC100%1/1
$Proc::ShellSpawn::A4{$_} //= ["Proc::ShellSpawn::Large::b_unsupported"]
$Proc::ShellSpawn::A4{$_}
Truth table100%2/2
A
A= $Proc::ShellSpawn::A4{$_}
Aresult
11
00
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
BranchTrueFalseTotal
defined $text ? : 40 0 40
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)
l!l
16650
MC/DC0%0/1
POSIX::dup($_[0]) // (return 0)
POSIX::dup($_[0])
Truth table50%1/2
A
A= POSIX::dup($_[0])
Aresult
11
00
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
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 548 548
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
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 595 595
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
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 649 649
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
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN ? $p =~ m(^[A-Za-z]:[/\\]|^[/\\]{2}) : $p =~ m[^/] 2610 66 2676
$Proc::ShellSpawn::WIN ? : 0 2676 2676
99 73 ▶ return ($c->{sh}{cwd} =~ m{^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)} ? $1 : '') . $p if $WIN && $p =~ m{^[/\\]}; # (the drive,
Branch: 2 branches
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN and $p =~ m(^[/\\]) 0 66 66
$c->{'sh'}{'cwd'} =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)) ? : 0 0 0
Condition33%1/3
$Proc::ShellSpawn::WIN and $p =~ m(^[/\\])
!ll&&!rl&&r
6600
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(^[/\\])
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $n =~ /^\.\.?\z/ 0 0 0
Condition0%0/2
$ENV{"USERPROFILE"} // (return)
l!l
00
MC/DC0%0/1
$ENV{"USERPROFILE"} // (return)
$ENV{"USERPROFILE"}
Truth table0%0/2
A
A= $ENV{"USERPROFILE"}
Aresult
11
00
107 7 ▶ return $up if lc $n eq lc($ENV{USERNAME} // '');
Branch: 1 branch
BranchTrueFalseTotal
if lc $n eq lc($ENV{"USERNAME"} // "") 0 0 0
Condition0%0/2
$ENV{"USERNAME"} // ""
l!l
00
MC/DC0%0/1
$ENV{"USERNAME"} // ""
$ENV{"USERNAME"}
Truth table0%0/2
A
A= $ENV{"USERNAME"}
Aresult
11
00
108 7 ▶ my $d = ($up =~ s{[^/\\]+[/\\]*\z}{}r) . $n; -d $d ? $d : undef }
Branch: 1 branch
BranchTrueFalseTotal
-d $d ? : 0 0 0
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
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN && $p eq '/dev/null' ? : 0 122 122
Condition33%1/3
$Proc::ShellSpawn::WIN and $p eq "/dev/null"
!ll&&!rl&&r
12200
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
my(@a) = stat $_[0] or return "" 584 1 585
my(@b) = stat $_[1] or return "" 583 1 584
120 563 ▶ if ($WIN && defined &Proc::Spawner::__win_same_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Proc::ShellSpawn::WIN and defined &Proc::Spawner::__win_same_file) 0 583 583
Condition33%1/3
$Proc::ShellSpawn::WIN and defined &Proc::Spawner::__win_same_file
!ll&&!rl&&r
58300
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if defined $r 0 0 0
$r ? : 0 0 0
124 577 ▶ $a[1] && $b[1] ? $a[0] == $b[0] && $a[1] == $b[1] : paths_eq(@_) }
Branch: 1 branch
BranchTrueFalseTotal
$a[1] && $b[1] ? : 583 0 583
Condition50%3/6
$a[1] and $b[1]
!ll&&!rl&&r
00583
$a[0] == $b[0] and $a[1] == $b[1]
!ll&&!rl&&r
05578
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]
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $a[0] == $b[0]B= $a[1] == $b[1]
ABresult
0X0
100
111
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
BranchTrueFalseTotal
defined $x and defined $y and $Proc::ShellSpawn::WIN ? lc $x eq lc $y : $x eq $y 3 0 3
$Proc::ShellSpawn::WIN ? : 0 3 3
Condition33%1/3
defined $x and defined $y
!ll&&!rl&&r
003
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $op eq ">" and $c->{"sh"}{"opt"}{"C"} and -f $path 1 121 122
Condition100%6/6
$op eq ">" and $c->{"sh"}{"opt"}{"C"} and -f $path
!ll&&!rl&&r
12011
$op eq ">" and $c->{"sh"}{"opt"}{"C"}
!ll&&!rl&&r
51692
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless $ok 17 104 121
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
BranchTrueFalseTotal
if (my $k = $o{"shell"}) 321 528 849
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
BranchTrueFalseTotal
$o{'jobs'} ? : 244 77 321
153 251 ▶ ljobs => $o{jobs} ? [@{$sh->{ljobs} // []}, @{$sh->{jobl}}] : [], # jobs listed in a pipeline or $( ) (rule E)
Condition100%2/2
$sh->{"ljobs"} // []
l!l
31213
MC/DC100%1/1
$sh->{"ljobs"} // []
$sh->{"ljobs"}
Truth table100%2/2
A
A= $sh->{"ljobs"}
Aresult
11
00
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
l!l&&r!l&&!r
532680
MC/DC0%0/2
$sh->{"main"} // $sh
$sh->{"main"} $sh
Truth table66%2/3
A // B
A= $sh->{"main"}B= $sh
ABresult
1X1
011
000
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
BranchTrueFalseTotal
@{$d->{'loops'};} ? : 70 779 849
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
BranchTrueFalseTotal
if $state == 2 0 860 860
167 846 ▶ my $a = $state == 0 && $c && delete $c->{sh}{trap}{EXIT};
Condition83%5/6
$state == 0 && $c && delete $c->{'sh'}{'trap'}{'EXIT'}
!ll&&!rl&&r
18518
$state == 0 and $c
!ll&&!rl&&r
10859
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'}
ABCresult
0XX0
10X0
1100
1111
168 847 ▶ if (defined $a && $a ne '' and ref(my $t = $c->{sh}{parse}->($a, nolineno => 1)) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $a and $a ne "" and ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY") 8 852 860
Condition83%5/6
defined $a and $a ne "" and ref(my $t = $c->{"sh"}{"parse"}->($a, "nolineno", 1)) eq "ARRAY"
!ll&&!rl&&r
85208
defined $a and $a ne ""
!ll&&!rl&&r
85118
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"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if $state == 2 0 7 7
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
BranchTrueFalseTotal
if $c and $c->{"late"} 3 856 859
Condition66%2/3
$c and $c->{"late"}
!ll&&!rl&&r
08563
MC/DC50%1/2
$c and $c->{"late"}
$c $c->{"late"}
Truth table66%2/3
A and B
A= $cB= $c->{"late"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if not $c->{"held"} or $c->{"released"} 721 854 1575
Condition66%2/3
not $c->{"held"} or $c->{"released"}
l!l&&r!l&&!r
0721854
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"}
ABresult
1X1
011
000
175 854 ▶ return $c->{late} = 1 if $c->{root} && ($c->{sh}{trap}{EXIT} // '') ne ''; # its EXIT trap still needs them (L5)
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"root"} and ($c->{"sh"}{"trap"}{"EXIT"} // "") ne "" 3 851 854
Condition100%5/5
$c->{"root"} and ($c->{"sh"}{"trap"}{"EXIT"} // "") ne ""
!ll&&!rl&&r
5303213
$c->{"sh"}{"trap"}{"EXIT"} // ""
l!l
3321
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$w & 127 ? : 8 279 287
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
BranchTrueFalseTotal
if %JOBS 0 0 0
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"
l!l
0548
MC/DC0%0/1
$ENV{"PROC_SHELLSPAWN_END"} // "shell"
$ENV{"PROC_SHELLSPAWN_END"}
Truth table50%1/2
A
A= $ENV{"PROC_SHELLSPAWN_END"}
Aresult
11
00
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
BranchTrueFalseTotal
() = ($_[0] // "") =~ /\A(shell|all|none)?(?::(\d+(?:\.\d*)?))?\z/ or return 1100 0 1100
Condition50%2/4
$_[0] // ""
l!l
11000
$m // "shell"
l!l
11000
MC/DC0%0/1
$_[0] // ""
$_[0]
MC/DC0%0/1
$m // "shell"
$m
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
Truth table50%1/2
A
A= $m
Aresult
11
00
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" }
l!l
5480
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" }
ABresult
1X1
011
000
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
l!l&&r!l&&!r
009
grep((defined $_ && !$_->{"released"}), values %LIVE) or %{$Proc::ShellSpawn::G->{"io"};}
l!l&&r!l&&!r
009
defined $_ && !$_->{'released'}
!ll&&!rl&&r
0130
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
ABCresult
1XX1
01X1
0011
0000
Truth table33%1/3
A && not(B)
A= defined $_B= !$_->{'released'}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $mode 0 550 550
Condition0%0/2
$mode //= "shell"
l!l
00
MC/DC0%0/1
$mode //= "shell"
$mode
Truth table0%0/2
A
A= $mode
Aresult
11
00
214 554 ▶ return if !%JOBS or $mode eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if not %JOBS or $mode eq "none" 541 9 550
Condition66%2/3
not %JOBS or $mode eq "none"
l!l&&r!l&&!r
54109
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"
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$mode eq 'all' ? : 0 9 9
not %JOBS or settled() 0 9 9
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
BranchTrueFalseTotal
if $Proc::ShellSpawn::RUNNING or not %JOBS 534 24 558
Condition66%2/3
$Proc::ShellSpawn::RUNNING or not %JOBS
l!l&&r!l&&!r
053424
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
ABresult
1X1
011
000
225 10 ignoring_int(\&Proc::Spawner::poll);
226 10 ▶ idle(0) unless %JOBS }
Branch: 1 branch
BranchTrueFalseTotal
unless %JOBS 8 16 24
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
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN 0 568 568
230 554 ▶ if ($on && %JOBS && !$IDLE_ON) {
Branch: 2 branches
BranchTrueFalseTotal
if ($on and %JOBS and not $IDLE_ON) { } 17 551 568
elsif (not $on and $IDLE_ON) { } 17 1068 1085
Condition83%5/6
$on and %JOBS and not $IDLE_ON
!ll&&!rl&&r
551017
$on and %JOBS
!ll&&!rl&&r
1753417
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ref $h eq "CODE" 0 7 7
Condition33%1/3
$IDLE_OLD && $IDLE_OLD->{'HANDLER'}
!ll&&!rl&&r
007
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'}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
POSIX::sigaction(17, $a, $IDLE_OLD) and $IDLE_ON = 1 17 0 17
237 10 ▶ elsif (!$on && $IDLE_ON) { POSIX::sigaction(POSIX::SIGCHLD(), $IDLE_OLD); $IDLE_ON = 0 } }
Condition66%2/3
not $on and $IDLE_ON
!ll&&!rl&&r
534017
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
ABresult
0X0
100
111
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)
!ll&&!rl&&r
361665482
$SIG{$_} // ""
l!l
55036166
$_ ne "FPE" or $FPE == 1
l!l&&r!l&&!r
20548
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
ABCresult
0XX0
1000
11X1
1011
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 { }
l!l&&r!l&&!r
21900
MC/DC0%0/2
$then //= sub { }
$then sub { }
Truth table33%1/3
A //= B
A= $thenB= sub { }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$e ? : 219 0 219
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
BranchTrueFalseTotal
if $t eq "" 0 631 631
unless $e 1 630 631
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
l!l
3627
MC/DC100%1/1
$err || undef
$err
Truth table100%2/2
A
A= $err
Aresult
11
00
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
BranchTrueFalseTotal
$_ eq 'all' ? : 539 9 548
$_ eq 'none' ? : 9 0 9
Condition100%2/2
$ENV{"PROC_SHELLSPAWN_INPROC"} // "all"
l!l
18530
MC/DC100%1/1
$ENV{"PROC_SHELLSPAWN_INPROC"} // "all"
$ENV{"PROC_SHELLSPAWN_INPROC"}
Truth table100%2/2
A
A= $ENV{"PROC_SHELLSPAWN_INPROC"}
Aresult
11
00
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'
l!l
45692
MC/DC100%1/1
$ENV{'PROC_SHELLSPAWN_ECHO'} || 'coreutils'
$ENV{'PROC_SHELLSPAWN_ECHO'}
Truth table100%2/2
A
A= $ENV{'PROC_SHELLSPAWN_ECHO'}
Aresult
11
00
269 547 ▶die "PROC_SHELLSPAWN_ECHO: '$ECHO' is none of coreutils, dash, bash\n" unless $ECHO =~ /\A(?:coreutils|dash|bash)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSpawn::ECHO =~ /\A(?:coreutils|dash|bash)\z/ 0 548 548
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'
l!l
20528
MC/DC100%1/1
$ENV{'PROC_SHELLSPAWN_SH'} || 'auto'
$ENV{'PROC_SHELLSPAWN_SH'}
Truth table100%2/2
A
A= $ENV{'PROC_SHELLSPAWN_SH'}
Aresult
11
00
279 547 ▶die "PROC_SHELLSPAWN_SH: '$SH' is none of auto, perl, program\n" unless $SH =~ /\A(?:auto|perl|program)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSpawn::SH =~ /\A(?:auto|perl|program)\z/ 0 548 548
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
BranchTrueFalseTotal
if $argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program" or $Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0]) 303 10 313
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])
l!l&&r!l&&!r
2911210
$argv->[0] ne "sh" or $Proc::ShellSpawn::SH eq "program"
l!l&&r!l&&!r
2811022
$Proc::ShellSpawn::SH eq "auto" and defined((find_cmd($c, "sh", $path))[0])
!ll&&!rl&&r
10012
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])
ABCDresult
1XXX1
01XX1
00111
000X0
00100
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"
l!l
100
MC/DC0%0/1
$parser // "Proc::ShellSubset"
$parser
Truth table50%1/2
A
A= $parser
Aresult
11
00
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
BranchTrueFalseTotal
unless @w 1306 0 1306
289 12 ▶ die "Proc::ShellSpawn: only 'sh' can be imported\n" unless @w == 1 && $w[0] eq 'sh';
Branch: 1 branch
BranchTrueFalseTotal
unless @w == 1 and $w[0] eq "sh" 0 0 0
Condition0%0/3
@w == 1 and $w[0] eq "sh"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (@a and $a[0] =~ /\A-(.+)\z/s) 0 0 0
Condition0%0/3
@a and $a[0] =~ /\A-(.+)\z/s
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
295 96 ▶ shift @a; last if $1 eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "-" 0 0 0
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
BranchTrueFalseTotal
$l eq 'c' ? : 0 0 0
$l eq 's' ? : 0 0 0
$l =~ /\A[a-zA-Z]\z/ && $l ne 'o' && $l ne 'i' ? : 0 0 0
Condition0%0/6
$l =~ /\A[a-zA-Z]\z/ and $l ne "o" and $l ne "i"
!ll&&!rl&&r
000
$l =~ /\A[a-zA-Z]\z/ and $l ne "o"
!ll&&!rl&&r
000
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"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ($opt_c) { } 0 0 0
elsif (not $opt_s and @a) { } 0 0 0
@a or return &$bad("-c requires an argument") 0 0 0
300 ▶ elsif (!$opt_s && @a) {
Condition0%0/3
not $opt_s and @a
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
301 8 ▶ $name = shift @a; open my $f, '<', $name or return $bad->("0: cannot open $name: $!"); binmode $f; local $/; $text = <$f> }
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<", $name or return &$bad("0: cannot open ${name}: $!") 0 0 0
302 0 ▶ else { binmode STDIN; local $/; $text = <STDIN> // '' }
Condition0%0/2
readline STDIN // ""
l!l
00
MC/DC0%0/1
readline STDIN // ""
readline STDIN
Truth table0%0/2
A
A= readline STDIN
Aresult
11
00
303 7 ▶ local $NAME = $name // 'sh';
Condition0%0/2
$name // "sh"
l!l
00
MC/DC0%0/1
$name // "sh"
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
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
BranchTrueFalseTotal
defined $st or print(STDERR qq[$Proc::ShellSpawn::NAME: outside the subset: $err->{"error"} at $err->{"pos"}\n]), (return 255) 0 0 0
306 7 ▶ if (my $s = $SIGNALLED) { local $SIG{$s} = 'DEFAULT'; kill $s, $$; sleep 1 } # die by it, as sh would
Branch: 1 branch
BranchTrueFalseTotal
if (my $s = $Proc::ShellSpawn::SIGNALLED) 0 0 0
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
BranchTrueFalseTotal
!defined($ENV{'PROC_SHELLSPAWN_BIN'}) ? : 548 0 548
$Proc::ShellSpawn::WIN ? : 0 548 548
$ENV{'PROC_SHELLSPAWN_BIN'} eq 'none' ? : 0 0 0
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:"
l!l
00
MC/DC0%0/1
$ENV{"SystemDrive"} // "C:"
$ENV{"SystemDrive"}
Truth table0%0/2
A
A= $ENV{"SystemDrive"}
Aresult
11
00
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
BranchTrueFalseTotal
defined $ENV{'LOCALAPPDATA'} ? : 0 0 0
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
BranchTrueFalseTotal
if -f "$d\\cat.exe" 0 0 0
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)
l!l
00
MC/DC0%0/1
$ENV{"SystemRoot"} // (return 0)
$ENV{"SystemRoot"}
Truth table0%0/2
A
A= $ENV{"SystemRoot"}
Aresult
11
00
329 0 ▶ $WINCLASH{lc $name} && lc(substr($p, 0, length $r) =~ tr{/}{\\}r) eq lc($r =~ tr{/}{\\}r) }
Branch: 1 branch
BranchTrueFalseTotal
$WINCLASH{lc $name} and lc substr($p, 0, length($r)) =~ tr[/][\\]r eq lc $r =~ tr[/][\\]r 0 0 0
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
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 334 334
Condition0%0/2
$c->{"sh"}{"vars"}{"PATHEXT"} // ".COM;.EXE;.BAT;.CMD"
l!l
00
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"}
Aresult
11
00
334 322 ▶ if (has_dir($name)) { -f path_in($c, "$name$_") and return "$name$_" for @ext; return $name }
Branch: 2 branches
BranchTrueFalseTotal
if (has_dir($name)) 30 304 334
-f path_in($c, "$name$_") and return "$name$_" 28 2 30
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
BranchTrueFalseTotal
$d eq '' ? : 0 2462 2462
$Proc::ShellSpawn::WIN && $d =~ /\\/ && !($d =~ m[/]) ? : 0 2462 2462
Condition33%2/6
$Proc::ShellSpawn::WIN and $d =~ /\\/ and not $d =~ m[/]
!ll&&!rl&&r
246200
$Proc::ShellSpawn::WIN and $d =~ /\\/
!ll&&!rl&&r
246200
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[/]
ABCresult
0XX0
10X0
1100
1111
338 2367 ▶ next unless -f path_in($c, $p);
Branch: 1 branch
BranchTrueFalseTotal
unless -f path_in($c, $p) 2173 289 2462
339 278 ▶ next if $WIN && win_clash($name, $p);
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN and win_clash($name, $p) 0 289 289
Condition33%1/3
$Proc::ShellSpawn::WIN and win_clash($name, $p)
!ll&&!rl&&r
28900
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)
ABresult
0X0
100
111
340 278 ▶ return $p if -x _;
Branch: 1 branch
BranchTrueFalseTotal
if -x _ 289 0 289
341 1 ▶ $denied //= $p } }
Condition0%0/3
$denied //= $p
l!l&&r!l&&!r
000
MC/DC0%0/2
$denied //= $p
$denied $p
Truth table0%0/3
A //= B
A= $deniedB= $p
ABresult
1X1
011
000
342 16 ▶ defined $denied ? (undef, 126, $denied) : (undef, 127) }
Branch: 1 branch
BranchTrueFalseTotal
defined $denied ? : 0 15 15
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/
!ll&&!rl&&r
3386034901
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/
ABresult
0X0
100
111
347 # names only
348 994 ▶ return inproc($c, $map, $argv, \%e, $k) if $INPROC{$argv->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::INPROC{$argv->[0]} 688 313 1001
349 306 ▶ if (my $a = sh_argv($c, $argv, $search // $e{PATH})) { $argv = $a; undef $search } # sh as Perl (SH1)
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = sh_argv($c, $argv, $search // $e{"PATH"})) 10 303 313
Condition33%1/3
$search // $e{"PATH"}
l!l&&r!l&&!r
03130
MC/DC0%0/2
$search // $e{"PATH"}
$search $e{"PATH"}
Truth table33%1/3
A // B
A= $searchB= $e{"PATH"}
ABresult
1X1
011
000
350 308 ▶ my ($path, $st, $what) = find_cmd($c, $argv->[0], $search // $e{PATH});
Condition33%1/3
$search // $e{"PATH"}
l!l&&r!l&&!r
03130
MC/DC0%0/2
$search // $e{"PATH"}
$search $e{"PATH"}
Truth table33%1/3
A // B
A= $searchB= $e{"PATH"}
ABresult
1X1
011
000
351 308 ▶ $c->{sh}{hash}{$argv->[0]} = $path if defined $path && !defined $search && !has_dir($argv->[0]); # remembered, as dash
Branch: 1 branch
BranchTrueFalseTotal
if defined $path and not defined $search and not has_dir($argv->[0]) 272 41 313
Condition83%5/6
defined $path and not defined $search and not has_dir($argv->[0])
!ll&&!rl&&r
1130272
defined $path and not defined $search
!ll&&!rl&&r
110302
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])
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if $log and $Proc::ShellSpawn::ONBUILTIN 0 15 15
$st == 127 ? : 0 0 0
Condition66%2/3
$log and $Proc::ShellSpawn::ONBUILTIN
!ll&&!rl&&r
4110
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
ABresult
0X0
100
111
356 307 ▶ cmd_msg($c, $map, "$argv->[0]: " . ($st == 127 ? 'not found' : $why), done($k, $st)) };
Branch: 1 branch
BranchTrueFalseTotal
$st == 127 ? : 12 3 15
357 307 ▶ return $no->($st, 'Permission denied', 1) if !defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 11 302 313
358 295 ▶ return $no->(126, 'Permission denied', 1) # Windows runs neither: as sh says it (CreateProcess: not found,
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::WIN and -e path_in($c, $path) and -d _ || !-x(_) 0 302 302
Condition22%2/9
$Proc::ShellSpawn::WIN and -e path_in($c, $path) and -d _ || !-x(_)
!ll&&!rl&&r
30200
$Proc::ShellSpawn::WIN and -e path_in($c, $path)
!ll&&!rl&&r
30200
-d _ or not -x _
l!l&&r!l&&!r
000
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 _
ABCDresult
0XXX0
10XX0
11000
111X1
11011
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
BranchTrueFalseTotal
$FPE ? : 0 302 302
Condition70%7/10
!$Proc::ShellSpawn::IGN0{$_} && ($SIG{$_} // '') eq 'IGNORE' && ($c->{'sh'}{'trap'}{$_} // 1) ne ''
!ll&&!rl&&r
1902701509
not $Proc::ShellSpawn::IGN0{$_} and ($SIG{$_} // "") eq "IGNORE"
!ll&&!rl&&r
0190271509
$SIG{$_} // ""
l!l
152219014
$c->{"sh"}{"trap"}{$_} // 1
l!l
01509
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"}{$_}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if $c->{"sh"}{"job"} 43 259 302
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
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN ? : 0 302 302
$c->{'sh'}{'cwd'} ne Cwd::getcwd() ? : 16 286 302
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
BranchTrueFalseTotal
if (not $node || $Proc::ShellSpawn::WIN and $! == 8) 0 302 302
Condition66%4/6
not $node || $Proc::ShellSpawn::WIN and $! == 8
!ll&&!rl&&r
29840
$node || $Proc::ShellSpawn::WIN
l!l&&r!l&&!r
29804
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
ABCresult
1XX0
01X0
0000
0011
371 0 $node = $G->start('/bin/sh', ['sh', $path, @$argv[1 .. $#$argv]], \@envp, $map, @o) }
372 295 ▶ return $node if $node;
Branch: 1 branch
BranchTrueFalseTotal
if $node 298 4 302
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
BranchTrueFalseTotal
$map->{$_} ? : 12 0 12
375 11 ▶ $st = $! == POSIX::ENOENT() ? 127 : 126;
Branch: 1 branch
BranchTrueFalseTotal
$! == 2 ? : 1 3 4
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
BranchTrueFalseTotal
if defined $bad 0 4 4
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
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 688 688
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
BranchTrueFalseTotal
$e and POSIX::isatty($e->{"fd"}) 0 0 0
390 688 ▶ my ($out, $err, $st, $seq) = Proc::ShellSpawn::Programs->can($argv->[0] eq '[' ? 'test' : $argv->[0])->($argv, $env, \%opt);
Branch: 1 branch
BranchTrueFalseTotal
$argv->[0] eq '[' ? : 30 658 688
391 687 ▶ my @seq = grep length $_->[1], @{$seq // [[2, $err], [1, $out]]};
Condition100%2/2
$seq // [[2, $err], [1, $out]]
l!l
29659
MC/DC100%1/1
$seq // [[2, $err], [1, $out]]
$seq
Truth table100%2/2
A
A= $seq
Aresult
11
00
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 ''
!ll&&!rl&&r
00688
$c->{"sh"}{"trap"}{"PIPE"} // 1
l!l
0688
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ($p) 685 630 1315
398 684 ▶ release($_) for values %$map; return $k->($st) unless $werr;
Branch: 1 branch
BranchTrueFalseTotal
unless $werr 684 1 685
399 1 ▶ local $! = $werr; return write_fd($d, 2, "$argv->[0]: write error" . ($werr > 0 ? ": $!" : '') . "\n", done($k, 1)) }
Branch: 1 branch
BranchTrueFalseTotal
$werr > 0 ? : 1 0 1
400 630 ▶ return $next->() if $p->[0] == 1 && $werr;
Branch: 1 branch
BranchTrueFalseTotal
if $p->[0] == 1 and $werr 0 630 630
Condition66%2/3
$p->[0] == 1 and $werr
!ll&&!rl&&r
36270
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($e and $p->[0] == 1) 4 626 630
Condition66%2/3
$e and $p->[0] == 1
!ll&&!rl&&r
62604
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
ABresult
0X0
100
111
404 4 ▶ if ($e == POSIX::EPIPE() && $pipe_dfl) { release($_) for values %$map; return $k->(128 + 13) } # (SIGPIPE: 13)
Branch: 1 branch
BranchTrueFalseTotal
if ($e == 32 and $pipe_dfl) 3 1 4
Condition66%2/3
$e == 32 and $pipe_dfl
!ll&&!rl&&r
103
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
!grep(($_->[0] == 1), @seq) && length $p->[1] <= 4096 ? : 1 0 1
Condition33%1/3
not grep(($_->[0] == 1), @seq) and length $p->[1] <= 4096
!ll&&!rl&&r
001
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
defined $w ? : 287 0 287
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
BranchTrueFalseTotal
if $i > $redirs->$#* 1456 443 1899
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
BranchTrueFalseTotal
if ($op eq "<<") 20 423 443
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
BranchTrueFalseTotal
() = new_pipe() or return &$fail("pipe: $!") 14 0 14
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
BranchTrueFalseTotal
if ($op eq "<&" or $op eq ">&") 337 86 423
Condition100%3/3
$op eq "<&" or $op eq ">&"
l!l&&r!l&&!r
633186
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 ">&"
ABresult
1X1
011
000
432 337 ▶ if ($w eq '-') { $m{$fd} = undef }
Branch: 3 branches
BranchTrueFalseTotal
if ($w eq '-') { } 4 333 337
elsif (exists $m{$w}) { } 330 3 333
elsif (visible($w)) { } 0 3 3
433 330 ▶ elsif (exists $m{$w}) { defined $m{$w} ? ($m{$fd} = $m{$w}) : return $fail->("$w: Bad file descriptor") }
Branch: 1 branch
BranchTrueFalseTotal
defined $m{$w} ? : 330 0 330
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)
!ll&&!rl&&r
11867
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)
ABresult
0X0
100
111
440 85 ▶ if (!$e) { # dash's wording
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 19 67 86
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
BranchTrueFalseTotal
$name eq '' || $!{'ENOENT'} ? : 18 1 19
$op eq '<' ? : 2 16 18
Condition100%3/3
$name eq "" or $!{"ENOENT"}
l!l&&r!l&&!r
1171
MC/DC100%2/2
$name eq "" or $!{"ENOENT"}
$name eq "" $!{"ENOENT"}
Truth table100%3/3
A or B
A= $name eq ""B= $!{"ENOENT"}
ABresult
1X1
011
000
442 19 ▶ return $fail->(($op eq '<' ? 'cannot open' : 'cannot create') . " $name: $err") }
Branch: 1 branch
BranchTrueFalseTotal
$op eq '<' ? : 2 17 19
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
BranchTrueFalseTotal
unless $redirs and @$redirs 347 31 378
Condition66%2/3
$redirs and @$redirs
!ll&&!rl&&r
347031
MC/DC50%1/2
$redirs and @$redirs
$redirs @$redirs
Truth table66%2/3
A and B
A= $redirsB= @$redirs
ABresult
0X0
100
111
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
BranchTrueFalseTotal
my($m, $opened) = or return defer($k, 2) 26 5 31
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 // []
l!l
1115
MC/DC100%1/1
$tail // []
$tail
Truth table100%2/2
A
A= $tail
Aresult
11
00
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
BranchTrueFalseTotal
if $n =~ /^[0-9]+\z/ 25 1249 1274
$n ? : 24 1 25
Condition75%3/4
$sh->{"args"}[$n - 1] // ""
l!l
222
$sh->{"arg0"} // "sh"
l!l
01
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]
Aresult
11
00
Truth table50%1/2
A
A= $sh->{"arg0"}
Aresult
11
00
458 13 ▶ $n eq '?' ? $sh->{q} : $n eq '!' ? ($sh->{bang} // {})->{first} // '' : $n eq '#' ? scalar @{$sh->{args}}
Branch: 2 branches
BranchTrueFalseTotal
$n eq '$' ? : 33 1018 1051
$n eq '@' || $n eq '*' ? : 15 1003 1018
Condition100%3/3
$n eq "\@" or $n eq "*"
l!l&&r!l&&!r
5101003
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 "*"
ABresult
1X1
011
000
459 1249 ▶ : $n eq '$' ? $sh->{pid} : $n eq '@' || $n eq '*' ? join(ifs1($c), @{$sh->{args}}) : $sh->{vars}{$n} // '' }
Branch: 3 branches
BranchTrueFalseTotal
$n eq '?' ? : 175 1074 1249
$n eq '!' ? : 10 1064 1074
$n eq '#' ? : 13 1051 1064
Condition100%6/6
+($sh->{"bang"} // {})->{"first"} // ""
l!l
82
$sh->{"bang"} // {}
l!l
91
$sh->{"vars"}{$n} // ""
l!l
97132
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"}
Aresult
11
00
Truth table100%2/2
A
A= $sh->{"vars"}{$n}
Aresult
11
00
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
BranchTrueFalseTotal
defined $i ? : 18 0 18
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
BranchTrueFalseTotal
$n =~ /^[\@*]\z/ ? : 4 64 68
$n eq '!' ? : 1 63 64
Condition100%3/3
$n =~ /^[?#\$0]\z/ or defined $sh->{"vars"}{$n}
l!l&&r!l&&!r
33030
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}
ABresult
1X1
011
000
464 71 ▶ : $n eq '!' ? defined $sh->{bang} : $n =~ /^[?#\$0]\z/ || defined $sh->{vars}{$n} }
Branch: 1 branch
BranchTrueFalseTotal
$n =~ /^[1-9][0-9]*\z/ ? : 3 68 71
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
BranchTrueFalseTotal
if $c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n) 6 1161 1167
Condition83%5/6
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/ and not isset($c, $n)
!ll&&!rl&&r
115836
$c->{"sh"}{"opt"}{"u"} and not $n =~ /^[\@*!]\z/
!ll&&!rl&&r
115809
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)
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ($p =~ /\G(?:(\\.)|(\[)|(.))/cgs) 149 41 190
476 149 ▶ if (!defined $2) { $o .= $+; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $2) 127 22 149
477 22 my $s = pos $p;
478 22 ▶ if ($p =~ /\G([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]/gcs) { my ($n, $b) = ($1, $2);
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /\G([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]/cgs) { } 19 3 22
479 19 ▶ if ("$n$b" =~ m{/}) { $o .= '\\['; pos($p) = $s }
Branch: 1 branch
BranchTrueFalseTotal
if ("$n$b" =~ m[/]) { } 2 17 19
480 17 ▶ else { $b =~ s/\[:([a-z]+):\]/class_chars($1)/ge; $o .= ($n ? '[!' : '[') . "$b]" } } # [^...]: [!...] (rule E)
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 2 15 17
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:]]/
!ll&&!rl&&r
5483397616988
MC/DC100%2/2
$_ ne '/' && /[[:punct:]]/
$_ ne '/' /[[:punct:]]/
Truth table100%3/3
A && B
A= $_ ne '/'B= /[[:punct:]]/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
my $m = $CLASS{$n} or return "[:${n}:]" 4 1 5
491 4 ▶ join '', map { ref $_ ? quote_bracket($_->[0]) . '-' . quote_bracket($_->[1]) : quote_bracket($_) } @$m }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 5 31 36
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
BranchTrueFalseTotal
$c =~ /[A-Za-z0-9]/ ? : 10 31 41
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
BranchTrueFalseTotal
unless ref $word 3734 659 4393
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"
l!l
20140
MC/DC0%0/1
$c->{"sh"}{"vars"}{"IFS"} // " \t\n"
$c->{"sh"}{"vars"}{"IFS"}
Truth table50%1/2
A
A= $c->{"sh"}{"vars"}{"IFS"}
Aresult
11
00
506 2014 ▶ if ($split && $how eq 'argv' && $ifs ne '') { # split at IFS characters (L2); the pieces may glob
Branch: 2 branches
BranchTrueFalseTotal
if ($split and $how eq 'argv' and $ifs ne '') { } 373 1641 2014
elsif ($split and $how eq 'argv') { } 2 1639 1641
Condition100%6/6
$split and $how eq "argv" and $ifs ne ""
!ll&&!rl&&r
16392373
$split and $how eq "argv"
!ll&&!rl&&r
159841375
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 ""
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
$nw eq '' ? : 368 5 373
$ws eq '' ? : 5 0 5
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
BranchTrueFalseTotal
if ($j % 2) 29 392 421
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
BranchTrueFalseTotal
if length $cur->{"text"} or $cur->{"keep"} or $nw ne "" and $p[$j] =~ /[$nw]/ 28 1 29
Condition77%7/9
length $cur->{"text"} or $cur->{"keep"} or $nw ne "" and $p[$j] =~ /[$nw]/
l!l&&r!l&&!r
2621
length $cur->{"text"} or $cur->{"keep"}
l!l&&r!l&&!r
2603
$nw ne "" and $p[$j] =~ /[$nw]/
!ll&&!rl&&r
102
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]/
ABCDresult
1XXX1
01XX1
00111
000X0
00100
513 392 ▶ $cur->{text} .= $p[$j]; $cur->{pat} .= $p[$j]; $cur->{glob} ||= active($p[$j]) } }
Condition100%3/3
$cur->{"glob"} ||= active($p[$j])
l!l&&r!l&&!r
36383
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])
ABresult
1X1
011
000
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"
!ll&&!rl&&r
1598412
$cur->{"glob"} ||= active($t)
l!l&&r!l&&!r
002
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"
ABresult
0X0
100
111
Truth table33%1/3
A ||= B
A= $cur->{"glob"}B= active($t)
ABresult
1X1
011
000
515 1639 ▶ else { $cur->{text} .= $t; $cur->{pat} .= $pat ? $t : glob_quote($t); $cur->{glob} ||= $pat && $t =~ /[*?\[]/;
Branch: 1 branch
BranchTrueFalseTotal
$pat ? : 48 1591 1639
Condition100%6/6
$cur->{"glob"} ||= $pat && $t =~ /[*?\[]/
l!l&&r!l&&!r
18381583
$pat && $t =~ /[*?\[]/
!ll&&!rl&&r
1581238
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 =~ /[*?\[]/
ABCresult
1XX1
0111
00X0
0100
516 659 ▶ $cur->{keep} = 1 unless $pat } };
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 1591 48 1639
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
BranchTrueFalseTotal
unless @_ 3 10 13
519 659 ▶ for my $j (0 .. $#_) { if ($j) { push @f, $cur; $cur = fresh_field() } $add->($_[$j], 0) } };
Branch: 1 branch
BranchTrueFalseTotal
if ($j) 14 10 24
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
BranchTrueFalseTotal
if ($i > $#parts) 636 2026 2662
523 636 ▶ push @f, $cur if length $cur->{text} or $cur->{keep} && !$cur->{gone} or $how ne 'argv';
Branch: 1 branch
BranchTrueFalseTotal
if length $cur->{"text"} or $cur->{"keep"} and not $cur->{"gone"} or $how ne "argv" 623 13 636
Condition88%8/9
length $cur->{"text"} or $cur->{"keep"} and not $cur->{"gone"} or $how ne "argv"
l!l&&r!l&&!r
623013
length $cur->{"text"} or $cur->{"keep"} and not $cur->{"gone"}
l!l&&r!l&&!r
6121113
$cur->{"keep"} and not $cur->{"gone"}
!ll&&!rl&&r
11211
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"
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
524 636 ▶ return $k->([map $_->{text}, @f]) if $how ne 'argv';
Branch: 1 branch
BranchTrueFalseTotal
if $how ne "argv" 48 588 636
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
BranchTrueFalseTotal
!$g || is_abs($p) || $c->{'sh'}{'cwd'} eq Cwd::getcwd() ? : 600 17 617
Condition100%6/6
not $g or is_abs($p) or $c->{"sh"}{"cwd"} eq Cwd::getcwd()
l!l&&r!l&&!r
5821817
not $g or is_abs($p)
l!l&&r!l&&!r
573935
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()
ABCresult
1XX1
01X1
0011
0000
528 617 ▶ my @m = $g && !$c->{sh}{opt}{f} ? sort { $a cmp $b } grep !m{(?:^|/)\.\.?\z},
Branch: 1 branch
BranchTrueFalseTotal
$g && !$c->{'sh'}{'opt'}{'f'} ? : 41 576 617
Condition100%3/3
$g and not $c->{"sh"}{"opt"}{"f"}
!ll&&!rl&&r
573341
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$base ? : 17 600 617
531 617 ▶ @m ? @m : $t } @f]) }
Branch: 1 branch
BranchTrueFalseTotal
@m ? : 27 590 617
532 2026 my $x = $parts[$i++];
533 2026 ▶ return $add->($x, 0), $next->() unless ref $x;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 695 1331 2026
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
BranchTrueFalseTotal
if ($kind eq '*') { } 48 1283 1331
elsif ($kind eq '~') { } 5 1278 1283
elsif ($kind eq '"$' and $a[0] eq '@' and $how eq 'argv') { } 12 1266 1278
elsif ($q eq '$') { } 1118 148 1266
elsif ($q eq '${#') { } 12 136 148
elsif ($q eq '${') { } 59 77 136
elsif ($kind eq q[']) { } 0 77 77
elsif ($kind eq 'ext') { } 0 77 77
elsif ($q eq '$((' and ref $a[0]) { } 0 77 77
elsif ($q eq '$((') { } 41 36 77
elsif ($q eq '$(') { } 36 0 36
elsif ($kind eq '{' or $kind eq '{..') { } 0 0 0
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
BranchTrueFalseTotal
$a[0] ne '' ? : 2 3 5
$Proc::ShellSpawn::WIN ? : 0 2 2
exists $c->{'sh'}{'vars'}{'HOME'} ? : 1 2 3
$Proc::ShellSpawn::WIN ? : 0 2 2
Condition75%3/4
($Proc::ShellSpawn::WIN ? win_home($a[0]) : (getpwnam $a[0])[7]) // "~$a[0]"
l!l
11
($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7]) // "~"
l!l
20
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])
Aresult
11
00
Truth table50%1/2
A
A= ($Proc::ShellSpawn::WIN ? $ENV{"USERPROFILE"} : (getpwuid $<)[7])
Aresult
11
00
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"
!ll&&!rl&&r
1266012
$kind eq "\"\$" and $a[0] eq "\@"
!ll&&!rl&&r
46680012
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"
ABCresult
0XX0
10X0
1100
1111
541 1118 ▶ elsif ($q eq '$') { my $v = getvar($c, $a[0]) // return; $add->($v, 0, $split) }
Condition100%2/2
getvar($c, $a[0]) // (return)
l!l
11135
MC/DC100%1/1
getvar($c, $a[0]) // (return)
getvar($c, $a[0])
Truth table100%2/2
A
A= getvar($c, $a[0])
Aresult
11
00
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)
l!l
120
MC/DC0%0/1
getvar($c, $a[0]) // (return)
getvar($c, $a[0])
Truth table50%1/2
A
A= getvar($c, $a[0])
Aresult
11
00
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 '')
!ll&&!rl&&r
25232
not $op =~ /:/ or $v ne ""
l!l&&r!l&&!r
3112
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 ""
ABCresult
0XX0
1000
11X1
1011
546 59 ▶ if ($op =~ /^[%#]/) { # remove the smallest or largest matching suffix or prefix
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /^[%#]/) 28 31 59
547 28 ▶ getvar($c, $n) // return; # set -u (L4)
Condition100%2/2
getvar($c, $n) // (return)
l!l
271
MC/DC100%1/1
getvar($c, $n) // (return)
getvar($c, $n)
Truth table100%2/2
A
A= getvar($c, $n)
Aresult
11
00
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
BranchTrueFalseTotal
if $op =~ /^(?:%|##)\z/ 19 15 34
550 55 ▶ for my $i (@i) { my ($cut, $keep) = $op =~ /%/ ? (substr($v, $i), substr($v, 0, $i))
Branch: 1 branch
BranchTrueFalseTotal
$op =~ /%/ ? : 47 75 122
551 : (substr($v, 0, $i), substr($v, $i));
552 143 ▶ return $keep if $cut =~ $re }
Branch: 1 branch
BranchTrueFalseTotal
if $cut =~ /$re/ 28 94 122
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
BranchTrueFalseTotal
if ($n eq '@' or $n eq '*') { } 4 23 27
Condition100%3/3
$n eq "\@" or $n eq "*"
l!l&&r!l&&!r
2223
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 "*"
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($kind eq '"${' and $n eq '@' and $how eq 'argv') { } 1 3 4
Condition83%5/6
$kind eq "\"\${" and $n eq "\@" and $how eq "argv"
!ll&&!rl&&r
301
$kind eq "\"\${" and $n eq "\@"
!ll&&!rl&&r
121
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"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
$op =~ /[-=?]/ ? : 28 3 31
561 31 ▶ unless ($word) { $add->($op =~ /[-=?]/ ? $v : '', 0, $split); return $next->() }
Branch: 2 branches
BranchTrueFalseTotal
unless ($word) 4 27 31
$op =~ /[-=?]/ ? : 3 1 4
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
BranchTrueFalseTotal
if $op =~ /\?/ 6 13 19
$t ne '' ? : 4 2 6
$op =~ /:/ ? : 2 0 2
564 if $op =~ /\?/;
565 13 ▶ if ($op =~ /=/) { setvar($c, $n, $t) or return }
Branch: 2 branches
BranchTrueFalseTotal
if ($op =~ /=/) 2 11 13
setvar($c, $n, $t) or return 2 0 2
566 27 ▶ $add->($t, 0, $split); $next->() }) if !$split || $op =~ /[=?]/;
Branch: 1 branch
BranchTrueFalseTotal
if not $split or $op =~ /[=?]/ 19 8 27
Condition100%3/3
not $split or $op =~ /[=?]/
l!l&&r!l&&!r
1278
MC/DC100%2/2
not $split or $op =~ /[=?]/
not $split $op =~ /[=?]/
Truth table100%3/3
not(A) or B
A= not $splitB= $op =~ /[=?]/
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless ref $p 6 2 8
569 2 ▶ return $add->($p->[1], 0), $more->() if $p->[0] eq "'";
Branch: 1 branch
BranchTrueFalseTotal
if $p->[0] eq "'" 2 0 2
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
BranchTrueFalseTotal
ref $w ? : 2 6 8
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]
!ll&&!rl&&r
36410
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]
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $v 0 0 0
575 66 ▶ elsif ($q eq '$((') { my $v = arith($c, $a[0]); return unless defined $v; $add->($v, 0, $split) }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 11 30 41
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 "{.."
l!l&&r!l&&!r
000
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 "{.."
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$now ? : 7484 714 8198
585 6309 ▶ $now = 0; $again or return } }->(); return }
Branch: 1 branch
BranchTrueFalseTotal
$again or return 7484 7048 14532
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
BranchTrueFalseTotal
if $i > $items->$#* 1493 3736 5229
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
BranchTrueFalseTotal
() = new_pipe() or return msg($c, "pipe: $!", sub { &$k(""); } ) 36 0 36
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
BranchTrueFalseTotal
unless $eof and defined $st 36 36 72
Condition100%3/3
$eof and defined $st
!ll&&!rl&&r
34236
MC/DC100%2/2
$eof and defined $st
$eof defined $st
Truth table100%3/3
A and B
A= $eofB= defined $st
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $_[0] 36 1008 1044
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)
l!l
90
MC/DC0%0/1
getvar($c, $1) // ($unset = 0)
getvar($c, $1)
Truth table50%1/2
A
A= getvar($c, $1)
Aresult
11
00
609 41 ▶ return if $unset;
Branch: 1 branch
BranchTrueFalseTotal
if $unset 0 41 41
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
BranchTrueFalseTotal
unless $e =~ /\G\s*\z/cg 0 41 41
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
BranchTrueFalseTotal
if $Proc::ShellSpawn::AP <= $#Proc::ShellSpawn::AT 0 41 41
Condition0%0/2
$Proc::ShellSpawn::ABAD //= "syntax error"
l!l
00
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "syntax error"
$Proc::ShellSpawn::ABAD
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
619 41 ▶ return if $ADEAD; # a readonly variable: the shell is already ending
Branch: 1 branch
BranchTrueFalseTotal
if $Proc::ShellSpawn::ADEAD 1 40 41
620 40 ▶ defined $ABAD ? $err->($ABAD) : $v }
Branch: 1 branch
BranchTrueFalseTotal
defined $Proc::ShellSpawn::ABAD ? : 10 30 40
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)
l!l
911
($Proc::ShellSpawn::ABAD //= 'syntax error') && 0
!ll
01
$Proc::ShellSpawn::ABAD //= "syntax error"
l!l
01
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++]
Aresult
11
00
Truth table50%1/2
A
A= ($Proc::ShellSpawn::ABAD //= 'syntax error')
Aresult
00
11
Truth table50%1/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
627 91 ▶ return -arith_unary() if $x eq '-'; return +arith_unary() if $x eq '+';
Branch: 2 branches
BranchTrueFalseTotal
if $x eq "-" 5 86 91
if $x eq "+" 0 86 86
628 86 ▶ return !arith_unary() ? 1 : 0 if $x eq '!'; return ~arith_unary() if $x eq '~';
Branch: 3 branches
BranchTrueFalseTotal
if $x eq "!" 0 86 86
!arith_unary() ? : 0 0 0
if $x eq "~" 0 86 86
629 86 ▶ if ($x eq '(') { my $v = arith_expr(0); ($AT[$AP++] // '') eq ')' or $ABAD //= 'syntax error'; return $v }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq "(") 1 85 86
($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // "") eq ")" or $Proc::ShellSpawn::ABAD //= "syntax error" 1 0 1
Condition25%1/4
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // ""
l!l
10
$Proc::ShellSpawn::ABAD //= "syntax error"
l!l
00
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++]
Aresult
11
00
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
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
BranchTrueFalseTotal
if $x =~ /^[0-9]/ 77 8 85
$x =~ /^0[xX]/ ? : 0 77 77
$x =~ /^0/ ? : 15 62 77
631 8 ▶ if ($x =~ /^[A-Za-z_]/) { my $v = var($AC, $x); $v = 0 if $v =~ /^\s*\z/;
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /^[A-Za-z_]/) 8 0 8
if $v =~ /^\s*\z/ 0 8 8
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
BranchTrueFalseTotal
unless ($v =~ /^\s*[-+]?[0-9]+\s*\z/) 0 8 8
unless $Proc::ShellSpawn::ASKIP 0 0 0
Condition0%0/2
$Proc::ShellSpawn::ABAD //= "${x}: not a number"
l!l
00
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "${x}: not a number"
$Proc::ShellSpawn::ABAD
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
633 22 return $v + 0 }
634 14 ▶ $ABAD //= 'syntax error'; 0 }
Condition0%0/2
$Proc::ShellSpawn::ABAD //= "syntax error"
l!l
00
MC/DC0%0/1
$Proc::ShellSpawn::ABAD //= "syntax error"
$Proc::ShellSpawn::ABAD
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
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
BranchTrueFalseTotal
if (not $min and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP] // "") =~ /^[A-Za-z_]/ and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP + 1] // "") =~ m[^(?:<<|>>|[-+*/%&^|])?=\z]) 5 87 92
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]
!ll&&!rl&&r
7985
not $min and ($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP] // "") =~ /^[A-Za-z_]/
!ll&&!rl&&r
433613
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP] // ""
l!l
490
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP + 1] // ""
l!l
130
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]
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if $o =~ /^\s*\z/ 1 4 5
641 12 ▶ ($op =~ m{^[/%]\z} && !$r) ? ($ABAD //= 'division by zero') : $op ne '' and $r = eval "\$o $op \$r";
Branch: 2 branches
BranchTrueFalseTotal
$op =~ m[^[/%]\z] && !$r ? $Proc::ShellSpawn::ABAD //= "division by zero" : $op ne "" and $r = eval "\$o $op \$r" 3 2 5
$op =~ m[^[/%]\z] && !$r ? : 0 5 5
Condition20%1/5
$op =~ m[^[/%]\z] and not $r
!ll&&!rl&&r
500
$Proc::ShellSpawn::ABAD //= "division by zero"
l!l
00
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
ABresult
0X0
100
111
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
642 12 ▶ $ASKIP or $ADEAD or setvar($AC, $n, $r) or $ADEAD = 1; return $r }
Branch: 1 branch
BranchTrueFalseTotal
$Proc::ShellSpawn::ASKIP or $Proc::ShellSpawn::ADEAD or setvar($Proc::ShellSpawn::AC, $n, $r) or $Proc::ShellSpawn::ADEAD = 1 4 1 5
Condition50%3/6
$Proc::ShellSpawn::ASKIP or $Proc::ShellSpawn::ADEAD or setvar($Proc::ShellSpawn::AC, $n, $r)
l!l&&r!l&&!r
041
$Proc::ShellSpawn::ASKIP or $Proc::ShellSpawn::ADEAD
l!l&&r!l&&!r
005
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)
ABCresult
1XX1
01X1
0011
0000
643 102 my $l = arith_unary();
644 102 ▶ while (defined(my $op = $AT[$AP])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $op = $Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP])) 50 81 131
645 57 ▶ if ($op eq '?' && $min <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "?" and $min <= 0) 1 49 50
Condition66%2/3
$op eq "?" and $min <= 0
!ll&&!rl&&r
4901
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
ABresult
0X0
100
111
646 8 ▶ $AP++; my $a = do { local $ASKIP = $ASKIP || !$l; arith_expr(0) };
Condition33%1/3
$Proc::ShellSpawn::ASKIP || !$l
l!l&&r!l&&!r
001
MC/DC0%0/2
$Proc::ShellSpawn::ASKIP || !$l
$Proc::ShellSpawn::ASKIP !$l
Truth table33%1/3
A || not(B)
A= $Proc::ShellSpawn::ASKIPB= !$l
ABresult
1X1
011
000
647 8 ▶ ($AT[$AP++] // '') eq ':' or $ABAD //= 'syntax error';
Branch: 1 branch
BranchTrueFalseTotal
($Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // "") eq ":" or $Proc::ShellSpawn::ABAD //= "syntax error" 1 0 1
Condition25%1/4
$Proc::ShellSpawn::AT[$Proc::ShellSpawn::AP++] // ""
l!l
10
$Proc::ShellSpawn::ABAD //= "syntax error"
l!l
00
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++]
Aresult
11
00
Truth table0%0/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
648 8 ▶ my $b = do { local $ASKIP = $ASKIP || $l; arith_expr(0) }; $l = $l ? $a : $b; next }
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 1 0 1
Condition33%1/3
$Proc::ShellSpawn::ASKIP || $l
l!l&&r!l&&!r
010
MC/DC0%0/2
$Proc::ShellSpawn::ASKIP || $l
$Proc::ShellSpawn::ASKIP $l
Truth table33%1/3
A || B
A= $Proc::ShellSpawn::ASKIPB= $l
ABresult
1X1
011
000
649 56 ▶ my $pr = $bin{$op}; last unless defined $pr && $pr >= $min; $AP++;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pr and $pr >= $min 6 43 49
Condition100%3/3
defined $pr and $pr >= $min
!ll&&!rl&&r
3343
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
ABresult
0X0
100
111
650 50 ▶ my $r = do { local $ASKIP = $ASKIP || ($op eq '&&' ? !$l : $op eq '||' ? $l : 0); arith_expr($pr + 1) };
Branch: 2 branches
BranchTrueFalseTotal
$op eq '&&' ? : 2 38 40
$op eq '||' ? : 2 36 38
Condition100%3/3
$Proc::ShellSpawn::ASKIP || ($op eq '&&' ? !$l : ($op eq '||' ? $l : 0))
l!l&&r!l&&!r
3238
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))
ABresult
1X1
011
000
651 50 ▶ if ($op eq '&&') { $l = $l && $r ? 1 : 0 } elsif ($op eq '||') { $l = $l || $r ? 1 : 0 }
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq '&&') { } 2 41 43
elsif ($op eq '||') { } 2 39 41
elsif ($op =~ m[^[/%]\z] and not $r) { } 12 27 39
$l && $r ? : 0 2 2
$l || $r ? : 2 0 2
Condition66%4/6
$l and $r
!ll&&!rl&&r
110
$l or $r
l!l&&r!l&&!r
110
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
ABresult
0X0
100
111
Truth table66%2/3
A or B
A= $lB= $r
ABresult
1X1
011
000
652 19 ▶ elsif ($op =~ m{^[/%]\z} && !$r) { $ABAD //= 'division by zero' unless $ASKIP; $l = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSpawn::ASKIP 9 3 12
Condition80%4/5
$op =~ m[^[/%]\z] and not $r
!ll&&!rl&&r
24312
$Proc::ShellSpawn::ABAD //= "division by zero"
l!l
09
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
ABresult
0X0
100
111
Truth table50%1/2
A
A= $Proc::ShellSpawn::ABAD
Aresult
11
00
653 34 ▶ else { $l = eval "\$l $op \$r" ; $l = $l ? 1 : 0 if $op =~ /^[<>=!]=?\z|^[<>]\z/ } }
Branch: 2 branches
BranchTrueFalseTotal
if $op =~ /^[<>=!]=?\z|^[<>]\z/ 1 26 27
$l ? : 1 0 1
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] // []
l!l
246778
MC/DC100%1/1
$_[0] // []
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
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
BranchTrueFalseTotal
if not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"} 8 2467 2475
Condition88%8/9
not $c->{"intrap"} and $p && @$p || $c->{"sh"}{"tbusy"}
!ll&&!rl&&r
3024378
$p and @$p or $c->{"sh"}{"tbusy"}
l!l&&r!l&&!r
802437
$p and @$p
!ll&&!rl&&r
20783598
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"}
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
666 2453 ▶ return defer($k, $st) if $i > $#$l;
Branch: 1 branch
BranchTrueFalseTotal
if $i > $l->$#* 792 1675 2467
667 889 ▶ x_andor($c, $l->[$i++], $i > $#$l ? $tail : undef, $me) }->(0) }
Branch: 1 branch
BranchTrueFalseTotal
$i > $l->$#* ? : 834 841 1675
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
BranchTrueFalseTotal
if $ao->[-1] eq "&" 37 1675 1712
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
BranchTrueFalseTotal
$i > 0 and $i <= $ao->$#* and ($$ao[$i - 1] eq "&&") != ($st == 0) and do { $i += 2 } 12 3324 3336
Condition100%6/6
$i > 0 and $i <= $ao->$#* and ($$ao[$i - 1] eq "&&") != ($st == 0)
!ll&&!rl&&r
32507412
$i > 0 and $i <= $ao->$#*
!ll&&!rl&&r
1675157586
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)
ABCresult
0XX0
10X0
1100
1111
675 3309 ▶ if ($i > $#$ao) { # set -e: the last pipeline failed, not negated, not in a condition
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $ao->$#*) 1575 1749 3324
676 1568 ▶ return leave($c, $st) if $st && $c->{sh}{opt}{e} && !$c->{cond} && $ran == $#$ao && ref $ao->[-1][0];
Branch: 1 branch
BranchTrueFalseTotal
if $st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#* and ref $ao->[-1][0] 6 1569 1575
Condition91%11/12
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#* and ref $ao->[-1][0]
!ll&&!rl&&r
156816
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"} and $ran == $ao->$#*
!ll&&!rl&&r
156807
$st and $c->{"sh"}{"opt"}{"e"} and not $c->{"cond"}
!ll&&!rl&&r
156627
$st and $c->{"sh"}{"opt"}{"e"}
!ll&&!rl&&r
13821849
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]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
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
BranchTrueFalseTotal
$i > $ao->$#* ? : 1664 85 1749
$i > $ao->$#* ? : 1664 85 1749
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
BranchTrueFalseTotal
my $null = open_end($c, "/dev/null", "<") or return msg($c, "/dev/null: $!", done($k, 2)) 37 0 37
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"} // []
l!l
1116
MC/DC100%1/1
$job->{"waiters"} // []
$job->{"waiters"}
Truth table100%2/2
A
A= $job->{"waiters"}
Aresult
11
00
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
BranchTrueFalseTotal
if $neg 4 1745 1749
Condition66%2/3
!ref($cmd[0]) && shift @cmd
!ll&&!rl&&r
174504
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$neg ? : 4 1645 1649
$_[0] ? : 1 3 4
700 1741 ▶ return x_cmd($c, $cmd[0], $tail, $kk) if @cmd == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @cmd == 1 1647 102 1749
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
BranchTrueFalseTotal
@{$ends[-1];} or return msg($c, "pipe: $!", sub { &$kk(2); } ) 106 0 106
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
BranchTrueFalseTotal
if $j 106 102 208
if $j < $#cmd 106 102 208
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
BranchTrueFalseTotal
unless --$left 101 105 206
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
BranchTrueFalseTotal
if $x->{"line"} 5 1884 1889
715 1881 ▶ return x_simple($c, $x, $tail, $k) if $x->{argv};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"argv"} 1464 425 1889
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
BranchTrueFalseTotal
if exists $x->{"cd"} 64 361 425
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
BranchTrueFalseTotal
if $x->{"set"} 131 230 361
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
BranchTrueFalseTotal
if exists $x->{"rest"} 2 228 230
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
BranchTrueFalseTotal
if (my($h) = $x->{"ext"} // map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))) 45 183 228
Condition66%2/3
$x->{"ext"} // map($Proc::ShellSpawn::KIND{$_}, grep(exists $x->{$_}, sort(keys %Proc::ShellSpawn::KIND)))
l!l&&r!l&&!r
047181
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)))
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (my $l = $x->{"group"}) 72 108 180
725 108 ▶ if (my $l = $x->{sub}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $x->{"sub"}) 40 68 108
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 // []
l!l
1426
MC/DC100%1/1
$tail // []
$tail
Truth table100%2/2
A
A= $tail
Aresult
11
00
728 68 ▶ return x_if($c, $x->{if}, $tail, $k) if $x->{if};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"if"} 8 60 68
729 60 ▶ return x_while($c, $x, $k) if $x->{while} || $x->{until};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"while"} or $x->{"until"} 14 46 60
Condition100%3/3
$x->{"while"} or $x->{"until"}
l!l&&r!l&&!r
13146
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"}
ABresult
1X1
011
000
730 46 ▶ return x_for($c, $x, $k) if exists $x->{for};
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{"for"} 27 19 46
731 19 ▶ return x_case($c, $x, $tail, $k) if exists $x->{case};
Branch: 1 branch
BranchTrueFalseTotal
if exists $x->{"case"} 19 0 19
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
BranchTrueFalseTotal
if $i > $arms->$#* 4 9 13
738 9 ▶ return x_list($c, $arms->[$i], $tail, $k) if $i == $#$arms; # else
Branch: 1 branch
BranchTrueFalseTotal
if $i == $arms->$#* 0 9 9
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
BranchTrueFalseTotal
$_[0] ? : 5 4 9
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
BranchTrueFalseTotal
@_ ? : 4 28 32
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
BranchTrueFalseTotal
($_[0] == 0) != $until ? : 32 11 43
Condition66%2/3
$x->{"while"} // $x->{"until"}
l!l&&r!l&&!r
4030
MC/DC0%0/2
$x->{"while"} // $x->{"until"}
$x->{"while"} $x->{"until"}
Truth table66%2/3
A // B
A= $x->{"while"}B= $x->{"until"}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless @w 17 49 66
763 27 ▶ setvar($c, $x->{for}, shift @w) or return; x_list($c, $x->{do}, undef, $next) }) }) }
Branch: 1 branch
BranchTrueFalseTotal
setvar($c, $x->{"for"}, shift @w) or return 49 0 49
Condition50%1/2
$x->{"in"} // [[["\"\$", "\@"]]]
l!l
270
MC/DC0%0/1
$x->{"in"} // [[["\"\$", "\@"]]]
$x->{"in"}
Truth table50%1/2
A
A= $x->{"in"}
Aresult
11
00
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
BranchTrueFalseTotal
unless @in 1 19 20
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
BranchTrueFalseTotal
unless @p 2 318 320
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
BranchTrueFalseTotal
$s =~ /$_[0]/ ? : 17 301 318
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
BranchTrueFalseTotal
ref $w ? : 34 311 345
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
BranchTrueFalseTotal
if $i > $#parts 345 363 708
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 }
l!l&&r!l&&!r
34500
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 }
ABresult
1X1
011
000
778 if $i > $#parts;
779 363 my $x = $parts[$i++];
780 363 ▶ return $g .= glob_quote($x), $next->() unless ref $x;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 319 44 363
781 44 ▶ if ($x->[0] eq '*') { $g .= $x->[1]; return $next->() }
Branch: 1 branch
BranchTrueFalseTotal
if ($x->[0] eq "*") 34 10 44
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
BranchTrueFalseTotal
$x->[0] =~ /^"/ ? : 3 7 10
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
BranchTrueFalseTotal
if ($g =~ /\G(?:(\*)|(\?)|\[([!^]?)(\]?(?:\\.|\[:[a-z]+:\]|[^\]\\])*)\]|\\(.)|(.))/cgs) 1465 345 1810
786 1465 ▶ $re .= defined $1 ? '.*' : defined $2 ? '.' : defined $4 ? bracket_re($3, $4) : quotemeta($5 // $6) }
Branch: 3 branches
BranchTrueFalseTotal
defined $1 ? : 19 1446 1465
defined $2 ? : 2 1444 1446
defined $4 ? : 13 1431 1444
Condition100%3/3
$5 // $6
l!l&&r!l&&!r
5140917
MC/DC100%2/2
$5 // $6
$5 $6
Truth table100%3/3
A // B
A= $5B= $6
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($b =~ /\G(?:(\[:[a-z]+:\])|\\(.)|(-)|(.))/cgs) 17 13 30
defined $1 ? : 1 16 17
defined $3 ? : 1 15 16
Condition66%2/3
$2 // $4
l!l&&r!l&&!r
3120
MC/DC0%0/2
$2 // $4
$2 $4
Truth table66%2/3
A // B
A= $2B= $4
ABresult
1X1
011
000
791 13 ▶ '[' . ($neg ? '^' : '') . $o . ']' }
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 3 10 13
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
BranchTrueFalseTotal
if $sh->{"ro"}{$n} 2 712 714
796 720 ▶ $sh->{exp}{$n} = 1 if $sh->{opt}{a}; $sh->{vars}{$n} = $v; 1 }
Branch: 1 branch
BranchTrueFalseTotal
if $sh->{"opt"}{"a"} 1 711 712
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
BranchTrueFalseTotal
unless (@s) 127 430 557
if $Proc::ShellSpawn::ONBUILTIN 0 127 127
Condition100%2/2
$c->{"sh"}{"qsub"} // 0
l!l
24103
MC/DC100%1/1
$c->{"sh"}{"qsub"} // 0
$c->{"sh"}{"qsub"}
Truth table100%2/2
A
A= $c->{"sh"}{"qsub"}
Aresult
11
00
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
BranchTrueFalseTotal
setvar($c, $n, shift()) or return 428 1 429
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
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 63 63
$x->{'cd_p'} ? : 0 0 0
810 71 ▶ my $d = @f ? $f[0] : var($c, 'HOME');
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 60 3 63
811 71 ▶ my $dash = @f == 1 && $d eq '-' and $d = var($c, 'OLDPWD'); # cd -: back, and print where
Branch: 1 branch
BranchTrueFalseTotal
my $dash = @f == 1 && $d eq "-" and $d = var($c, "OLDPWD") 4 59 63
Condition100%3/3
@f == 1 && $d eq '-'
!ll&&!rl&&r
5544
MC/DC100%2/2
@f == 1 && $d eq '-'
@f == 1 $d eq '-'
Truth table100%3/3
A && B
A= @f == 1B= $d eq '-'
ABresult
0X0
100
111
812 71 ▶ return defer($k, 0) if @f == 1 && $d eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @f == 1 and $d eq "" 0 63 63
Condition66%2/3
@f == 1 and $d eq ""
!ll&&!rl&&r
5580
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 ""
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $x->{"cd_extra"} or @f > 1 4 59 63
Condition100%3/3
$x->{"cd_extra"} or @f > 1
l!l&&r!l&&!r
2259
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless @f or isset($c, "HOME") 1 58 59
Condition100%3/3
@f or isset($c, "HOME")
l!l&&r!l&&!r
5621
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")
ABresult
1X1
011
000
816 66 ▶ return defer($k, 0) if !@f && $d eq ''; # HOME empty: nothing, as both shells (X45)
Branch: 1 branch
BranchTrueFalseTotal
if not @f and $d eq "" 1 57 58
Condition100%3/3
not @f and $d eq ""
!ll&&!rl&&r
5611
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 ""
ABresult
0X0
100
111
817 57 ▶ if ($d =~ /^-/ && !$dash) { return msg($c, "cd: bad argument", done($k, 2)) }
Branch: 1 branch
BranchTrueFalseTotal
if ($d =~ /^-/ and not $dash) 1 56 57
Condition66%2/3
$d =~ /^-/ and not $dash
!ll&&!rl&&r
5601
MC/DC50%1/2
$d =~ /^-/ and not $dash
$d =~ /^-/ not $dash
Truth table66%2/3
A and not(B)
A= $d =~ /^-/B= not $dash
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($x->{'cd_p'}) { } 3 53 56
Condition66%2/3
-d $new && Cwd::realpath($new)
!ll&&!rl&&r
102
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$Proc::ShellSpawn::WIN && $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s ? : 0 53 53
Condition33%1/3
$Proc::ShellSpawn::WIN and $new =~ m(^([A-Za-z]:|[/\\]{2}[^/\\]+[/\\][^/\\]+)(.*))s
!ll&&!rl&&r
5300
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
ABresult
0X0
100
111
822 53 ▶ my @p; for (split $SEP, $rest) { next if $_ eq '' or $_ eq '.'; $_ eq '..' ? pop @p : push @p, $_ }
Branch: 2 branches
BranchTrueFalseTotal
if $_ eq "" or $_ eq "." 42 120 162
$_ eq '..' ? : 2 118 120
Condition66%2/3
$_ eq "" or $_ eq "."
l!l&&r!l&&!r
420120
MC/DC50%1/2
$_ eq "" or $_ eq "."
$_ eq "" $_ eq "."
Truth table66%2/3
A or B
A= $_ eq ""B= $_ eq "."
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$new and -d $new and $Proc::ShellSpawn::WIN || -x _ or return msg($c, "cd: can't cd to $d", done($k, 2)) 49 7 56
Condition88%8/9
$new and -d $new and $Proc::ShellSpawn::WIN || -x _
!ll&&!rl&&r
6149
$new and -d $new
!ll&&!rl&&r
1550
$Proc::ShellSpawn::WIN or -x _
l!l&&r!l&&!r
0491
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 _
ABCDresult
0XXX0
10XX0
11000
111X1
11011
825 57 ▶ setvar($c, OLDPWD => $c->{sh}{cwd}) && setvar($c, PWD => $new) or return; $c->{sh}{cwd} = $new;
Branch: 1 branch
BranchTrueFalseTotal
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) and setvar($c, "PWD", $new) or return 49 0 49
Condition33%1/3
setvar($c, "OLDPWD", $c->{"sh"}{"cwd"}) and setvar($c, "PWD", $new)
!ll&&!rl&&r
0049
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)
ABresult
0X0
100
111
826 64 ▶ $dash ? put($c, 1, "$new\n", done($k, 0)) : defer($k, 0) };
Branch: 1 branch
BranchTrueFalseTotal
$dash ? : 4 45 49
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
BranchTrueFalseTotal
defined $x->{'cd'} ? : 61 3 64
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
BranchTrueFalseTotal
if $x->{"exec"} 3 1461 1464
832 1456 ▶ my @env = @{$x->{env} // []}; my %env;
Condition100%2/2
$x->{"env"} // []
l!l
181446
MC/DC100%1/1
$x->{"env"} // []
$x->{"env"}
Truth table100%2/2
A
A= $x->{"env"}
Aresult
11
00
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
BranchTrueFalseTotal
unless @env 1464 321 1785
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
BranchTrueFalseTotal
if exists $v->{"sh"}{"qsub"} 2 319 321
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
BranchTrueFalseTotal
unless ($m) 23 1428 1451
@argv && $Proc::ShellSpawn::SPECIAL{$argv[0]} ? : 4 19 23
Condition100%3/3
@argv and $Proc::ShellSpawn::SPECIAL{$argv[0]}
!ll&&!rl&&r
3164
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]}
ABresult
0X0
100
111
846 1420 ▶ unless (@argv) { release($_) for @$opened; return defer($k, $c->{sh}{qsub} // 0) }
Branch: 1 branch
BranchTrueFalseTotal
unless (@argv) 4 1424 1428
Condition100%2/2
$c->{"sh"}{"qsub"} // 0
l!l
13
MC/DC100%1/1
$c->{"sh"}{"qsub"} // 0
$c->{"sh"}{"qsub"}
Truth table100%2/2
A
A= $c->{"sh"}{"qsub"}
Aresult
11
00
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
BranchTrueFalseTotal
if (my $e = $c->{"sh"}{"cmd"}{$argv[0]} // ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))) 502 922 1424
$x->{'fn'} ? : 2 1388 1390
Condition100%3/3
$c->{"sh"}{"cmd"}{$argv[0]} // ($x->{"fn"} ? ["Proc::ShellSpawn::Large::b_late"] : cmd_of($argv[0]))
l!l&&r!l&&!r
34468922
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]))
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $Proc::ShellSpawn::ONBUILTIN 0 502 502
851 502 ▶ if ($SPECIAL{$argv[0]}) { setvar($c, $_, $env{$_}) or return for sort keys %env; %env = () } # these settings stay
Branch: 2 branches
BranchTrueFalseTotal
if ($Proc::ShellSpawn::SPECIAL{$argv[0]}) 161 341 502
setvar($c, $_, $env{$_}) or return 1 0 1
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
BranchTrueFalseTotal
if $argv[0] eq "printf" 33 889 922
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
BranchTrueFalseTotal
if $node and $c->{"sh"}{"job"} 43 879 922
Condition83%5/6
$node and $c->{"sh"}{"job"}
!ll&&!rl&&r
64623343
$c->{"sh"}{"job"}{"first"} //= $node->{"pid"}
l!l&&r!l&&!r
8350
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"}
ABresult
0X0
100
111
Truth table66%2/3
A //= B
A= $c->{"sh"}{"job"}{"first"}B= $node->{"pid"}
ABresult
1X1
011
000
856 1456 ▶ release($_) for @$opened; after_start($tail) }) }) }) }
Condition100%2/2
$x->{"redir"} // []
l!l
961355
MC/DC100%1/1
$x->{"redir"} // []
$x->{"redir"}
Truth table100%2/2
A
A= $x->{"redir"}
Aresult
11
00
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
BranchTrueFalseTotal
($a[1] // '') eq '--' ? : 0 33 33
Condition50%1/2
$a[1] // ""
l!l
330
MC/DC0%0/1
$a[1] // ""
$a[1]
Truth table50%1/2
A
A= $a[1]
Aresult
11
00
862 33 ▶ return @a unless defined $a[$i] && $a[$i] !~ /^-/; # printf -v ...: the program's, as decided (Q2)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a[$i] and not $a[$i] =~ /^-/ 0 33 33
Condition33%1/3
defined $a[$i] and not $a[$i] =~ /^-/
!ll&&!rl&&r
0033
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] =~ /^-/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
defined $cv && $cv =~ /^[scb]\z/ ? : 14 10 24
Condition100%3/3
defined $cv and $cv =~ /^[scb]\z/
!ll&&!rl&&r
1914
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/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
defined $v and $v =~ /^\+?[0-9]+\z/ and $v <= 2147483647 and $v >= $min 38 4 42
Condition66%4/6
defined $v and $v =~ /^\+?[0-9]+\z/ and $v <= 2147483647
!ll&&!rl&&r
4038
defined $v and $v =~ /^\+?[0-9]+\z/
!ll&&!rl&&r
0438
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless @a 0 17 17
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
BranchTrueFalseTotal
unless ok_num($a[0], 0) 1 16 17
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
BranchTrueFalseTotal
@a ? : 7 9 16
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
BranchTrueFalseTotal
unless ok_num($j, 1) 0 16 16
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
BranchTrueFalseTotal
if $j > @$l 6 10 16
882 10 release_all(map $_->{scope}, @$l[$#$l - $j + 1 .. $#$l]);
883 10 ▶ defer($l->[-$j]{$n eq 'break' ? 'brk' : 'cont'}) }
Branch: 1 branch
BranchTrueFalseTotal
$n eq 'break' ? : 4 6 10
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
BranchTrueFalseTotal
if (@a and $a[0] =~ /^-(r*)(p?)\z/ and "$1$2" ne "") 8 51 59
if $2 3 5 8
Condition77%7/9
@a and $a[0] =~ /^-(r*)(p?)\z/ and "$1$2" ne ""
!ll&&!rl&&r
5108
@a and $a[0] =~ /^-(r*)(p?)\z/
!ll&&!rl&&r
0518
$raw ||= $1 ne ""
l!l&&r!l&&!r
152
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 ""
ABCresult
0XX0
10X0
1100
1111
Truth table100%3/3
A ||= B
A= $rawB= $1 ne ""
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless @a 0 51 51
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
BranchTrueFalseTotal
unless /^[A-Za-z_][A-Za-z0-9_]*\z/ 1 68 69
897 75 ▶ return handler("Proc::ShellSpawn::Large::unsupported")->($c, "the name '$_' in 'read'")
Branch: 1 branch
BranchTrueFalseTotal
unless Proc::ShellSubset::settable($_) 0 68 68
898 unless Proc::ShellSubset::settable($_);
899 75 ▶ return msg($c, "read: $_: is read only", done($k, 2)) if $c->{sh}{ro}{$_} }
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"sh"}{"ro"}{$_} 1 67 68
900 56 ▶ my $e = $m->{0} or return defer($k, 1);
Branch: 1 branch
BranchTrueFalseTotal
my $e = $m->{0} or return defer($k, 1) 48 1 49
901 55 ▶ my $ifs = $env->{IFS} // $c->{sh}{vars}{IFS} // " \t\n";
Condition60%3/5
($env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}) // " \t\n"
l!l
480
$env->{"IFS"} // $c->{"sh"}{"vars"}{"IFS"}
l!l&&r!l&&!r
9390
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"}
ABresult
1X1
011
000
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 '\\'
l!l&&r!l&&!r
111170
MC/DC0%0/2
$raw || $_ ne '\\'
$raw $_ ne '\\'
Truth table66%2/3
A || B
A= $rawB= $_ ne '\\'
ABresult
1X1
011
000
907 55 ▶ my $W = length $ws ? qr/[$ws]*+/ : qr//; # IFS blanks, as many as there are
Branch: 1 branch
BranchTrueFalseTotal
length $ws ? : 42 6 48
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
BranchTrueFalseTotal
length $nws ? : 8 40 48
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
BranchTrueFalseTotal
length $nws ? : 8 40 48
910 55 ▶ my $unit = $raw ? qr/./s : qr/\\.|[^\\]/s;
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 5 43 48
911 55 ▶ my $field = length "$ws$nws" ? qr/(?:(?![$ws$nws])$unit)*+/ : qr/(?:$unit)*+/; # units up to an unprotected IFS character
Branch: 1 branch
BranchTrueFalseTotal
length "$ws$nws" ? : 47 1 48
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
BranchTrueFalseTotal
$raw ? : 7 59 66
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
BranchTrueFalseTotal
unless $raw 43 5 48
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
BranchTrueFalseTotal
$line =~ /^($field)$end/ or $line =~ /^((?:$unit)*?)$W\z/ 41 7 48
921 55 setvar($c, $a[-1], $val->($1));
922 55 ▶ defer($k, $eof ? 1 : 0) };
Branch: 1 branch
BranchTrueFalseTotal
$eof ? : 8 40 48
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
BranchTrueFalseTotal
unless defined $b 8 777 785
926 779 ▶ if ($b eq "\n") { # continued if the line ends in an odd number of backslashes
Branch: 1 branch
BranchTrueFalseTotal
if ($b eq "\n") 40 737 777
927 42 ▶ return $got->(0) if $raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0 40 0 40
Condition66%2/3
$raw or ($line =~ /(\\*)\z/)[0] =~ tr/\\// % 2 == 0
l!l&&r!l&&!r
5350
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
defined $prompt && $e->{'fh'} && -t $e->{'fh'} ? : 0 48 48
Condition66%4/6
defined $prompt and $e->{"fh"} and -t $e->{"fh"}
!ll&&!rl&&r
4530
defined $prompt and $e->{"fh"}
!ll&&!rl&&r
4503
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"}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if defined $p and is_abs($p) and files_eq($p, ".") 549 2 551
Condition50%3/6
defined $p and is_abs($p) and files_eq($p, ".")
!ll&&!rl&&r
02549
defined $p and is_abs($p)
!ll&&!rl&&r
00551
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, ".")
ABCresult
0XX0
10X0
1100
1111
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"
l!l
0548
MC/DC0%0/1
$ENV{"PROC_SHELLSPAWN_ENVNAMES"} // "block"
$ENV{"PROC_SHELLSPAWN_ENVNAMES"}
Truth table50%1/2
A
A= $ENV{"PROC_SHELLSPAWN_ENVNAMES"}
Aresult
11
00
951 545 ▶die "PROC_SHELLSPAWN_ENVNAMES: '$ENV_NAMES' is neither block nor upper\n" unless $ENV_NAMES =~ /\A(?:block|upper)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Proc::ShellSpawn::ENV_NAMES =~ /\A(?:block|upper)\z/ 0 548 548
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
BranchTrueFalseTotal
unless $Proc::ShellSpawn::WIN and $Proc::ShellSpawn::ENV_NAMES eq "block" and defined &Proc::Spawner::__win_env_names 551 0 551
Condition33%2/6
$Proc::ShellSpawn::WIN and $Proc::ShellSpawn::ENV_NAMES eq "block" and defined &Proc::Spawner::__win_env_names
!ll&&!rl&&r
55100
$Proc::ShellSpawn::WIN and $Proc::ShellSpawn::ENV_NAMES eq "block"
!ll&&!rl&&r
55100
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
ABCresult
0XX0
10X0
1100
1111
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 $_} // $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$name{uc $_} // $_
$name{uc $_} $_
Truth table0%0/3
A // B
A= $name{uc $_}B= $_
ABresult
1X1
011
000
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()
l!l&&r!l&&!r
05570
MC/DC0%0/2
$o{"parser"} // default_parser()
$o{"parser"} default_parser()
Truth table33%1/3
A // B
A= $o{"parser"}B= default_parser()
ABresult
1X1
011
000
958 552 ▶ my $tree = ref $s ? $s : $parse->($s);
Branch: 1 branch
BranchTrueFalseTotal
ref $s ? : 0 557 557
959 551 ▶ return (undef, $tree) if ref $tree eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tree eq "HASH" 6 551 557
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"} // []
l!l
53615
$o{"opt"} // {}
l!l
0551
$o{"interactive"} // "nop"
l!l
0551
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"}
Aresult
11
00
Truth table50%1/2
A
A= $o{"opt"}
Aresult
11
00
Truth table50%1/2
A
A= $o{"interactive"}
Aresult
11
00
967 cmd => {}, ro => {}, trap => {}, jobl => [], umask => umask,
968 546 ▶ alias => {}, hash => {}, intext => 0, interactive => $o{interactive} // 'nop' };
Branch: 1 branch
BranchTrueFalseTotal
$Proc::Spawner::WIN ? : 0 551 551
969 546 my $st;
970 546 ▶ my $c = { sh => $sh, loops => [], map => { map +($_ => is_open($_) ? own_fd($_) : undef), 0 .. 2 } };
Branch: 1 branch
BranchTrueFalseTotal
is_open($_) ? : 1653 0 1653
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()
l!l&&r!l&&!r
05510
MC/DC0%0/2
$st //= shift()
$st shift()
Truth table33%1/3
A //= B
A= $stB= shift()
ABresult
1X1
011
000
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()
l!l&&r!l&&!r
000
MC/DC0%0/2
$st //= shift()
$st shift()
Truth table0%0/3
A //= B
A= $stB= shift()
ABresult
1X1
011
000
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;
« blib/lib/Proc/Spawner/Loop/Win32.pm ↑ Summary lib/Proc/Spawner/Loop/POSIX.pm »