| 1 | package TUI::StdDlg::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: defines utility functions used for Standard Dialogs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | our $VERSION = '2.000002'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | fexpand | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | driveValid | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | isDir | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | pathValid | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | validFileName | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | getCurDir | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | getHomeDir | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | isWild | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | all => \@EXPORT_OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | ▶ | use Scalar::Util qw( readonly ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 10 | ▶ | use TUI::toolkit qw( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | :boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | :utils | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | Maybe | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | :is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | :types | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 10 | ▶ | use TUI::StdDlg::Const qw( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | DIRECTORY | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | FA_DIREC | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | :MAX | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 10 | ▶ | use TUI::StdDlg::Dos; # ffblk | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | ▶ | use TUI::StdDlg::Dir qw( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | getcurdir | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | getdisk | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | findfirst | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | fnmerge | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | fnsplit | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 10 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | my ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | $skip, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $squeeze, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | $isSep, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $isHomeExpand, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $isAbsolute, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $addFinalSep, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $getPathDrive, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 46 | ▶ | $skip = sub { # void ($src, $k) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 46 | my ( $src, $k ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 46 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 46 | ▶ | assert ( is_Str $src ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 46 | ▶ | assert ( is_Str $k ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 46 | ▶ | while ( length( $src ) && substr( $src, 0, 1 ) eq $k ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $src and substr($src, 0, 1) eq $k
MC/DC100%2/2
length $src and substr($src, 0, 1) eq $k
length $src
substr($src, 0, 1) eq $k
Truth table100%3/3
A and B
A= length $srcB= substr($src, 0, 1) eq $k
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | substr( $src, 0, 1, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 46 | $_[0] = $src; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 46 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | ▶ | $squeeze = sub { # void ($path) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=18 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 8 | my ( $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 8 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | ▶ | assert ( is_Str $path ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | ▶ | assert ( not readonly $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | my $dest = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | my $src = $path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | my $last = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | ▶ | while ( length $src ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 356 | ▶ | if ( $last eq '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 44 | &$skip( $src, '\\' ); # skip repeated '\' | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 356 | ▶ | if ( ( !$last || $last eq '\\' ) && substr( $src, 0, 1 ) eq '.' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
!$last || $last eq "\\" and substr($src, 0, 1) eq "."
not $last or $last eq "\\"
MC/DC66%2/3
!$last || $last eq "\\" and substr($src, 0, 1) eq "."
not $last
$last eq "\\"
substr($src, 0, 1) eq "."
Truth table80%4/5
not(A) or B and C
A= not $lastB= $last eq "\\"C= substr($src, 0, 1) eq "."
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | substr( $src, 0, 1, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # have a '.' or '.\' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | ▶ | if ( !length( $src ) || substr( $src, 0, 1 ) eq '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
not length $src or substr($src, 0, 1) eq "\\"
MC/DC50%1/2
not length $src or substr($src, 0, 1) eq "\\"
not length $src
substr($src, 0, 1) eq "\\"
Truth table66%2/3
not(A) or B
A= not length $srcB= substr($src, 0, 1) eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | &$skip( $src, '\\' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # have a '..' or '..\' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ▶ | elsif ( substr( $src, 0, 1 ) eq '.' | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
substr($src, 0, 1) eq "." and length $src == 1 || substr($src, 1, 1) eq "\\"
length $src == 1 or substr($src, 1, 1) eq "\\"
MC/DC33%1/3
substr($src, 0, 1) eq "." and length $src == 1 || substr($src, 1, 1) eq "\\"
substr($src, 0, 1) eq "."
length $src == 1
substr($src, 1, 1) eq "\\"
Truth table50%2/4
A and B or C
A= substr($src, 0, 1) eq "."B= length $src == 1C= substr($src, 1, 1) eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | && ( length( $src ) == 1 || substr( $src, 1, 1 ) eq '\\' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # skip the following '.' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | substr( $src, 0, 1, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | &$skip( $src, '\\' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # back up to previous '\' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | substr( $dest, -1, 1, '' ) if length( $dest ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # back up to previous '\' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | while ( length( $dest ) && substr( $dest, -1, 1 ) ne '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $dest and substr($dest, -1, 1) ne "\\"
MC/DC50%1/2
length $dest and substr($dest, -1, 1) ne "\\"
length $dest
substr($dest, -1, 1) ne "\\"
Truth table66%2/3
A and B
A= length $destB= substr($dest, -1, 1) ne "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | substr( $dest, -1, 1, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # move to the next position | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | $last = length( $dest ) ? substr( $dest, -1, 1 ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } #/ elsif ( substr( $src, 0, ...)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # copy the '.' we just skipped | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | $dest .= $last = '.'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } #/ if ( ( $last eq "\0" ||...)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # copy first char from src to dest | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 348 | my $c = substr( $src, 0, 1, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 348 | $dest .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 348 | $last = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } #/ while ( length( $src ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Perl string needs no zero terminator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | $_[0] = $dest; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | }; #/ sub squeeze_inplace | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 23 | ▶ | $isSep = sub { # $bool ($c) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 23 | my ( $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 23 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 23 | ▶ | assert ( is_Str $c ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 23 | ▶ | return ( $c eq '\\' || $c eq '/' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$c eq '\\' || $c eq '/'
MC/DC100%2/2
$c eq '\\' || $c eq '/'
$c eq '\\'
$c eq '/'
Truth table100%3/3
A || B
A= $c eq '\\'B= $c eq '/'
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | ▶ | $isHomeExpand = sub { # $bool ($path) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | my ( $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 6 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | assert ( is_Str $path ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 6 | my @path = ( split( //, $path ), ('') x 2 )[ 0 .. 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | ▶ | return $path[0] eq '~' && &$isSep( $path[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$path[0] eq '~' && &$isSep($path[1])
MC/DC50%1/2
$path[0] eq '~' && &$isSep($path[1])
$path[0] eq '~'
&$isSep($path[1])
Truth table66%2/3
A && B
A= $path[0] eq '~'B= &$isSep($path[1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | ▶ | $isAbsolute = sub { # $bool ($path) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | my ( $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | ▶ | assert ( is_Str $path ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | my @path = ( split( //, $path ), ('') x 3 )[ 0 .. 2 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | ▶ | return &$isSep( $path[0] ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
&$isSep($path[0]) || $path[0] && $path[1] eq ':' && &$isSep($path[2])
$path[0] and $path[1] eq ":" and &$isSep($path[2])
$path[0] and $path[1] eq ":"
MC/DC0%0/4
&$isSep($path[0]) || $path[0] && $path[1] eq ':' && &$isSep($path[2])
&$isSep($path[0])
$path[0]
$path[1] eq ":"
&$isSep($path[2])
Truth table20%1/5
A || B and C and D
A= &$isSep($path[0])B= $path[0]C= $path[1] eq ":"D= &$isSep($path[2])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | || ( $path[0] && $path[1] eq ':' && &$isSep( $path[2] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | ▶ | $addFinalSep = sub { # void ($path, $size) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | my ( $path, $size ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | ▶ | assert ( is_Str $path ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | assert ( is_Int $size ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | ▶ | assert ( not readonly $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 5 | ▶ | if ( $size < 1 && length( $path ) < $size ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$size < 1 and length $path < $size
MC/DC0%0/2
$size < 1 and length $path < $size
$size < 1
length $path < $size
Truth table33%1/3
A and B
A= $size < 1B= length $path < $size
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $path .= '\\'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $_[0] = $path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 32 | ▶ | $getPathDrive = sub { # $int ($path) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 32 | my ( $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 32 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 32 | ▶ | assert ( is_Str $path ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 32 | my @path = ( split( //, $path ), ('') x 2 )[ 0 .. 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 32 | ▶ | if ( $path[0] && $path[1] eq ':' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$path[0] and $path[1] eq ":"
MC/DC50%1/2
$path[0] and $path[1] eq ":"
$path[0]
$path[1] eq ":"
Truth table66%2/3
A and B
A= $path[0]B= $path[1] eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 14 | my $drive = ord( uc $path[0] ) - ord( 'A' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 14 | ▶ | if ( 0 <= $drive && $drive <= ord( 'Z' ) - ord( 'A' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
0 <= $drive and $drive <= 25
MC/DC0%0/2
0 <= $drive and $drive <= 25
0 <= $drive
$drive <= 25
Truth table33%1/3
A and B
A= 0 <= $driveB= $drive <= 25
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 14 | return $drive; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 18 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub driveValid { # $bool ($drive) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
driveValid: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | pos => [Str], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my ( $drive ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $drive = uc( $drive ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | assert ( $drive =~ /^[A-Z]$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $mask = 1 << ( ord( $drive ) - ord( 'A' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if ( $^O eq 'MSWin32' && eval { require Win32API::File; !$@ } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$^O eq "MSWin32" and eval {
do {
require Win32API::File;
not $@
}
}
MC/DC0%0/2
$^O eq "MSWin32" and eval {
do {
require Win32API::File;
not $@
}
}
$^O eq "MSWin32"
eval {
do {
require Win32API::File;
not $@
}
}
Truth table0%0/3
A and B
A= $^O eq "MSWin32"B= eval {
do {
require Win32API::File;
not $@
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | return ( Win32API::File::GetLogicalDrives() & $mask ) != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $path = "$drive:/"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return -d $path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub isDir { # $bool ($str) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isDir: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | pos => [Str], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my ( $str ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $ff = ffblk->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | return findfirst( $str, $ff, FA_DIREC ) == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
findfirst($str, $ff, 16) == 0 && ($ff->ff_attrib & 16) != 0
MC/DC0%0/2
findfirst($str, $ff, 16) == 0 && ($ff->ff_attrib & 16) != 0
findfirst($str, $ff, 16) == 0
($ff->ff_attrib & 16) != 0
Truth table0%0/3
A && B
A= findfirst($str, $ff, 16) == 0B= ($ff->ff_attrib & 16) != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | && ( $ff->ff_attrib() & FA_DIREC ) != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub pathValid { # $bool ($path) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pathValid: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | pos => [Str], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my ( $path ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $expPath = $path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | fexpand( $expPath ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $len = length( $expPath ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ( $len <= 3 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return driveValid( substr( $expPath, 0, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $expPath =~ s/\\$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return isDir( $expPath ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub validFileName { # $bool ($fileName) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validFileName: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | pos => [Str], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my ( $fileName ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | state $illegalChars = qr/[;,=+<>|"\[\] \\]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $path = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $dir = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $name = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $ext = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | fnsplit( $fileName, $path, $dir, $name, $ext ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $path .= $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | return false | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dir ne "" and not pathValid($path)
MC/DC0%0/2
$dir ne "" and not pathValid($path)
$dir ne ""
not pathValid($path)
Truth table0%0/3
A and not(B)
A= $dir ne ""B= not pathValid($path)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | if $dir ne '' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | && !pathValid( $path ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | my $ext1 = $ext ne '' ? substr( $ext, 1 ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | return false | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$name =~ /$illegalChars/ or $ext1 =~ /$illegalChars/ or index($ext1, ".") != -1
$name =~ /$illegalChars/ or $ext1 =~ /$illegalChars/
MC/DC0%0/3
$name =~ /$illegalChars/ or $ext1 =~ /$illegalChars/ or index($ext1, ".") != -1
$name =~ /$illegalChars/
$ext1 =~ /$illegalChars/
index($ext1, ".") != -1
Truth table0%0/4
A or B or C
A= $name =~ /$illegalChars/B= $ext1 =~ /$illegalChars/C= index($ext1, ".") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | if $name =~ $illegalChars | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | || $ext1 =~ $illegalChars | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | || index( $ext1, '.' ) != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return true; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | sub getHomeDir { # $bool ($drive, $dir) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getHomeDir: called CC=13 SCAR=37.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | pos => [ Maybe[Str], Maybe[Str] ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | my ( $drive, $dir ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | assert ( !defined or !readonly $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_ and &readonly($_[0])
MC/DC0%0/2
defined $_ and &readonly($_[0])
defined $_
&readonly($_[0])
Truth table33%1/3
A and B
A= defined $_B= &readonly($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | ▶ | assert ( !defined or !readonly $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_ and &readonly($_[1])
MC/DC0%0/2
defined $_ and &readonly($_[1])
defined $_
&readonly($_[1])
Truth table33%1/3
A and B
A= defined $_B= &readonly($_[1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $homedrive = $ENV{"HOMEDRIVE"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $homepath = $ENV{"HOMEPATH"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ( $homedrive && $homepath ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$homedrive and $homepath
MC/DC0%0/2
$homedrive and $homepath
$homedrive
$homepath
Truth table0%0/3
A and B
A= $homedriveB= $homepath
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( defined $drive ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $_[0] = $drive = substr( $homedrive, 0, MAXDRIVE ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ( defined $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $_[1] = $dir = substr( $homepath, 0, MAXDIR ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | return true; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | my $home = $ENV{"HOME"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | ▶ | if ( $home ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ▶ | if ( defined $drive ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | $_[0] = $drive = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | if ( defined $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | $_[1] = $dir = substr( $home, 0, MAXPATH ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | return true; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | return false; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 8 | ▶ | sub getCurDir { # void ($dir, $drive) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCurDir: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 8 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | pos => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | Int, { default => -1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 8 | my ( $dir, $drive ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 8 | ▶ | assert ( not readonly $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 8 | ▶ | $drive = getdisk() unless 0 <= $drive && $drive <= ord( 'Z' ) - ord( 'A' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
0 <= $drive and $drive <= 25
MC/DC50%1/2
0 <= $drive and $drive <= 25
0 <= $drive
$drive <= 25
Truth table66%2/3
A and B
A= 0 <= $driveB= $drive <= 25
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 8 | $dir = chr( $drive + ord( 'A' ) ) . ':\\'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 8 | getcurdir( $drive + 1, my $tmp ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 8 | substr( $dir, 3 ) = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 8 | ▶ | $dir .= '\\' if length $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 8 | ▶ | substr( $dir, MAXPATH ) = '' if length $dir > MAXPATH; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 8 | $_[0] = $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub isWild { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isWild: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | pos => [Str], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my ( $f ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | return $f =~ /[?*]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 8 | ▶ | sub fexpand { # void ($rpath, |$relativeTo) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fexpand: called CC=16 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 8 | state $sig = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | pos => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | Str, { optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 8 | my ( $rpath, $relativeTo ) = $sig->( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 8 | ▶ | assert ( not readonly $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 8 | ▶ | unless ( defined $relativeTo ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 8 | $relativeTo = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 8 | getCurDir( $relativeTo, &$getPathDrive($rpath) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 8 | my $fn = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | drive => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | dir => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | file => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ext => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 8 | my $path = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 8 | my $drv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # Prioritize drive letter in 'rpath'. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 8 | ▶ | if ( ( $drv = &$getPathDrive( $rpath ) ) == -1 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
($drv = &$getPathDrive($rpath)) == -1 and ($drv = &$getPathDrive($relativeTo)) == -1
MC/DC0%0/2
($drv = &$getPathDrive($rpath)) == -1 and ($drv = &$getPathDrive($relativeTo)) == -1
($drv = &$getPathDrive($rpath)) == -1
($drv = &$getPathDrive($relativeTo)) == -1
Truth table66%2/3
A and B
A= ($drv = &$getPathDrive($rpath)) == -1B= ($drv = &$getPathDrive($relativeTo)) == -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | && ( $drv = &$getPathDrive( $relativeTo ) ) == -1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $drv = getdisk(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 8 | $fn->{drive} = chr( ord('A') + $drv ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 8 | $fn->{drive} .= ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 8 | my $flags = fnsplit( $rpath, undef, $fn->{dir}, $fn->{file}, $fn->{ext} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 8 | ▶ | if ( ( $flags & DIRECTORY ) == 0 || !&$isSep( substr $fn->{dir}, 0, 1 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
($flags & 8) == 0 or not &$isSep(substr($fn->{"dir"}, 0, 1))
MC/DC50%1/2
($flags & 8) == 0 or not &$isSep(substr($fn->{"dir"}, 0, 1))
($flags & 8) == 0
not &$isSep(substr($fn->{"dir"}, 0, 1))
Truth table66%2/3
A or not(B)
A= ($flags & 8) == 0B= not &$isSep(substr($fn->{"dir"}, 0, 1))
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 6 | my $rbase = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 6 | ▶ | if ( &$isHomeExpand( $fn->{dir} ) && getHomeDir( $fn->{drive}, $rbase ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&$isHomeExpand($fn->{"dir"}) and getHomeDir($fn->{"drive"}, $rbase)
MC/DC50%1/2
&$isHomeExpand($fn->{"dir"}) and getHomeDir($fn->{"drive"}, $rbase)
&$isHomeExpand($fn->{"dir"})
getHomeDir($fn->{"drive"}, $rbase)
Truth table66%2/3
A and B
A= &$isHomeExpand($fn->{"dir"})B= getHomeDir($fn->{"drive"}, $rbase)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # Home expansion. Overwrite drive if necessary. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # 'dir' begins with "~/" or "~\", so we can reuse the separator. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | $rbase .= substr( $fn->{dir}, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | ▶ | $rbase = substr( $rbase, 0, MAXDIR ) if length $rbase > MAXDIR; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # If 'rpath' is relative but contains a drive letter, just swap drives. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 5 | ▶ | if ( &$getPathDrive( $rpath ) != -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | if ( getcurdir( $drv + 1, $rbase ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $rbase = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # Expand 'relativeTo'. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 4 | $rbase = substr( $relativeTo, 0, MAXPATH ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 4 | ▶ | if ( !&$isAbsolute( $rbase ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $curpath = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | getCurDir( $curpath, $drv ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | fexpand( $rbase, $curpath ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # Skip drive letter in 'rbase' (remove "C:") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 4 | ▶ | if ( &$getPathDrive( $rbase ) != -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 4 | substr( $rbase, 0, 2, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # Ensure 'rbase' ends with a separator. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 5 | &$addFinalSep( $rbase, MAXPATH ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 5 | $rbase .= $fn->{dir}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 5 | ▶ | $rbase = substr( $rbase, 0, MAXDIR ) if length $rbase > MAXDIR; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } #/ else [ if ( &$isHomeExpand( $fn->{dir}...))] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 6 | ▶ | if ( !&$isSep( substr( $rbase, 0, 1 ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | $fn->{dir} = substr( '\\' . $rbase, 0, MAXDIR ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 5 | $fn->{dir} = substr( $rbase, 0, MAXDIR ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } #/ if ( ( ( $flags & $DIRECTORY...))) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 8 | $fn->{dir} =~ tr{\/}{\\}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 8 | &$squeeze( $fn->{dir} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 8 | fnmerge( $path, $fn->{drive}, $fn->{dir}, $fn->{file}, $fn->{ext} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # $path = uc $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 8 | $_[0] = $rpath = substr( $path, 0, MAXPATH ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 10 | 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||