ArduinoBuilder/FilePath.pm

filter: Statementstmt 60.5% 43 / 71 Branchbran 27.7% 5 / 18 Conditioncond 29.4% 5 / 17 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 75.0% 12 / 16 Podpod 0.0% 0 / 3 totaltotal 50.0% 68 / 136 CC 18 SCAR 28.2
CC
18
Cov
50%
__ANON__
56.0
find_all_files_with_extensions
20.0
list_sub_directories
12.0
CRAP 16.7
« ArduinoBuilder/System.pm ↑ Summary ArduinoBuilder/Config.pm »
1 package App::ArduinoBuilder::FilePath;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use App::ArduinoBuilder::System 'system_canonpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Spec::Functions 'catdir';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use List::Util 'min', 'any';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Log::Any::Simple ':default';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our @EXPORT_OK = qw(find_latest_revision_dir list_sub_directories find_all_files_with_extensions);
15  
16 88 ▶sub _compare_version_string {
Subroutine _compare_version_string: called CC=4 SCAR=13.9
17 88 my @la = split /\.|-/, $a;
18 88 my @lb = split /\.|-/, $b;
19 88 for my $i (0..min($#la, $#lb)) {
20 # Let’s try to handle things like: 1.5.0-b
21 176 ▶ my $c = $la[$i] <=> $lb[$i] || $la[$i] cmp $lb[$i];
Condition66%2/3
$la[$i] <=> $lb[$i] || $la[$i] cmp $lb[$i]
l!l&&r!l&&!r
570119
MC/DC50%1/2
$la[$i] <=> $lb[$i] || $la[$i] cmp $lb[$i]
$la[$i] <=> $lb[$i] $la[$i] cmp $lb[$i]
Truth table66%2/3
A || B
A= $la[$i] <=> $lb[$i]B= $la[$i] cmp $lb[$i]
ABresult
1X1
011
000
22 176 ▶ return $c if $c;
Branch: 1 branch
BranchTrueFalseTotal
if $c 57 119 176
23 }
24 31 return $#la <=> $#lb;
25 }
26  
27 41 ▶sub _pick_highest_version_string {
Subroutine _pick_highest_version_string: called CC=1 SCAR=0.0
28 41 return (sort _compare_version_string @_)[-1];
29 }
30  
31 # find_latest_revision('/path/to/dir') --> '/path/to/dir/9.8.2'
32 # Returns the input if there are no sub-directories looking like revisions in
33 # the given directory.
34 2 ▶sub find_latest_revision_dir {
Subroutine find_latest_revision_dir: called CC=4 SCAR=13.9
Pod undocumented
35 2 my ($dir) = @_;
36 2 ▶ opendir my $dh, $dir or fatal "Can’t open dir '$dir': $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or fatal("Can\x{2019}t open dir '${dir}': $!") 2 0 2
37 2 ▶ my @revs_dir = grep { -d catdir($dir, $_) && m/^\d+(?:\.\d+)?(?:-.*)?/ } readdir($dh);
Condition100%3/3
-d catdir($dir, $_) && /^\d+(?:\.\d+)?(?:-.*)?/
!ll&&!rl&&r
144
MC/DC100%2/2
-d catdir($dir, $_) && /^\d+(?:\.\d+)?(?:-.*)?/
-d catdir($dir, $_) /^\d+(?:\.\d+)?(?:-.*)?/
Truth table100%3/3
A && B
A= -d catdir($dir, $_)B= /^\d+(?:\.\d+)?(?:-.*)?/
ABresult
0X0
100
111
38 2 closedir $dh;
39 2 ▶ return $dir unless @revs_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless @revs_dir 1 1 2
40 1 return catdir($dir, _pick_highest_version_string(@revs_dir));
41 }
42  
43 0 ▶sub list_sub_directories {
Subroutine list_sub_directories: not called CC=3 SCAR=24.8
Pod undocumented
44 0 my ($dir) = @_;
45 0 ▶ opendir my $dh, $dir or fatal "Can’t open dir '$dir': $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or fatal("Can\x{2019}t open dir '${dir}': $!") 0 0 0
46 0 ▶ my @sub_dirs = grep { -d catdir($dir, $_) && ! m/^\./ } readdir($dh);
Condition0%0/3
-d catdir($dir, $_) && !/^\./
!ll&&!rl&&r
000
MC/DC0%0/2
-d catdir($dir, $_) && !/^\./
-d catdir($dir, $_) !/^\./
Truth table0%0/3
A && not(B)
A= -d catdir($dir, $_)B= !/^\./
ABresult
0X0
100
111
47 0 closedir $dh;
48 0 return @sub_dirs;
49 }
50  
51 # $dir can be a single directory to search or an array ref.
52 # excluded_dirs must be an array_ref
53 0 ▶sub find_all_files_with_extensions {
Subroutine find_all_files_with_extensions: not called CC=4 SCAR=30.0
Pod undocumented
54 0 my ($dir, $exts, $excluded_dirs, $no_recurse) = @_;
55 0 my $exts_re = join('|', @{$exts});
56 0 ▶ my @excluded_dirs = map { system_canonpath($_) } @{$excluded_dirs // []};
Condition0%0/2
$excluded_dirs // []
l!l
00
MC/DC0%0/1
$excluded_dirs // []
$excluded_dirs
Truth table0%0/2
A
A= $excluded_dirs
Aresult
11
00
57 0 my @found;
58 0 ▶ my @dirs = ref $dir ? @{$dir} : $dir;
Branch: 1 branch
BranchTrueFalseTotal
ref $dir ? : 0 0 0
59 0 for my $d (@dirs) {
60 0 ▶ find(sub { push @found, $File::Find::name if -f && m/\.(?:$exts_re)$/;
Subroutine __ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ and /\.(?:$exts_re)$/ 0 0 0
Condition0%0/3
-f $_ and /\.(?:$exts_re)$/
!ll&&!rl&&r
000
MC/DC0%0/2
-f $_ and /\.(?:$exts_re)$/
-f $_ /\.(?:$exts_re)$/
Truth table0%0/3
A and B
A= -f $_B= /\.(?:$exts_re)$/
ABresult
0X0
100
111
61 0 ▶ if (-d) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_) 0 0 0
62 # $_ eq '.' only on the first, root directly that we are crawling.
63 0 ▶ if ($no_recurse && $_ ne '.') {
Branch: 2 branches
BranchTrueFalseTotal
if ($no_recurse and $_ ne '.') { } 0 0 0
elsif (/^\..+/) { } 0 0 0
Condition0%0/3
$no_recurse and $_ ne "."
!ll&&!rl&&r
000
MC/DC0%0/2
$no_recurse and $_ ne "."
$no_recurse $_ ne "."
Truth table0%0/3
A and B
A= $no_recurseB= $_ ne "."
ABresult
0X0
100
111
64 0 $File::Find::prune = 1;
65 0 return;
66 } elsif (/^\..+/) {
67 0 $File::Find::prune = 1;
68 0 return;
69 }
70 0 my $a = system_canonpath($_);
71 0 ▶ $File::Find::prune = any { $_ eq $a } @excluded_dirs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 }
73 0 }, $d);
74 }
75 0 return @found;
76 }
77  
78 2 1;
« ArduinoBuilder/System.pm ↑ Summary ArduinoBuilder/Config.pm »