lib/BATsh/Env.pm

filter: Statementstmt 89.2% 174 / 195 Branchbran 67.5% 81 / 120 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 96.4% 27 / 28 Podpod 84.6% 11 / 13 totaltotal 80.8% 300 / 371 SCAR 46.2
CC
67
Cov
80%
expand_sh
42.0
_expand_tilde_param
23.1
_expand_var_modifier
14.3
CRAP 101.6
« lib/BATsh/MB.pm ↑ Summary blib/script/batsh.pl »
1 package BATsh::Env;
2 # Copyright (c) 2026 INABA Hitoshi <ina.cpan@gmail.com>
3 ######################################################################
4 #
5 # BATsh::Env - Shared environment variable store
6 #
7 # v0.02 changes:
8 # - Variable names are case-insensitive (cmd.exe compatible).
9 # Stored internally in uppercase.
10 # - SETLOCAL ENABLEDELAYEDEXPANSION flag tracked per scope.
11 # - expand_cmd expands !VAR! when delayed expansion is active.
12 # - expand_cmd expands %0..%9 and %* positional parameters.
13 # - _expand_tilde_param: %~[fdpnx]*N batch-parameter tilde modifiers.
14 # Modifiers f(full path), d(drive), p(dir), n(basename), x(ext).
15 # Uses File::Spec and Cwd for cross-platform absolute path resolution.
16 # - init() guards undef %ENV values (Windows compatibility).
17 #
18 ######################################################################
19  
20 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 36 ▶BEGIN { if ($] < 5.006 && !defined(&warnings::import)) { $INC{'warnings.pm'} = 'stub'; eval 'package warnings; sub import {}' } }
Subroutine BEGIN: called CC=3 SCAR=16.5
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.006" and not defined &warnings::import) 0 36 36
Condition33%1/3
$] < "5.006" and not defined &warnings::import
!ll&&!rl&&r
3600
MC/DC0%0/2
$] < "5.006" and not defined &warnings::import
$] < "5.006" not defined &warnings::import
Truth table33%1/3
A and not(B)
A= $] < "5.006"B= not defined &warnings::import
ABresult
0X0
100
111
22 36 ▶use warnings; local $^W = 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶BEGIN { pop @INC if $INC[-1] eq '.' }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 0 36 36
24  
25 36 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 $VERSION = '0.10';
27  
28 36 require BATsh::MB;
29  
30 36 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 36 ▶BEGIN { eval { require Cwd } }
Subroutine BEGIN: called CC=1 SCAR=0.0
32 36 ▶BEGIN { eval { require POSIX } }
Subroutine BEGIN: called CC=1 SCAR=0.0
33 36 $VERSION = $VERSION;
34  
35 # Keys stored in UPPERCASE for case-insensitive lookup
36 36 ▶use vars qw(%STORE);
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 # Delayed expansion flag
39 36 ▶use vars qw($DELAYED_EXPANSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 36 $DELAYED_EXPANSION = 0;
41  
42 # SETLOCAL scope stack: each entry = { store => \%snap, delayed => $flag }
43 36 ▶use vars qw(@SETLOCAL_STACK);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 36 @SETLOCAL_STACK = ();
45  
46 sub init {
47 459 ▶ %STORE = ();
Subroutine init: called CC=3 SCAR=11.1
Pod documented
48 459 for my $k (keys %ENV) {
49 12393 ▶ $STORE{uc($k)} = defined $ENV{$k} ? $ENV{$k} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{$k} ? : 12393 0 12393
50 }
51 459 $DELAYED_EXPANSION = 0;
52 }
53  
54 3737 ▶sub _key { return uc($_[0]) }
Subroutine _key: called CC=1 SCAR=0.0
55  
56 1329 ▶sub get { my ($c, $n) = @_; return $STORE{_key($n)} }
Subroutine get: called CC=1 SCAR=0.0
Pod documented
57 2365 ▶sub set { my ($c, $n, $v) = @_; $STORE{_key($n)} = defined $v ? $v : '' }
Subroutine set: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 2365 0 2365
58 42 ▶sub unset { my ($c, $n) = @_; delete $STORE{_key($n)} }
Subroutine unset: called CC=1 SCAR=0.0
Pod documented
59 1 ▶sub exists_var { my ($c, $n) = @_; return exists $STORE{_key($n)} ? 1 : 0 }
Subroutine exists_var: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
exists $BATsh::Env::STORE{_key($n)} ? : 1 0 1
60 sub sync_to_env {
61 32 ▶ %ENV = ();
Subroutine sync_to_env: called CC=3 SCAR=11.0
Pod documented
62 32 for my $k (keys %STORE) {
63 879 ▶ next if index($k, '%') >= 0; # %0..%9, %*, %%V: not env names
Branch: 1 branch
BranchTrueFalseTotal
if index($k, "%") != -1 2 877 879
64 877 $ENV{$k} = BATsh::MB::dec($STORE{$k});
65 }
66 }
67 7 ▶sub snapshot { my %s = %STORE; return { %s } }
Subroutine snapshot: called CC=1 SCAR=0.0
Pod undocumented
68 7 ▶sub restore { my ($c, $s) = @_; %STORE = %{$s} }
Subroutine restore: called CC=1 SCAR=0.0
Pod undocumented
69 63 ▶sub delayed_expansion { return $DELAYED_EXPANSION }
Subroutine delayed_expansion: called CC=1 SCAR=0.0
Pod documented
70  
71 sub setlocal {
72 8 ▶ my ($opts) = @_;
Subroutine setlocal: called CC=4 SCAR=14.3
Pod documented
73 8 ▶ $opts = '' unless defined $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts 0 8 8
74 8 my %snap = %STORE;
75 8 push @SETLOCAL_STACK, { store => { %snap }, delayed => $DELAYED_EXPANSION };
76 8 ▶ if ($opts =~ /ENABLEDELAYEDEXPANSION/i) { $DELAYED_EXPANSION = 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($opts =~ /ENABLEDELAYEDEXPANSION/i) { } 4 4 8
elsif ($opts =~ /DISABLEDELAYEDEXPANSION/i) { } 0 4 4
77 0 elsif ($opts =~ /DISABLEDELAYEDEXPANSION/i) { $DELAYED_EXPANSION = 0 }
78 # ENABLEEXTENSIONS / DISABLEEXTENSIONS: accepted, not modelled
79 }
80  
81 sub endlocal {
82 8 ▶ unless (@SETLOCAL_STACK) {
Subroutine endlocal: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless (@BATsh::Env::SETLOCAL_STACK) 0 8 8
83 0 warn "[BATsh] Warning: ENDLOCAL without matching SETLOCAL\n";
84 0 return;
85 }
86 8 my $f = pop @SETLOCAL_STACK;
87 8 %STORE = %{$f->{store}};
88 8 $DELAYED_EXPANSION = $f->{delayed};
89 }
90  
91 # ----------------------------------------------------------------
92 # expand_cmd: %VAR% expansion, then optional !VAR! delayed expansion
93 # ----------------------------------------------------------------
94 sub expand_cmd {
95 393 ▶ my ($class, $str) = @_;
Subroutine expand_cmd: called CC=5 SCAR=16.2
Pod documented
96 393 ▶ return '' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 393 393
97  
98 # %~[modifiers][0-9]: batch parameter modifiers (e.g. %~dp0, %~nx1)
99 # Must be processed BEFORE %VAR% to avoid being mis-parsed.
100 393 $str =~ s/%~([fdpnxs]*)([0-9])/_expand_tilde_param($1, $2)/ge;
101  
102 # Batch positional parameters: %0..%9 and %* (single % prefix, no closing %)
103 # Must expand BEFORE %VAR% so that "%0 foo=%1" is not mis-parsed by
104 # the greedy %([^%]+)% pattern as a single named variable.
105 393 $str =~ s/%([0-9*])/
106 61 ▶ do { my $k = "%$1"; exists($STORE{$k}) ? $STORE{$k} : '' }
Branch: 1 branch
BranchTrueFalseTotal
exists $BATsh::Env::STORE{$k} ? : 61 0 61
107 /ge;
108  
109 # %VAR:~n,m% substring and %VAR:str1=str2% substitution
110 # Must be processed BEFORE plain %VAR% expansion.
111 393 $str =~ s/%([A-Za-z_][A-Za-z0-9_]*):([^%
112 15 ]+)%/_expand_var_modifier($1,$2)/ge;
113  
114 # %VAR% substitution: dynamic pseudo-variables first, then STORE lookup
115 393 $str =~ s/%([^%\r\n]+)%/_expand_named_var($1)/ge;
116  
117 # %% -> literal %
118 393 $str =~ s/%%/%/g;
119  
120 # !VAR! delayed expansion (only when enabled)
121 393 ▶ if ($DELAYED_EXPANSION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($BATsh::Env::DELAYED_EXPANSION) 19 374 393
122 19 $str =~ s/!([A-Za-z_][A-Za-z0-9_]*)!/
123 5 ▶ do { my $k=uc($1); exists($STORE{$k}) ? $STORE{$k} : '' }
Branch: 1 branch
BranchTrueFalseTotal
exists $BATsh::Env::STORE{$k} ? : 5 0 5
124 /ge;
125 }
126  
127 393 return $str;
128 }
129  
130 # ----------------------------------------------------------------
131 # _expand_tilde_param: resolve %~[fdpnx]*N batch-parameter modifiers
132 #
133 # Modifier letters (combinable, same as cmd.exe):
134 # (none) strip surrounding double-quotes only
135 # f fully qualified path (absolute)
136 # d drive letter only (e.g. "C:" on Windows, "" on Unix)
137 # p path component only (directory, with trailing separator)
138 # n filename without extension
139 # x extension only (including leading dot, e.g. ".bat")
140 #
141 # The value is taken from %N in the Env store (%0..%9).
142 # ----------------------------------------------------------------
143 # _expand_named_var: resolve %VARNAME% with dynamic pseudo-variable support
144 #
145 # Dynamic pseudo-variables (read-only, computed at expansion time):
146 # %RANDOM% pseudo-random integer 0-32767 (cmd.exe range)
147 # %DATE% current date YYYY-MM-DD
148 # %TIME% current time HH:MM:SS.cc
149 # %CD% current working directory
150 # %CMDCMDLINE% empty string (not meaningful in a pure-Perl interpreter)
151 # %ERRORLEVEL% current ERRORLEVEL from BATsh::CMD (via hook function)
152 #
153 # All other names: looked up in %STORE (case-insensitive, as cmd.exe).
154 # ----------------------------------------------------------------
155 sub _expand_named_var {
156 85 ▶ my ($name) = @_;
Subroutine _expand_named_var: called CC=11 SCAR=24.7
157 85 my $upper = uc($name);
158 85 ▶ if ($upper eq 'RANDOM') {
Branch: 1 branch
BranchTrueFalseTotal
if ($upper eq "RANDOM") 1 84 85
159 1 return int(rand(32768));
160 }
161 84 ▶ if ($upper eq 'DATE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($upper eq "DATE") 1 83 84
162 1 my @t = localtime(time());
163 1 return sprintf('%04d-%02d-%02d', $t[5]+1900, $t[4]+1, $t[3]);
164 }
165 83 ▶ if ($upper eq 'TIME') {
Branch: 1 branch
BranchTrueFalseTotal
if ($upper eq "TIME") 1 82 83
166 1 my @t = localtime(time());
167 1 return sprintf('%02d:%02d:%02d.%02d', $t[2], $t[1], $t[0], 0);
168 }
169 82 ▶ if ($upper eq 'CD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($upper eq "CD") 1 81 82
170 1 ▶ return BATsh::MB::enc(defined(&Cwd::cwd) ? Cwd::cwd() : '.');
Branch: 1 branch
BranchTrueFalseTotal
defined &Cwd::cwd ? : 1 0 1
171 }
172 81 ▶ if ($upper eq 'CMDCMDLINE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($upper eq "CMDCMDLINE") 0 81 81
173 0 return '';
174 }
175 81 ▶ if ($upper eq 'ERRORLEVEL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($upper eq "ERRORLEVEL") 3 78 81
176 return defined(&BATsh::CMD::_get_errorlevel)
177 ? BATsh::CMD::_get_errorlevel()
178 3 ▶ : (exists($STORE{ERRORLEVEL}) ? $STORE{ERRORLEVEL} : '0');
Branch: 2 branches
BranchTrueFalseTotal
defined &BATsh::CMD::_get_errorlevel ? : 3 0 3
exists $BATsh::Env::STORE{'ERRORLEVEL'} ? : 0 0 0
179 }
180 78 ▶ return exists($STORE{$upper}) ? $STORE{$upper} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $BATsh::Env::STORE{$upper} ? : 78 0 78
181 }
182  
183 # ----------------------------------------------------------------
184 # _expand_var_modifier: %VAR:~n,m% substring / %VAR:str1=str2% substitution
185 #
186 # Substring form (cmd.exe compatible):
187 # %VAR:~n% characters from offset n to end
188 # %VAR:~n,m% m characters starting at offset n (negative = from end)
189 #
190 # Substitution form:
191 # %VAR:str1=str2% replace first occurrence of str1 with str2
192 # %VAR:*str1=str2% replace from start up-to-and-including first str1
193 # with str2 (cmd.exe *-prefix behaviour)
194 # ----------------------------------------------------------------
195 sub _expand_var_modifier {
196 15 ▶ my ($varname, $modifier) = @_;
Subroutine _expand_var_modifier: called CC=14 SCAR=26.6
197 15 my $val = do {
198 15 my $k = uc($varname);
199 15 ▶ exists($STORE{$k}) ? $STORE{$k} : ''
Branch: 1 branch
BranchTrueFalseTotal
exists $BATsh::Env::STORE{$k} ? : 15 0 15
200 };
201  
202 # Substring: ~n or ~n,m
203 15 ▶ if ($modifier =~ /\A~(-?\d+)(?:,(-?\d+))?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modifier =~ /\A~(-?\d+)(?:,(-?\d+))?\z/) 9 6 15
204 9 my ($n, $m) = ($1, $2);
205 9 my $len = BATsh::MB::mb_length($val);
206 9 ▶ my $start = ($n < 0) ? $len + $n : $n;
Branch: 1 branch
BranchTrueFalseTotal
$n < 0 ? : 1 8 9
207 9 ▶ $start = 0 if $start < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $start < 0 0 9 9
208 9 ▶ return '' if $start >= $len;
Branch: 1 branch
BranchTrueFalseTotal
if $start >= $len 1 8 9
209 8 ▶ if (!defined $m) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $m) 2 6 8
210 2 return BATsh::MB::mb_substr($val, $start);
211 }
212 6 my $end;
213 6 ▶ if ($m < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m < 0) { } 1 5 6
214 1 $end = $len + $m;
215 }
216 else {
217 5 $end = $start + $m;
218 }
219 6 ▶ $end = $len if $end > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $end > $len 0 6 6
220 6 ▶ return '' if $end <= $start;
Branch: 1 branch
BranchTrueFalseTotal
if $end <= $start 1 5 6
221 5 return BATsh::MB::mb_substr($val, $start, $end - $start);
222 }
223  
224 # Substitution: str1=str2 or *str1=str2
225 6 ▶ if ($modifier =~ /\A(\*?)([^=]*)=(.*)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modifier =~ /\A(\*?)([^=]*)=(.*)\z/) 6 0 6
226 6 my ($star, $str1, $str2) = ($1, $2, $3);
227 6 ▶ if ($star eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($star eq '*') { } 1 5 6
228 1 my $pos = index(lc($val), lc($str1));
229 1 ▶ if ($pos >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= 0) 1 0 1
230 1 return $str2 . substr($val, $pos + length($str1));
231 }
232 0 return $val;
233 }
234 else {
235 5 my $lval = lc($val);
236 5 my $lstr1 = lc($str1);
237 5 my $pos = index($lval, $lstr1);
238 5 ▶ if ($pos >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= 0) 4 1 5
239 4 return substr($val, 0, $pos) . $str2
240 . substr($val, $pos + length($str1));
241 }
242 1 return $val;
243 }
244 }
245  
246 # Unrecognised modifier: return as-is
247 0 return '%' . $varname . ':' . $modifier . '%';
248 }
249  
250 # Uses File::Spec (platform-aware) and a hand-rolled path splitter so
251 # that Windows-style paths work correctly on Windows and Unix-style
252 # paths work on Unix without requiring Win32-specific modules.
253 # ----------------------------------------------------------------
254 sub _expand_tilde_param {
255 16 ▶ my ($mods, $n) = @_;
Subroutine _expand_tilde_param: called CC=22 SCAR=31.4
256 16 my $key = "%$n";
257 16 ▶ my $val = exists($STORE{$key}) ? $STORE{$key} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $BATsh::Env::STORE{$key} ? : 15 1 16
258  
259 # Always strip surrounding double-quotes first
260 16 $val =~ s/\A"//;
261 16 $val =~ s/"\z//;
262  
263 # With no recognised modifiers, just return the dequoted value
264 16 ▶ return $val unless $mods =~ /[fdpnx]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mods =~ /[fdpnx]/ 3 13 16
265  
266 # --- Normalise: extract drive letter first, then convert \ to / ---
267 # Extracting the drive before splitting avoids "C:" being treated as
268 # a path component and re-attached incorrectly.
269 13 my $drv = ''; # e.g. "C:" on Windows, "" on Unix
270 13 my $path = $val;
271 13 $path =~ s{\\}{/}g; # normalise separators
272 13 ▶ if ($path =~ s{\A([A-Za-z]:)}{}) { $drv = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ s/\A([A-Za-z]:)//) 4 9 13
273  
274 # --- resolve to absolute path when f/d/p requested ---
275 13 ▶ if ($mods =~ /[fdp]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mods =~ /[fdp]/) 4 9 13
276 4 ▶ unless ($path =~ m{\A/} || $drv ne '') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[\A/] or $drv ne "") 2 2 4
Condition66%2/3
$path =~ m[\A/] or $drv ne ""
l!l&&r!l&&!r
202
MC/DC50%1/2
$path =~ m[\A/] or $drv ne ""
$path =~ m[\A/] $drv ne ""
Truth table66%2/3
A or B
A= $path =~ m[\A/]B= $drv ne ""
ABresult
1X1
011
000
277 # relative Unix path: prepend cwd
278 2 ▶ my $cwd = BATsh::MB::enc(defined(&Cwd::cwd) ? Cwd::cwd() : '.');
Branch: 1 branch
BranchTrueFalseTotal
defined &Cwd::cwd ? : 2 0 2
279 2 $cwd =~ s{\\}{/}g;
280 2 $cwd =~ s{/+\z}{};
281 2 $path = "$cwd/$path";
282 }
283 # Ensure exactly one leading slash
284 4 ▶ $path = "/$path" unless $path =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[\A/] 0 4 4
285 # Collapse . and ..
286 4 my @segs;
287 4 for my $p (split m{/+}, $path) {
288 23 ▶ next if $p eq '' || $p eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "" or $p eq "." 4 19 23
Condition66%2/3
$p eq "" or $p eq "."
l!l&&r!l&&!r
4019
MC/DC50%1/2
$p eq "" or $p eq "."
$p eq "" $p eq "."
Truth table66%2/3
A or B
A= $p eq ""B= $p eq "."
ABresult
1X1
011
000
289 19 ▶ if ($p eq '..') { pop @segs if @segs }
Branch: 2 branches
BranchTrueFalseTotal
if ($p eq '..') { } 0 19 19
if @segs 0 0 0
290 19 else { push @segs, $p }
291 }
292 4 $path = '/' . join('/', @segs);
293 4 ▶ $path = '/' if $path eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "/" 0 4 4
294 }
295  
296 # --- split path into directory and filename ---
297 13 my ($dirs, $file) = ('', '');
298 13 ▶ if ($path =~ m{\A(.*/)([^/]*)\z}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[\A(.*/)([^/]*)\z]) { } 9 4 13
299 9 ($dirs, $file) = ($1, $2);
300 }
301 else {
302 4 $file = $path;
303 }
304  
305 # --- split filename into base and extension ---
306 13 my ($base, $ext) = ('', '');
307 13 ▶ if ($file =~ m{\A(.+)(\.[^.]+)\z}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\A(.+)(\.[^.]+)\z/) { } 13 0 13
308 13 ($base, $ext) = ($1, $2);
309 }
310 else {
311 0 $base = $file;
312 }
313  
314 # --- build result ---
315 13 ▶ if ($mods =~ /f/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mods =~ /f/) 1 12 13
316 # Full absolute path: drive + dirs + file
317 # dirs already ends with / when non-root
318 1 return $drv . $dirs . $file;
319 }
320  
321 12 my $result = '';
322 12 ▶ $result .= $drv if $mods =~ /d/;
Branch: 1 branch
BranchTrueFalseTotal
if $mods =~ /d/ 2 10 12
323 12 ▶ $result .= $dirs if $mods =~ /p/;
Branch: 1 branch
BranchTrueFalseTotal
if $mods =~ /p/ 3 9 12
324 12 ▶ $result .= $base if $mods =~ /n/;
Branch: 1 branch
BranchTrueFalseTotal
if $mods =~ /n/ 6 6 12
325 12 ▶ $result .= $ext if $mods =~ /x/;
Branch: 1 branch
BranchTrueFalseTotal
if $mods =~ /x/ 5 7 12
326 12 return $result;
327 }
328  
329 # ----------------------------------------------------------------
330 # expand_sh: $VAR and ${VAR} (SH mode)
331 # ----------------------------------------------------------------
332 sub expand_sh {
333 0 ▶ my ($class, $str) = @_;
Subroutine expand_sh: not called CC=6 SCAR=37.4
Pod documented
334 0 ▶ return '' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
335 0 $str =~ s/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/
336 0 ▶ do { my $k=$1; defined($STORE{$k}) ? $STORE{$k} : defined($STORE{uc($k)}) ? $STORE{uc($k)} : '' }
Branch: 2 branches
BranchTrueFalseTotal
defined $BATsh::Env::STORE{$k} ? : 0 0 0
defined $BATsh::Env::STORE{uc $k} ? : 0 0 0
337 /ge;
338 0 $str =~ s/\$([A-Za-z_][A-Za-z0-9_]*)/
339 0 ▶ do { my $k=$1; defined($STORE{$k}) ? $STORE{$k} : defined($STORE{uc($k)}) ? $STORE{uc($k)} : '' }
Branch: 2 branches
BranchTrueFalseTotal
defined $BATsh::Env::STORE{$k} ? : 0 0 0
defined $BATsh::Env::STORE{uc $k} ? : 0 0 0
340 /ge;
341 0 return $str;
342 }
343  
344 36 1;
345  
346 __END__
« lib/BATsh/MB.pm ↑ Summary blib/script/batsh.pl »