| 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]
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]
| |||||||||||||||||||||||||||||||||
| 22 | 176 | ▶ | return $c if $c; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | my @revs_dir = grep { -d catdir($dir, $_) && m/^\d+(?:\.\d+)?(?:-.*)?/ } readdir($dh); | ||||||||||||||||||||||||||||||
|
Condition100%3/3
-d catdir($dir, $_) && /^\d+(?:\.\d+)?(?:-.*)?/
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+)?(?:-.*)?/
| |||||||||||||||||||||||||||||||||
| 38 | 2 | closedir $dh; | |||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | return $dir unless @revs_dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my @sub_dirs = grep { -d catdir($dir, $_) && ! m/^\./ } readdir($dh); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
-d catdir($dir, $_) && !/^\./
MC/DC0%0/2
-d catdir($dir, $_) && !/^\./
-d catdir($dir, $_)
!/^\./
Truth table0%0/3
A && not(B)
A= -d catdir($dir, $_)B= !/^\./
| |||||||||||||||||||||||||||||||||
| 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 // []
MC/DC0%0/1
$excluded_dirs // []
$excluded_dirs
Truth table0%0/2
A
A= $excluded_dirs
| |||||||||||||||||||||||||||||||||
| 57 | 0 | my @found; | |||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my @dirs = ref $dir ? @{$dir} : $dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
-f $_ and /\.(?:$exts_re)$/
MC/DC0%0/2
-f $_ and /\.(?:$exts_re)$/
-f $_
/\.(?:$exts_re)$/
Truth table0%0/3
A and B
A= -f $_B= /\.(?:$exts_re)$/
| |||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (-d) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | # $_ eq '.' only on the first, root directly that we are crawling. | ||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($no_recurse && $_ ne '.') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$no_recurse and $_ ne "."
MC/DC0%0/2
$no_recurse and $_ ne "."
$no_recurse
$_ ne "."
Truth table0%0/3
A and B
A= $no_recurseB= $_ ne "."
| |||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||