lib/App/Yath/Script.pm

filter: Statementstmt 94.5% 206 / 218 Branchbran 83.3% 90 / 108 Conditioncond 81.6% 40 / 49 MC/DCmcdc 66.6% 20 / 30 Subroutinesub 89.6% 26 / 29 Podpod 42.1% 8 / 19 totaltotal 86.0% 390 / 453 CC 80 SCAR 19.3
CC
80
Cov
90%
find_rc_updir
14.1
find_alt_script
11.3
do_begin
9.5
CRAP 6.9
↑ Summary lib/App/Yath/Script/V0.pm »
1 package App::Yath::Script;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 ▶use Cwd qw/realpath/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use File::Spec();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 ▶use Importer Importer => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 our @EXPORT_OK = (
12 qw{
13 script
14 module
15  
16 do_exec
17  
18 clean_path
19 find_in_updir
20 find_rc_updir
21 mod2file
22 },
23 );
24  
25 13 our $VERSION = '2.000017';
26  
27 13 our ($SCRIPT, $MOD);
28  
29 0 ▶sub script { $SCRIPT }
Subroutine script: not called CC=1 SCAR=6.9
Pod documented
30 0 ▶sub module { $MOD }
Subroutine module: not called CC=1 SCAR=6.9
Pod documented
31  
32 12 ▶sub do_begin {
Subroutine do_begin: called CC=9 SCAR=22.6
Pod documented
33 # Check for an explicit version as the very first argument (V# or v#).
34 # Strip it from @ARGV before anything else sees it.
35 12 my $cli_version;
36 12 ▶ if (@ARGV && $ARGV[0] =~ /^[Vv](\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV and $ARGV[0] =~ /^[Vv](\d+)$/) 4 8 12
Condition100%3/3
@ARGV and $ARGV[0] =~ /^[Vv](\d+)$/
!ll&&!rl&&r
174
MC/DC100%2/2
@ARGV and $ARGV[0] =~ /^[Vv](\d+)$/
@ARGV $ARGV[0] =~ /^[Vv](\d+)$/
Truth table100%3/3
A and B
A= @ARGVB= $ARGV[0] =~ /^[Vv](\d+)$/
ABresult
0X0
100
111
37 4 $cli_version = int($1);
38 4 shift @ARGV;
39 }
40  
41 12 my $argv = [@ARGV];
42 12 my @caller = caller();
43  
44 12 my $exec = 0;
45  
46 12 $SCRIPT = clean_path($caller[1]);
47 12 $ENV{YATH_SCRIPT} = $SCRIPT;
48  
49 12 inject_includes();
50  
51 12 my $local_vers = install_local_lib();
52  
53 12 ▶ $exec = 1 if find_alt_script();
Branch: 1 branch
BranchTrueFalseTotal
if find_alt_script() 0 12 12
54  
55 12 my ($config, $user_config, $version) = find_rc_files($cli_version);
56 12 ▶ $version //= $local_vers;
Condition33%1/3
$version //= $local_vers
l!l&&r!l&&!r
1200
MC/DC0%0/2
$version //= $local_vers
$version $local_vers
Truth table33%1/3
A //= B
A= $versionB= $local_vers
ABresult
1X1
011
000
57  
58 # Pre-parse the global section of the rc files for dev-libs flags
59 # so a user can put `-D` (etc) at the top of .yath.rc instead of on
60 # every CLI invocation. Only the global section is parsed -- command
61 # sections are reserved for the per-command parser since this layer
62 # has no idea which command is about to run. Run before the regular
63 # CLI -D pass so `T2_HARNESS_INCLUDES` carries everything across the
64 # re-exec triggered by either source.
65 12 ▶ $exec = 1 if parse_rc_dev_libs($config, $user_config);
Branch: 1 branch
BranchTrueFalseTotal
if parse_rc_dev_libs($config, $user_config) 0 12 12
66 12 ▶ $exec = 1 if parse_new_dev_libs();
Branch: 1 branch
BranchTrueFalseTotal
if parse_new_dev_libs() 0 12 12
67  
68 12 ▶ do_exec($argv) if $exec;
Branch: 1 branch
BranchTrueFalseTotal
if $exec 0 12 12
69  
70 12 ▶ $MOD = defined($version) ? load_yath_module($version) : load_latest_yath_module();
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 12 0 12
71  
72 12 $MOD->do_begin(
73 script => $SCRIPT,
74 argv => $argv,
75 config => $config,
76 user_config => $user_config,
77 );
78 }
79  
80 12 ▶sub do_runtime { $MOD->do_runtime(@_) }
Subroutine do_runtime: called CC=1 SCAR=0.0
Pod documented
81  
82 0 ▶sub do_exec {
Subroutine do_exec: not called CC=1 SCAR=6.9
Pod documented
83 0 my ($argv) = @_;
84 # Hooks (coderef, arrayref, blessed object) cannot be serialized. Anything
85 # that installed one via PERL5OPT installs it again in the new process, so
86 # only the paths need to survive the exec.
87 0 $ENV{T2_HARNESS_INCLUDES} = join ';' => grep { !ref $_ } @INC;
88 0 exec($^X, $SCRIPT, @$argv);
89 }
90  
91 12 ▶sub find_alt_script {
Subroutine find_alt_script: called CC=4 SCAR=24.2
Pod undocumented
92 12 my $script = './scripts/yath';
93 12 ▶ return 0 unless -f $script;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $script 12 0 12
94 0 ▶ return 0 unless -x $script;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $script 0 0 0
95  
96 0 $script = clean_path($script);
97  
98 0 ▶ return 0 if $script eq clean_path($SCRIPT);
Branch: 1 branch
BranchTrueFalseTotal
if $script eq clean_path($App::Yath::Script::SCRIPT) 0 0 0
99  
100 0 $SCRIPT = $script;
101  
102 0 return 1;
103 }
104  
105 15 ▶sub parse_new_dev_libs {
Subroutine parse_new_dev_libs: called CC=1 SCAR=0.0
Pod undocumented
106 15 return _install_dev_libs(_collect_dev_libs(@ARGV));
107 }
108  
109 20 ▶sub parse_rc_dev_libs {
Subroutine parse_rc_dev_libs: called CC=5 SCAR=16.1
Pod undocumented
110 20 ▶ my @files = grep { defined && length } @_;
Condition100%3/3
defined $_ && length $_
!ll&&!rl&&r
13218
MC/DC100%2/2
defined $_ && length $_
defined $_ length $_
Truth table100%3/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
111 20 ▶ return 0 unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 3 17 20
112  
113 17 my @args;
114 17 for my $file (@files) {
115 18 ▶ next unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 1 17 18
116 17 push @args => _rc_global_tokens($file);
117 }
118  
119 17 return _install_dev_libs(_collect_dev_libs(@args));
120 }
121  
122 # Walk a list of argv-style tokens looking for -D / --dev-lib(s) flags.
123 # Returns the list of paths to add to @INC.
124 48 ▶sub _collect_dev_libs {
Subroutine _collect_dev_libs: called CC=9 SCAR=22.0
125 48 my @args = @_;
126  
127 48 my @add;
128 48 for my $arg (@args) {
129 55 ▶ last if $arg eq '::';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "::" 2 53 55
130 53 ▶ last if $arg eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "--" 3 50 53
131  
132 50 ▶ next unless $arg =~ m/^(?:-D|--dev-libs?)(?:=(.+))?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg =~ /^(?:-D|--dev-libs?)(?:=(.+))?$/ 31 19 50
133 19 my $val = $1;
134  
135 19 ▶ unless (defined $val && length $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val and length $val) 4 15 19
Condition66%2/3
defined $val and length $val
!ll&&!rl&&r
4015
MC/DC50%1/2
defined $val and length $val
defined $val length $val
Truth table66%2/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
136 4 push @add => map { clean_path($_) } 'lib', 'blib/lib', 'blib/arch';
137 4 next;
138 }
139  
140 15 for my $path (split /,/, $val) {
141 13 ▶ if ($path =~ m/\*/) { push @add => glob($path) }
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\*/) { } 1 18 19
142 18 else { push @add => $path }
143 }
144 }
145  
146 48 return @add;
147 }
148  
149 # Dedup against @INC and prepend. Returns 1 if anything was added.
150 36 ▶sub _install_dev_libs {
Subroutine _install_dev_libs: called CC=4 SCAR=13.9
151 36 my @add = @_;
152 36 ▶ return 0 unless @add;
Branch: 1 branch
BranchTrueFalseTotal
unless @add 30 6 36
153  
154 6 my %seen = map { ($_ => 1, clean_path($_) => 1) } @INC;
155 6 ▶ @add = grep { !($seen{$_} || $seen{clean_path($_)}) } @add;
Condition66%2/3
$seen{$_} || $seen{clean_path($_)}
l!l&&r!l&&!r
209
MC/DC50%1/2
$seen{$_} || $seen{clean_path($_)}
$seen{$_} $seen{clean_path($_)}
Truth table66%2/3
A || B
A= $seen{$_}B= $seen{clean_path($_)}
ABresult
1X1
011
000
156 6 ▶ return 0 unless @add;
Branch: 1 branch
BranchTrueFalseTotal
unless @add 1 5 6
157  
158 5 unshift @INC => @add;
159 5 return 1;
160 }
161  
162 # Tokenize the global section of an rc file into argv-style tokens.
163 # Stops at the first [section] marker. `--foo` and `--foo=bar` lines
164 # yield one token; `--foo bar` lines yield two, matching the format
165 # App::Yath2::ConfigFile uses for command sections.
166 22 ▶sub _rc_global_tokens {
Subroutine _rc_global_tokens: called CC=6 SCAR=17.9
167 22 my ($file) = @_;
168  
169 22 my @args;
170 22 ▶ open(my $fh, '<', $file) or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return 22 0 22
171 22 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 21 18 39
172 21 chomp $line;
173 21 $line =~ s/\s*[#;].*//;
174 21 $line =~ s/^\s+//;
175 21 $line =~ s/\s+$//;
176 21 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 4 17 21
177 17 ▶ last if $line =~ /^\[/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\[/ 4 13 17
178  
179 13 ▶ if ($line =~ /^(\S+)\s+(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(\S+)\s+(.+)$/) { } 1 12 13
180 1 push @args => ($1, $2);
181 }
182 else {
183 12 push @args => $line;
184 }
185 }
186 22 close($fh);
187  
188 22 return @args;
189 }
190  
191 # Locate the project- and user-level rc files plus the version number
192 # they imply. Returns ($config, $user_config, $version), each of which
193 # may be undef. When $cli_version is defined the caller's explicit
194 # version always wins; only versioned rc files matching that version
195 # are looked up.
196 18 ▶sub find_rc_files {
Subroutine find_rc_files: called CC=7 SCAR=19.5
Pod undocumented
197 18 my ($cli_version) = @_;
198  
199 18 ▶ if (defined $cli_version) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cli_version) 7 11 18
200 # Explicit version on CLI: prefer matching versioned rc files,
201 # but fall back to plain .yath.rc / .yath.user.rc when no
202 # versioned match exists. Accept both .yath.v#.rc and
203 # .yath.V#.rc.
204 7 ▶ my $config = find_in_updir(".yath.v${cli_version}.rc")
Condition100%6/6
(find_in_updir(".yath.v$cli_version.rc") // find_in_updir(".yath.V$cli_version.rc")) // find_in_updir(".yath.rc")
l!l&&r!l&&!r
511
find_in_updir(".yath.v$cli_version.rc") // find_in_updir(".yath.V$cli_version.rc")
l!l&&r!l&&!r
412
MC/DC100%3/3
(find_in_updir(".yath.v$cli_version.rc") // find_in_updir(".yath.V$cli_version.rc")) // find_in_updir(".yath.rc")
find_in_updir(".yath.v$cli_version.rc") find_in_updir(".yath.V$cli_version.rc") find_in_updir(".yath.rc")
Truth table100%4/4
A // B // C
A= find_in_updir(".yath.v$cli_version.rc")B= find_in_updir(".yath.V$cli_version.rc")C= find_in_updir(".yath.rc")
ABCresult
1XX1
01X1
0011
0000
205 // find_in_updir(".yath.V${cli_version}.rc")
206 // find_in_updir(".yath.rc");
207 7 ▶ my $user_config = find_in_updir(".yath.user.v${cli_version}.rc")
Condition83%5/6
(find_in_updir(".yath.user.v$cli_version.rc") // find_in_updir(".yath.user.V$cli_version.rc")) // find_in_updir(".yath.user.rc")
l!l&&r!l&&!r
115
find_in_updir(".yath.user.v$cli_version.rc") // find_in_updir(".yath.user.V$cli_version.rc")
l!l&&r!l&&!r
106
MC/DC66%2/3
(find_in_updir(".yath.user.v$cli_version.rc") // find_in_updir(".yath.user.V$cli_version.rc")) // find_in_updir(".yath.user.rc")
find_in_updir(".yath.user.v$cli_version.rc") find_in_updir(".yath.user.V$cli_version.rc") find_in_updir(".yath.user.rc")
Truth table75%3/4
A // B // C
A= find_in_updir(".yath.user.v$cli_version.rc")B= find_in_updir(".yath.user.V$cli_version.rc")C= find_in_updir(".yath.user.rc")
ABCresult
1XX1
01X1
0011
0000
208 // find_in_updir(".yath.user.V${cli_version}.rc")
209 // find_in_updir(".yath.user.rc");
210 7 return ($config, $user_config, $cli_version);
211 }
212  
213 11 my ($config, $config_version) = find_rc_updir('.yath');
214 11 my ($user_config, $user_version) = find_rc_updir('.yath.user');
215  
216 # .yath.user(.v#).rc version takes precedence over .yath(.v#).rc.
217 # Either may be undef (plain unversioned rc); when both are undef
218 # the caller falls back to install_local_lib's version, then to
219 # load_yath_module's @INC scan.
220 11 ▶ my $version = $user_version // $config_version;
Condition100%3/3
$user_version // $config_version
l!l&&r!l&&!r
182
MC/DC100%2/2
$user_version // $config_version
$user_version $config_version
Truth table100%3/3
A // B
A= $user_versionB= $config_version
ABresult
1X1
011
000
221  
222 11 return ($config, $user_config, $version);
223 }
224  
225 # Load and return the App::Yath::Script::V{X} module to delegate to.
226 # Dies if the requested module fails to load. V0 is reserved for
227 # script validation and emits a warning when explicitly requested.
228 14 ▶sub load_yath_module {
Subroutine load_yath_module: called CC=3 SCAR=11.0
Pod undocumented
229 14 my ($version) = @_;
230  
231 14 ▶ warn "Warning: Version '0' is for validating the yath script only, it should not be used for any real testing.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $version == 0 13 1 14
232 if $version == 0;
233  
234 14 my $mod = "App::Yath::Script::V${version}";
235 14 my $file = mod2file($mod);
236 14 ▶ eval { require $file; 1 } or die "Could not load $mod: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $file; 1 } } or die "Could not load ${mod}: $@" 13 1 14
237 13 return $mod;
238 }
239  
240 # Scan @INC for installed App::Yath::Script::V#.pm modules and return
241 # the version numbers sorted highest-first. V0 is excluded since it is
242 # reserved for script validation and must never be auto-selected.
243 4 ▶sub find_installed_versions {
Subroutine find_installed_versions: called CC=7 SCAR=19.5
Pod undocumented
244 4 my %found;
245 4 for my $inc (@INC) {
246 4 ▶ next if ref $inc;
Branch: 1 branch
BranchTrueFalseTotal
if ref $inc 0 4 4
247 4 my $dir = File::Spec->catdir($inc, 'App', 'Yath', 'Script');
248 4 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 1 3 4
249 3 ▶ opendir(my $dh, $dir) or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or next 3 0 3
250 3 for my $entry (readdir $dh) {
251 14 ▶ $found{$1} = 1 if $entry =~ /^V(\d+)\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
if $entry =~ /^V(\d+)\.pm$/ 8 6 14
252 }
253 3 closedir $dh;
254 }
255 4 delete $found{0};
256 4 return sort { $b <=> $a } keys %found;
257 }
258  
259 # Final fallback when no version was captured from CLI, rc files, or a
260 # local checkout. Tries each installed App::Yath::Script::V# module
261 # from highest to lowest until one loads. Dies with the collected load
262 # errors if none succeed (or if none are installed).
263 3 ▶sub load_latest_yath_module {
Subroutine load_latest_yath_module: called CC=4 SCAR=13.9
Pod undocumented
264 3 my @vers = find_installed_versions();
265  
266 3 ▶ die "No App::Yath (App::Yath::Script::V#) modules appear to be installed.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @vers 1 2 3
267 unless @vers;
268  
269 2 my @err;
270 2 for my $v (@vers) {
271 3 my $mod = "App::Yath::Script::V${v}";
272 3 my $file = mod2file($mod);
273 3 ▶ return $mod if eval { require $file; 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { require $file; 1 } } 2 1 3
274 1 push @err => $@;
275 }
276  
277 0 die join "\n" => (
278 "No Test2::Harness (App::Yath) versions could be loaded:",
279 @err,
280 );
281 }
282  
283 15 ▶sub inject_includes {
Subroutine inject_includes: called CC=2 SCAR=6.9
Pod undocumented
284 15 ▶ return unless $ENV{T2_HARNESS_INCLUDES};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"T2_HARNESS_INCLUDES"} 13 2 15
285 # Keep any hooks this process already has. PERL5OPT runs before us, so a
286 # tool like Carmel has already reinstalled the hook that makes its modules
287 # findable, and replacing @INC outright would throw it away.
288 2 @INC = (grep({ ref $_ } @INC), split(/;/, $ENV{T2_HARNESS_INCLUDES}));
289 }
290  
291 # Scan ./lib/App/Yath/Script for V#.pm modules and return the highest
292 # version found, or undef when no such modules are present. Used by
293 # install_local_lib() to detect a working-copy checkout that ships its
294 # own versioned script module.
295 21 ▶sub find_local_version {
Subroutine find_local_version: called CC=7 SCAR=19.5
Pod undocumented
296 21 my $local_path = File::Spec->catdir(File::Spec->curdir, 'lib', 'App', 'Yath', 'Script');
297 21 ▶ return undef unless -d $local_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $local_path 15 6 21
298 6 ▶ opendir(my $dh, $local_path) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $local_path or return undef 6 0 6
299  
300 6 my $vers;
301 6 for my $file (readdir($dh)) {
302 22 ▶ next unless $file =~ m/^V(\d+)\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /^V(\d+)\.pm$/ 13 9 22
303 9 my $n = int($1);
304 9 ▶ $vers = $n if !defined($vers) || $n > $vers;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $vers or $n > $vers 7 2 9
Condition100%3/3
not defined $vers or $n > $vers
l!l&&r!l&&!r
522
MC/DC100%2/2
not defined $vers or $n > $vers
not defined $vers $n > $vers
Truth table100%3/3
not(A) or B
A= not defined $versB= $n > $vers
ABresult
1X1
011
000
305 }
306 6 closedir $dh;
307  
308 6 return $vers;
309 }
310  
311 # If the cwd contains ./lib/App/Yath/Script/V#.pm modules, ensure ./lib
312 # is at the front of @INC so they take precedence over any installed
313 # copy. Returns the highest local version found, or undef if no local
314 # modules exist. Idempotent: a re-exec that already has ./lib in @INC
315 # (via T2_HARNESS_INCLUDES) does not re-print or re-unshift.
316 15 ▶sub install_local_lib {
Subroutine install_local_lib: called CC=3 SCAR=11.0
Pod undocumented
317 15 my $local_vers = find_local_version();
318 15 ▶ return undef unless defined $local_vers;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local_vers 13 2 15
319  
320 2 my $lib_path = clean_path(File::Spec->catdir(File::Spec->curdir, 'lib'));
321 2 ▶ return $local_vers if grep { clean_path($_) eq $lib_path } @INC;
Branch: 1 branch
BranchTrueFalseTotal
if grep {clean_path($_) eq $lib_path;} @INC 1 1 2
322  
323 1 print "Detected App::Yath::Script::V# modules in local ./lib, adding '$lib_path' to the front of \@INC.\n";
324 1 unshift @INC => $lib_path;
325  
326 1 return $local_vers;
327 }
328  
329 70 ▶sub clean_path {
Subroutine clean_path: called CC=5 SCAR=16.1
Pod documented
330 70 my ( $path, $absolute ) = @_;
331  
332 70 ▶ confess "No path was provided to clean_path()" unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 2 68 70
333  
334 68 ▶ $absolute //= 1;
Condition100%2/2
$absolute //= 1
l!l
167
MC/DC100%1/1
$absolute //= 1
$absolute
Truth table100%2/2
A
A= $absolute
Aresult
11
00
335 68 ▶ $path = realpath($path) // $path if $absolute;
Branch: 1 branch
BranchTrueFalseTotal
if $absolute 67 1 68
Condition66%2/3
realpath($path) // $path
l!l&&r!l&&!r
6250
MC/DC0%0/2
realpath($path) // $path
realpath($path) $path
Truth table66%2/3
A // B
A= realpath($path)B= $path
ABresult
1X1
011
000
336  
337 68 return File::Spec->rel2abs($path);
338 }
339  
340 37 ▶sub find_rc_updir {
Subroutine find_rc_updir: called CC=14 SCAR=26.5
Pod undocumented
341 37 my ($prefix) = @_;
342  
343 37 my $versioned_pattern = qr/^\Q$prefix\E\.[Vv](\d+)\.rc$/;
344 37 my $plain_name = "$prefix.rc";
345  
346 37 my $abs = eval { realpath(File::Spec->rel2abs('.')) };
347 37 my %seen;
348 37 ▶ while ($abs && !$seen{$abs}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($abs and not $seen{$abs}++) 60 11 71
Condition66%2/3
$abs and not $seen{$abs}++
!ll&&!rl&&r
01160
MC/DC50%1/2
$abs and not $seen{$abs}++
$abs not $seen{$abs}++
Truth table66%2/3
A and not(B)
A= $absB= not $seen{$abs}++
ABresult
0X0
100
111
349 # Priority 1: plain name that is a symlink to a versioned file.
350 60 my $plain_path = File::Spec->catfile($abs, $plain_name);
351 60 ▶ if (-l $plain_path && -f $plain_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $plain_path and -f $plain_path) 5 55 60
Condition66%2/3
-l $plain_path and -f $plain_path
!ll&&!rl&&r
5505
MC/DC50%1/2
-l $plain_path and -f $plain_path
-l $plain_path -f $plain_path
Truth table66%2/3
A and B
A= -l $plain_pathB= -f $plain_path
ABresult
0X0
100
111
352 5 ▶ my $target = readlink($plain_path) // '';
Condition50%1/2
readlink $plain_path // ""
l!l
50
MC/DC0%0/1
readlink $plain_path // ""
readlink $plain_path
Truth table50%1/2
A
A= readlink $plain_path
Aresult
11
00
353 5 ▶ if ((File::Spec->splitpath($target))[2] =~ $versioned_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if (("File::Spec"->splitpath($target))[2] =~ /$versioned_pattern/) 5 0 5
354 5 return ($plain_path, int($1));
355 }
356 }
357  
358 # Priority 2: explicitly versioned file -- highest version wins.
359 55 ▶ if (opendir(my $dh, $abs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $abs) 55 0 55
360 55 my ($best_ver, $best_entry);
361 55 for my $entry (readdir $dh) {
362 498 ▶ next unless $entry =~ $versioned_pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry =~ /$versioned_pattern/ 478 20 498
363 20 my $v = int($1);
364 20 ▶ if (!defined($best_ver) || $v > $best_ver) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $best_ver or $v > $best_ver) 19 1 20
Condition100%3/3
not defined $best_ver or $v > $best_ver
l!l&&r!l&&!r
1721
MC/DC100%2/2
not defined $best_ver or $v > $best_ver
not defined $best_ver $v > $best_ver
Truth table100%3/3
not(A) or B
A= not defined $best_verB= $v > $best_ver
ABresult
1X1
011
000
365 19 $best_ver = $v;
366 19 $best_entry = $entry;
367 }
368 }
369 55 closedir $dh;
370 55 ▶ if (defined $best_ver) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $best_ver) 17 38 55
371 17 return (File::Spec->catfile($abs, $best_entry), $best_ver);
372 }
373 }
374  
375 # Priority 3: plain unversioned file -- no version captured, the
376 # caller (find_rc_files / install_local_lib / load_yath_module)
377 # decides what version to use.
378 38 ▶ if (-f $plain_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $plain_path) 4 34 38
379 4 return ($plain_path, undef);
380 }
381  
382 34 $abs = eval { realpath(File::Spec->catdir($abs, '..')) };
383 }
384  
385 11 return;
386 }
387  
388 33 ▶sub find_in_updir {
Subroutine find_in_updir: called CC=5 SCAR=16.2
Pod documented
389 33 my $path = shift;
390 33 ▶ return clean_path($path) if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 9 24 33
391  
392 24 my %seen;
393 24 while(1) {
394 75 $path = File::Spec->catdir('..', $path);
395 75 my $check = eval { realpath(File::Spec->rel2abs($path)) };
396 75 ▶ last unless $check;
Branch: 1 branch
BranchTrueFalseTotal
unless $check 0 75 75
397 75 ▶ last if $seen{$check}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$check}++ 24 51 75
398 51 ▶ return $check if -e $check;
Branch: 1 branch
BranchTrueFalseTotal
if -e $check 0 51 51
399 }
400  
401 24 return;
402 }
403  
404 22 ▶sub mod2file {
Subroutine mod2file: called CC=2 SCAR=6.9
Pod documented
405 22 my ($mod) = @_;
406 22 ▶ confess "No module name provided" unless $mod;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod 2 20 22
407 20 my $file = $mod;
408 20 $file =~ s{::}{/}g;
409 20 $file .= ".pm";
410 20 return $file;
411 }
412  
413 13 1;
414  
415 __END__
↑ Summary lib/App/Yath/Script/V0.pm »