| 1 | package Proc::ShellSubset::Small; # Proc::ShellSubset with its options frozen (see doc/parsers/shell-subset-spec.md, section 9) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Proc::ShellSubset::Small::parse($string) returns a List, or { error => '...', pos => N, last => N, tree => List }: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # 'last' is the position after the last top-level ';', '&' or newline, 'tree' the part parsed so far, with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # { ERROR => 1 } where parsing failed (an 'exec' in the wrong place gets ERROR => 1 in its own hash; an 'exec' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # not checked yet when parsing failed has exec => its position, which may be 0: test the key with exists). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Frozen options, each at the value that leaves the least code: no if, while, until, for, case, read (so no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # break, continue), no brace expansion, no ${x:-w} forms, no commands with only settings, no ~ after NAME= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # in arguments; ^ and $PWD accepted, no checker, an empty string accepted (an empty List), multi-digit fds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # accepted (as bash reads them; dash reads '10>f' as the argument 10 and a redirection). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # List = [ AndOr, ... ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # AndOr = [ Pipeline, '&&' | '||', Pipeline, ..., '&' (only if in background) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Pipeline = [ '!' (only if negated), Command, ... ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # Command = { argv => [Word, ...], env => [NAME, Word, ...], redir => [Redir, ...], exec => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # | { sub => List, redir => [...] } | { group => List, redir => [...] } | { cd => Word | undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # (keys only when non-empty; argv->[0] is a plain string; cd alone has cd => undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Redir = [ fd, op, Word ] (for <& and >&: [ fd, op, 'digit or -' ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Word = 'literal text' | [ Part, ... ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Part = 'literal text' | [ '$', NAME or '?' or '!' ] | [ '$((', 'expr' ] | [ '$(', List ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # | the same three with '"' in front ('"$' ...) when inside double quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # | [ '~', 'user' or '' ] | [ '*', 'pattern text' ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | our ($M, @OPEN, $ATT, $LAST); # position map of a backquote's inside; arrays being filled (for the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # partial tree); how many of them are in the tree; end of the last top-level chain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my %KW = map +($_ => 1), qw(if then else elif fi case esac for while until do done in [[ ]] function select coproc !); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my %BI = map +($_ => 1), qw(. break continue eval export readonly return set shift times trap unset alias | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | unalias read wait umask ulimit jobs fg bg command getopts hash type fc chdir local source let declare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | typeset shopt enable builtin caller dirs pushd popd disown mapfile readarray suspend logout help | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | history bind compgen complete compopt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my %SH = map +($_ => 1), qw(IFS PS1 PS2 PS4 OPTIND PPID OLDPWD LINENO _ BASH BASHOPTS BASHPID DIRSTACK | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | EPOCHREALTIME EPOCHSECONDS EUID FUNCNAME GROUPS HISTCMD HOSTTYPE MACHTYPE OPTERR OSTYPE PIPESTATUS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | POSIXLY_CORRECT RANDOM SECONDS SHELLOPTS SHLVL SRANDOM UID); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $NM = qr/[A-Za-z_][A-Za-z0-9_]*/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | my $END = qr/(?=[ \t\n;&|()<>]|\z)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $B = qr/(?:[ \t]|\\\n|#.*)*+/; # blanks, line continuations, a comment | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | my $BN = qr/(?:[ \t\n]|\\\n|#.*)*+/; # the same, and newlines | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $PIECE = qr/\G(?: '(?<sq>[^']*)' | (?<dq>") | \\(?<bs>.) | (?<ex>[\$`]) | (?<gl>[*?]) | (?<br>\[) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | | (?<ti>~) | (?<lit>(?:\{\}|[^ \t\n;&|()<>'"\\\$`*?\[{}~\x00-\x1f\x7f])+) | (?<bad>.) )/sx; # {} is literal (C2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $ARITH = qr{(?(DEFINE) # the expression grammar of $((...)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | (?<w> [ \t\n]* ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | (?<num> (?: 0[xX][0-9a-fA-F]+ | 0[0-7]* | [1-9][0-9]* ) (?![0-9A-Za-z_]) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | (?<atom> (?&w) (?: [-+!~] (?&w) )* (?: (?&num) | \$? [A-Za-z_][A-Za-z0-9_]* | \$\{[A-Za-z_][A-Za-z0-9_]*\} | \$[?!] | \$\{[?!]\} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | | \( (?&e) (?&w) \) ) ) # $NAME, ${NAME}: substituted as text first (C9) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | (?<op> (?&w) (?: << | >> | <= | >= | == | != | && | \|\| | [-+*/%<>&^|] ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | (?<e> (?&atom) (?: (?&op) (?&atom) )* (?: (?&w) \? (?&e) (?&w) : (?&e) )? ) )}x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | my %EX = ('$' => \&dollar, '`' => \&bq); # the expansion a $ or ` starts: ($q, $p) -> Part | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1992 | ▶ | sub P { my $p = shift; $M ? $$M[$p] // $$M[-1] : $p } # position in the original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
P: called CC=3 SCAR=11.7
Pod
undocumented
Branch: 1 branch
Condition33%1/3
$Proc::ShellSubset::Small::M->[$p] // $Proc::ShellSubset::Small::M->[-1]
MC/DC0%0/2
$Proc::ShellSubset::Small::M->[$p] // $Proc::ShellSubset::Small::M->[-1]
$Proc::ShellSubset::Small::M->[$p]
$Proc::ShellSubset::Small::M->[-1]
Truth table33%1/3
A // B
A= $Proc::ShellSubset::Small::M->[$p]B= $Proc::ShellSubset::Small::M->[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 831 | ▶ | sub E { push @{$OPEN[$ATT // -1]}, { ERROR => 1 } if @OPEN; die [shift, P(shift)] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
E: called CC=3 SCAR=11.0
Pod
undocumented
Branch: 1 branch
Condition100%2/2
$Proc::ShellSubset::Small::ATT // -1
MC/DC100%1/1
$Proc::ShellSubset::Small::ATT // -1
$Proc::ShellSubset::Small::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::Small::ATT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 64 | ▶ | sub U { /\G$B/gc; E(/\G(.)/s ? 'unexpected ' . ($1 eq "\n" ? 'newline' : "'$1'") : 'unexpected end', pos) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
U: called CC=3 SCAR=11.1
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1873 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1873 | my $s = shift; local ($M, @OPEN, $ATT); local $LAST = 0; my @l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1873 | my $t = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1873 | local $_ = $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1873 | ▶ | E('NUL character', $-[0]) if /\0/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1872 | ▶ | E(q{starts with - or +: sh would read it as options}, $-[1]) if /\A[ \t\n\r\f\cK]*([-+])/; # Perl skips leading white space, then runs sh -c STRING (U1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1866 | shell('', \@l) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1873 | ▶ | $t // (ref $@ eq 'ARRAY' ? { error => $@->[0], pos => $@->[1], last => $LAST, tree => \@l } : die $@) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::Small::LAST, "tree", \@l} : die($@))
MC/DC100%1/1
$t // (ref $@ eq "ARRAY" ? {"error", $@->[0], "pos", $@->[1], "last", $Proc::ShellSubset::Small::LAST, "tree", \@l} : die($@))
$t
Truth table100%2/2
A
A= $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2252 | ▶ | sub list { # up to ')' (subshell, $()), '}' (group) or the end ('') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2252 | ▶ | my ($t, $l) = @_; local $OPEN[@OPEN] = $l; my $top = !$t && !$M; # fills @$l in place | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$t || $Proc::ShellSubset::Small::M
MC/DC100%2/2
$t || $Proc::ShellSubset::Small::M
$t
$Proc::ShellSubset::Small::M
Truth table100%3/3
A || B
A= $tB= $Proc::ShellSubset::Small::M
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2252 | ▶ | my $e = $t eq ')' ? qr/\G(?=\))/ : $t ? qr/\G(?=\}$END)/ : qr/\G\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2252 | ▶ | while (/\G$BN/gc, !/$e/) { # (zero-length /gc matches can't repeat at one place: test with plain //) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2408 | push @$l, my $c = []; andor($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1588 | ▶ | if (/\G$B&(?!&)/gc) { push @$c, '&' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1317 | ▶ | elsif (!/\G$B(?:;(?!;)|\n)/gc) { /\G$B/gc, /$e/ ? last : U() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 271 | ▶ | $LAST = pos if $top } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1368 | $l } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2196 | ▶ | sub shell { # a list that runs in a shell of its own: exec is checked at its end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shell: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2196 | my $l = list(@_); xc($l, 1); $l } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2408 | ▶ | sub andor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
andor: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2408 | my $ao = shift; local $OPEN[@OPEN] = $ao; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2408 | ▶ | do { push @$ao, my $p = []; pipeline($p) } while /\G$B(&&|\|\|)$BN/gc && push @$ao, $1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
/\G$B(&&|\|\|)$BN/cg and push @$ao, $1
MC/DC50%1/2
/\G$B(&&|\|\|)$BN/cg and push @$ao, $1
/\G$B(&&|\|\|)$BN/cg
push @$ao, $1
Truth table66%2/3
A and B
A= /\G$B(&&|\|\|)$BN/cgB= push @$ao, $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2567 | ▶ | sub pipeline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pipeline: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2567 | my $p = shift; local $OPEN[@OPEN] = $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2567 | ▶ | push @$p, '!' if /\G!(?=[ \t])$B/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2567 | ▶ | E("'! !'", pos) if @$p && /\G!$END/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$p and /\G!$END/
MC/DC100%2/2
@$p and /\G!$END/
@$p
/\G!$END/
Truth table100%3/3
A and B
A= @$pB= /\G!$END/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2562 | ▶ | do { command($p) } while /\G$B\|(?![|&])$BN/gc } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3106 | ▶ | sub command { # pushes the command onto the pipeline @{$_[0]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 3106 | my $pl = shift; my $p = pos; my $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3106 | ▶ | E("'((' at the start of a command", $p) if /\G\(\(/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3101 | ▶ | if (/\G\(/gc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 71 | push @$pl, $c = { sub => my $l = [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 71 | ▶ | shell(')', $l); /\G\)/gc; @$l or E('empty subshell', $p) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | elsif (/\G\{(?=[ \t\n])/gc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 56 | push @$pl, $c = { group => my $l = [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 56 | ▶ | list('}', $l); /\G\}/gc; @$l or E('empty group', $p) } # xc: by the parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2974 | else { return simple($pl) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 115 | ▶ | my ($r, @r); push @r, $r while /\G$B/gc, $r = redir(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 115 | ▶ | $c->{redir} = \@r if @r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 115 | $c } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 7490 | ▶ | sub redir { # a redirection, or nothing (pos unchanged) if none starts here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redir: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 7490 | my $p = pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 7490 | ▶ | E('process substitution (bash)', $p) if /\G[<>]\(/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 7477 | ▶ | /\G([0-9]*)(<<|>>|<>|>\||<&|>&|<|>)$B/gc or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 480 | ▶ | E('target followed by a redirection operator (dash: a descriptor)', pos) if /\G[0-9]+[<>]/; # x >&2>f (U4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 474 | my ($n, $op) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 474 | ▶ | E('here-document', $p) if $op eq '<<'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 469 | ▶ | my $fd = length $n ? 0 + $n : $op =~ /^</ ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 469 | ▶ | return [$fd, $op, /\G([0-9-])$END/gc ? $1 : E("'$op' takes one digit or '-'", pos)] if $op =~ /&/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 390 | [$fd, $op, word('r')] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2974 | ▶ | sub simple { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple: called CC=40 SCAR=38.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2974 | my $pl = shift; my (@env, @av, @ap, @r, @np, $kw); my $p0 = pos; # @ap: the position of each word of @av | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2974 | push @$pl, my $c = { argv => \@av }; local $OPEN[@OPEN] = \@av; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2974 | ▶ | while (/\G$B/gc, !/\G(?=[;&|()\n]|\z)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7341 | my $p = pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 7341 | ▶ | if (my $r = redir()) { push @r, $r } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 184 | ▶ | elsif (!@av and /\G($NM)(\+?)=/gc) { E("'$1+='", $p) if $2; push @np, ["$1", $p]; push @env, "$1", word('e') } # "$1", not $1: word() matches again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @av and /\G($NM)(\+?)=/cg
MC/DC100%2/2
not @av and /\G($NM)(\+?)=/cg
not @av
/\G($NM)(\+?)=/cg
Truth table100%3/3
not(A) and B
A= not @avB= /\G($NM)(\+?)=/cg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 6698 | ▶ | else { push @av, word('a'); push @ap, $p; $kw //= substr $_, $p, pos() - $p } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$kw //= substr($_, $p, pos($_) - $p)
MC/DC0%0/2
$kw //= substr($_, $p, pos($_) - $p)
$kw
substr($_, $p, pos($_) - $p)
Truth table66%2/3
A //= B
A= $kwB= substr($_, $p, pos($_) - $p)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2434 | name(@$_) for grep $$_[0] ne 'IFS', @np; # bash refuses its own names (UID=5 cmd) (U5) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2430 | ▶ | @av or E(@env || @r ? 'no command name' : 'missing command', $p0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@env or @r
MC/DC100%2/2
@env or @r
@env
@r
Truth table100%3/3
A or B
A= @envB= @r
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2326 | ▶ | E('command name not literal', $ap[0]) if ref $av[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2319 | my $n = $av[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2319 | ▶ | if ($n eq 'exec') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 61 | shift @av; my $xp = shift @ap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 61 | ▶ | @av or E("'exec' without a command", $p0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 57 | ▶ | E("unsupported 'exec' form", $ap[0]) if ref($av[0]) || $av[0] =~ /^-|^(?:cd|:|exit)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $av[0] or $av[0] =~ /^-|^(?:cd|:|exit)\z/
MC/DC50%1/2
ref $av[0] or $av[0] =~ /^-|^(?:cd|:|exit)\z/
ref $av[0]
$av[0] =~ /^-|^(?:cd|:|exit)\z/
Truth table66%2/3
A or B
A= ref $av[0]B= $av[0] =~ /^-|^(?:cd|:|exit)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 51 | $c->{exec} = P($xp) } # its position, until xc() has checked it and made it 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2258 | ▶ | E("keyword '$n'", $ap[0]) if $KW{$n} && $kw eq $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$KW{$n} and $kw eq $n
MC/DC100%2/2
$KW{$n} and $kw eq $n
$KW{$n}
$kw eq $n
Truth table100%3/3
A and B
A= $KW{$n}B= $kw eq $n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2178 | ▶ | E("builtin '$n'", $ap[0]) if $BI{$n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2151 | ▶ | if ($n eq 'cd') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 48 | ▶ | @av <= 2 && !@env && !@r && !defined $ENV{CDPATH} && ($av[1] // '') !~ /^-/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition85%12/14
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"} and not +($av[1] // "") =~ /^-/
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"}
@av <= 2 and not @env and not @r
@av <= 2 and not @env
$av[1] // ""
MC/DC60%3/5
@av <= 2 and not @env and not @r and not defined $ENV{"CDPATH"} and not +($av[1] // "") =~ /^-/
@av <= 2
not @env
not @r
not defined $ENV{"CDPATH"}
$av[1]
Truth table66%4/6
A and not(B) and not(C) and not(D) and not(E)
A= @av <= 2B= not @envC= not @rD= not defined $ENV{"CDPATH"}E= $av[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | or E('unsupported cd form', $ap[0]); # C8: the argument may have expansions; cd alone goes home | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | E('cd to $HOME without HOME', $ap[0]) if !defined $ENV{HOME} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | && (@av == 1 || ref $av[1] && grep { ref && $$_[0] =~ /^\$/ } @{$av[1]}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition8%1/12
not defined $ENV{"HOME"} and @av == 1 || ref $av[1] && grep({ref $_ and $_->[0] =~ /^\$/;} @{$av[1];})
@av == 1 or ref $av[1] and grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
ref $av[1] and grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
ref $_ && $_->[0] =~ /^\$/
MC/DC0%0/4
not defined $ENV{"HOME"} and @av == 1 || ref $av[1] && grep({ref $_ and $_->[0] =~ /^\$/;} @{$av[1];})
not defined $ENV{"HOME"}
@av == 1
ref $av[1]
grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
MC/DC0%0/2
ref $_ && $_->[0] =~ /^\$/
ref $_
$_->[0] =~ /^\$/
Truth table20%1/5
not(A) and B or C and D
A= not defined $ENV{"HOME"}B= @av == 1C= ref $av[1]D= grep {ref $_ and $_->[0] =~ /^\$/;} @{$av[1];}
Truth table0%0/3
A && B
A= ref $_B= $_->[0] =~ /^\$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 36 | return %$c = (cd => $av[1]) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2103 | ▶ | if ($n =~ /^(?::|exit)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 60 | ▶ | E("settings before '$n'", $p0) if @env; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 56 | ▶ | E('unsupported exit status', $ap[0]) if $n eq 'exit' && (@av > 2 || @av == 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
$n eq "exit" and @av > 2 || @av == 2 && (!($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255)
@av > 2 or @av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
@av == 2 and !($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255
not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/ or $av[1] > 255
MC/DC80%4/5
$n eq "exit" and @av > 2 || @av == 2 && (!($av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/) || $av[1] > 255)
$n eq "exit"
@av > 2
@av == 2
not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/
$av[1] > 255
Truth table83%5/6
A and B or C and not(D) or E
A= $n eq "exit"B= @av > 2C= @av == 2D= not $av[1] =~ /^(?:0|[1-9][0-9]{0,2})\z/E= $av[1] > 255
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | && ($av[1] !~ /^(?:0|[1-9][0-9]{0,2})\z/ || $av[1] > 255)) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2140 | ▶ | $c->{env} = \@env if @env; $c->{redir} = \@r if @r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2140 | $c } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7266 | ▶ | sub word { # $x: a(rgument), e(nv value), r(edirection target) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
word: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 7266 | ▶ | my $x = shift; my $p0 = pos; my @s; local $ATT = $ATT // $#OPEN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$Proc::ShellSubset::Small::ATT // $#Proc::ShellSubset::Small::OPEN
MC/DC100%1/1
$Proc::ShellSubset::Small::ATT // $#Proc::ShellSubset::Small::OPEN
$Proc::ShellSubset::Small::ATT
Truth table100%2/2
A
A= $Proc::ShellSubset::Small::ATT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 7266 | ▶ | return '[' if $x eq 'a' and /\G\[$END/gc; # '[' alone: literal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$x eq "a" and /\G\[$END/cg
MC/DC100%2/2
$x eq "a" and /\G\[$END/cg
$x eq "a"
/\G\[$END/cg
Truth table100%3/3
A and B
A= $x eq "a"B= /\G\[$END/cg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 7186 | ▶ | my $te = $x eq 'e' ? qr{(?=[/:])|$END} : qr{(?=/)|$END}; # ~ also before ':' in a setting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 7186 | my $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | my %do = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 144 | ▶ | sq => sub { push @s, [q => shift] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 409 | ▶ | dq => sub { push @s, [q => '']; dq(\@s, $p) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 101 | ▶ | bs => sub { $_[0] eq "\n" ? E('backslash-newline in a word', $p) : push @s, [q => shift] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 671 | ▶ | ex => sub { push @s, [x => $EX{$_[0]}->('', $p)] }, # also in redirection targets (Q1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 170 | ▶ | gl => sub { E('pattern in a redirection target', $p) if $x eq 'r'; push @s, [$x eq 'e' ? 'u' : 'g', shift] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 44 | ▶ | br => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 44 | ▶ | E('pattern in a redirection target', $p) if $x eq 'r'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 44 | ▶ | push @s, $x eq 'e' ? [u => '['] : /\G(!?\]?[^\] \t\n;&|()<>'"\\\$`{}^\/,]*\])/gc ? [g => "[$1"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | : /\G(?:\\.|'[^']*'|"(?:[^"\\]|\\.)*"|[^ \t\n;&|()<>\\'"])*?\]/s # a ] later in the word, past quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ? E('bracket expression with a quote, expansion or slash', $p) : [g => '['] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 122 | ▶ | ti => sub { # ~ at the start of the word, or after an unquoted ':' in a setting, is an expansion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 122 | ▶ | return push @s, [u => '~'] if @s && !($x eq 'e' && $s[-1][0] eq 'u' && $s[-1][1] =~ /:\z/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
@s and not $x eq "e" && $s[-1][0] eq "u" && $s[-1][1] =~ /:\z/
$x eq 'e' && $s[-1][0] eq 'u' && $s[-1][1] =~ /:\z/
$x eq "e" and $s[-1][0] eq "u"
MC/DC100%4/4
@s and not $x eq "e" && $s[-1][0] eq "u" && $s[-1][1] =~ /:\z/
@s
$x eq "e"
$s[-1][0] eq "u"
$s[-1][1] =~ /:\z/
Truth table100%5/5
A and not(B and C && D)
A= @sB= $x eq "e"C= $s[-1][0] eq "u"D= $s[-1][1] =~ /:\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 97 | ▶ | /\G((?:[A-Za-z0-9._][A-Za-z0-9._-]*)?)$te/gc or E('unsupported ~ form', $p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 88 | ▶ | E('~ without HOME', $p) if $1 eq '' && !defined $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$1 eq "" and not defined $ENV{"HOME"}
MC/DC0%0/2
$1 eq "" and not defined $ENV{"HOME"}
$1 eq ""
not defined $ENV{"HOME"}
Truth table66%2/3
A and not(B)
A= $1 eq ""B= not defined $ENV{"HOME"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 88 | push @s, [x => ['~', $1]] }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 5955 | ▶ | lit => sub { push @s, [u => shift] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 109 | ▶ | bad => sub { E({"'" => 'unterminated quote', '\\' => 'final backslash', '{' => "unquoted '{'", '}' => "unquoted '}'"}->{$_[0]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%2/2
{"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]} // sprintf("control character \\x%02x", ord shift())
MC/DC100%1/1
{"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]} // sprintf("control character \\x%02x", ord shift())
{"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]}
Truth table100%2/2
A
A= {"'", "unterminated quote", "\\", "final backslash", "{", "unquoted '{'", "}", "unquoted '}'"}->{$_[0]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 7186 | // sprintf('control character \\x%02x', ord shift), $p) }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 7186 | ▶ | until (/\G$END/) { $p = pos; /$PIECE/gc; my ($k, $v) = %+; $do{$k}($v) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 6727 | ▶ | @s or $x eq 'e' or E('missing word', $p0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@s or $x eq "e"
MC/DC100%2/2
@s or $x eq "e"
@s
$x eq "e"
Truth table100%3/3
A or B
A= @sB= $x eq "e"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6695 | my $k = join '', map $$_[0], @s; my @v; # kinds: u(nquoted) q(uoted) g(lob char) x(pansion) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6695 | ▶ | push @v, defined $1 ? ['*', join '', map $$_[1], splice @s, 0, length $1] : (shift @s)->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | while $k =~ /([ug]*g[ug]*)|./g; # unquoted text next to a pattern character joins it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 6695 | ▶ | dots(@v) and E("pattern that may match '.' or '..'", $p0); # dash: yes, bash 5.2: no (U2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 6683 | mkword(@v) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 6695 | ▶ | sub dots { # can a pattern in these Parts match a whole file name component '.' or '..'? (U2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dots: called CC=17 SCAR=28.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 6695 | my ($re, $g) = ('', 0); # the component so far as a regex (only the character '.' matters); has it a pattern? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 6695 | for my $x (@_, '/') { # literal text and patterns, split at '/'; an expansion is taken to match no '.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 14325 | ▶ | for (ref $x ? $$x[0] eq '*' ? map [g => $_], split m{(/)}, $$x[1] : [x => ''] : map [l => $_], split m{(/)}, $x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 22011 | my ($k, $v) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 22011 | ▶ | if ($v eq '/') { return 1 if $g && $re =~ /^\\\./ && grep /^$re\z/, '.', '..'; ($re, $g) = ('', 0) } # only a written '.' matches a leading one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%6/6
$g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".."
$g and $re =~ /^\\\./
MC/DC100%3/3
$g and $re =~ /^\\\./ and grep /^$re\z/, ".", ".."
$g
$re =~ /^\\\./
grep /^$re\z/, ".", ".."
Truth table100%4/4
A and B and C
A= $gB= $re =~ /^\\\./C= grep /^$re\z/, ".", ".."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 13705 | elsif ($k eq 'l') { $re .= quotemeta $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 668 | elsif ($k eq 'x') { $re .= '(?!)' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 219 | ▶ | else { $g ||= $v =~ /[*?[]/; $re .= $v =~ s{\[(!?)(\]?[^\]]*)\]|([*?])|(.)}{ # a bracket expression: can it match '.'? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$g ||= $v =~ /[*?[]/
MC/DC100%2/2
$g ||= $v =~ /[*?[]/
$g
$v =~ /[*?[]/
Truth table100%3/3
A ||= B
A= $gB= $v =~ /[*?[]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 742 | ▶ | defined $2 ? (($1 ? $2 !~ /\./ : $2 =~ /[.\-]|\[:/) ? q{[.]} : q{(?!)}) : defined $3 ? ($3 eq '*' ? '.*' : '.') : quotemeta $4}gesr } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 6683 | 0 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 6683 | ▶ | sub mkword { # a Word from Parts: adjacent strings joined, a lone string bare, nothing '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mkword: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 6683 | ▶ | my @w; !ref && @w && !ref $w[-1] ? $w[-1] .= $_ : push @w, $_ for @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not ref $_ and @w and not ref $w[-1]
not ref $_ and @w
MC/DC100%3/3
not ref $_ and @w and not ref $w[-1]
not ref $_
@w
not ref $w[-1]
Truth table100%4/4
not(A) and B and not(C)
A= not ref $_B= @wC= not ref $w[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 6683 | ▶ | @w == 1 && !ref $w[0] ? $w[0] : @w ? \@w : '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@w == 1 and not ref $w[0]
MC/DC100%2/2
@w == 1 and not ref $w[0]
@w == 1
not ref $w[0]
Truth table100%3/3
A and not(B)
A= @w == 1B= not ref $w[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 409 | ▶ | sub dq { # after '"', up to the closing '"' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dq: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 409 | my ($s, $p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 409 | ▶ | until (/\G"/gc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 753 | ▶ | next if /\G\\\n/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 751 | ▶ | if (/\G(?:([^"\\\$`]+)|\\([\$`"\\])|(\\))/gc) { push @$s, [q => $+] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 287 | elsif (/\G([\$`])/gc) { push @$s, [x => $EX{$1}->('"', pos() - 1)] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | else { E('unterminated double quote', $p) } } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 857 | ▶ | sub dollar { # after '$'; $q is '"' inside double quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dollar: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 857 | my ($q, $p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 857 | ▶ | return '$' unless /\G[A-Za-z_0-9{(@*#?\$!\[-]/ or !$q && /\G['"]/; # starts nothing: literal (C1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/
not $q and /\G['"]/
MC/DC100%3/3
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/ or not $q and /\G['"]/
/\G[A-Za-z_0-9{(\@*#?\$!\[-]/
not $q
/\G['"]/
Truth table100%4/4
A or not(B) and C
A= /\G[A-Za-z_0-9{(\@*#?\$!\[-]/B= not $qC= /\G['"]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 800 | ▶ | return [$q . '$((', arith($p)] if /\G\(\(/gc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 751 | ▶ | if (/\G\(/gc) { my $l = shell(')', []); /\G\)/gc; return [$q . '$(', $l] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 586 | ▶ | return [$q . '$', name("$1", $p)] if /\G(?|\{($NM|[?!])\}|($NM|[?!]))/gc; # $? and $! (corpus-round C6) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 224 | ▶ | E(/\G['"\[]/ ? 'bash-only $ form' : 'unsupported parameter form', $p) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 508 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 508 | my ($n, $p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | E("shell-set variable '$n'", $p) if $SH{$n} || $n =~ /^(?:BASH|COMP|READLINE)_/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 508 | ▶ | || $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ && !defined $ENV{$n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$SH{$n} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
$SH{$n} or $n =~ /^(?:BASH|COMP|READLINE)_/
$n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
MC/DC50%2/4
$SH{$n} or $n =~ /^(?:BASH|COMP|READLINE)_/ or $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/ and not defined $ENV{$n}
$SH{$n}
$n =~ /^(?:BASH|COMP|READLINE)_/
$n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/
not defined $ENV{$n}
Truth table60%3/5
A or B or C and not(D)
A= $SH{$n}B= $n =~ /^(?:BASH|COMP|READLINE)_/C= $n =~ /^(?:PATH|SHELL|TERM|HOSTNAME)\z/D= not defined $ENV{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 498 | $n } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 49 | ▶ | sub arith { # after '$((': check the expression by its grammar, return its text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arith: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 49 | my $p = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 49 | ▶ | /\G((?&e))(?&w)\)\)$ARITH/gc && $1 !~ /\+\+|--/ or E('bad arithmetic expression', $p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/\G((?&e))(?&w)\)\)$ARITH/cg and not $1 =~ /\+\+|--/
MC/DC100%2/2
/\G((?&e))(?&w)\)\)$ARITH/cg and not $1 =~ /\+\+|--/
/\G((?&e))(?&w)\)\)$ARITH/cg
not $1 =~ /\+\+|--/
Truth table100%3/3
A and not(B)
A= /\G((?&e))(?&w)\)\)$ARITH/cgB= not $1 =~ /\+\+|--/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 27 | ▶ | my $t = $1; name("$1", $p) while $t =~ /\b($NM)/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 27 | $t } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 101 | ▶ | sub bq { # after '`': find the closing '`', undo its escapes, parse the result as its own string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bq: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 101 | my ($q, $p) = @_; my $s = pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 101 | ▶ | /\G((?:[^`\\]|\\.)*)`/sgc or E('unterminated backquote', $p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 96 | my ($raw, $in, @m) = ($1, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 96 | ▶ | while ($raw =~ /\\([\$`\\$q])|(\\\n)|(.)/sg) { # a backslash escapes $ ` \ and, inside double quotes, " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1018 | ▶ | E('backslash-newline inside backquotes', $s + $-[0]) if defined $2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1016 | $in .= $+; push @m, P($s + $-[$#-]) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 94 | push @m, P(pos() - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 94 | [$q . '$(', do { local $_ = $in; local $M = \@m; shell('', []) }] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1367 | ▶ | sub xc { # B3: 'exec' only where nothing can follow it in the shell (or subshell) it replaces | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xc: called CC=12 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1367 | my ($l, $ok) = @_; # $ok: nothing follows this list in its shell | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1367 | for my $ch (@$l) { my @p = grep ref, @$ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1505 | for my $pl (@p) { my @c = grep ref, @$pl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1658 | ▶ | my $last = @c > 1 # each element of a longer pipeline is a subshell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%15/15
@c > 1 || $pl == $p[-1] && $pl->[0] ne '!' && ($ch->[-1] eq '&' || $ok && $ch == $l->[-1])
$pl == $p[-1] and $pl->[0] ne "!" and $ch->[-1] eq "&" || $ok && $ch == $l->[-1]
$pl == $p[-1] and $pl->[0] ne "!"
$ch->[-1] eq "&" or $ok and $ch == $l->[-1]
$ok and $ch == $l->[-1]
MC/DC100%6/6
@c > 1 || $pl == $p[-1] && $pl->[0] ne '!' && ($ch->[-1] eq '&' || $ok && $ch == $l->[-1])
@c > 1
$pl == $p[-1]
$pl->[0] ne "!"
$ch->[-1] eq "&"
$ok
$ch == $l->[-1]
Truth table100%7/7
A || B and C and D or E and F
A= @c > 1B= $pl == $p[-1]C= $pl->[0] ne "!"D= $ch->[-1] eq "&"E= $okF= $ch == $l->[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | || $pl == $p[-1] && $pl->[0] ne '!' && ($ch->[-1] eq '&' || $ok && $ch == $l->[-1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1658 | for my $x (@c) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2160 | ▶ | xc($x->{group}, $last) if $x->{group}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2151 | ▶ | if (exists $x->{exec}) { my $xp = $x->{exec}; $x->{exec} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 51 | ▶ | $x->{ERROR} = 1, die ["'exec' with something after it", $xp] if !$last } } } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||