lib/TUI/StdDlg/Util.pm

filter: Statementstmt 79.1% 193 / 244 Branchbran 54.0% 67 / 124 Conditioncond 48.7% 38 / 78 MC/DCmcdc 29.7% 14 / 47 Subroutinesub 84.0% 21 / 25 Podpod 100% 8 / 8 totaltotal 64.8% 341 / 526 CC 89 SCAR 28.3
CC
89
Cov
67%
validFileName
56.0
getHomeDir
42.7
__ANON__
19.0
CRAP 17.0
« lib/TUI/toolkit/Params.pm ↑ Summary lib/TUI/Views/Scroller.pm »
1 package TUI::StdDlg::Util;
2 # ABSTRACT: defines utility functions used for Standard Dialogs
3
4 16 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 16 our $VERSION = '2.000003';
9 16 $VERSION =~ tr/_//d;
10 16 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 16 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 our @EXPORT_OK = qw(
14 fexpand
15 driveValid
16 isDir
17 pathValid
18 validFileName
19 getCurDir
20 getHomeDir
21 isWild
22 );
23
24 16 our %EXPORT_TAGS = (
25 all => \@EXPORT_OK,
26 );
27
28 16 ▶use Scalar::Util qw( readonly );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 16 ▶use TUI::toolkit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
30 :boolean
31 :utils
32 16 );
33 16 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
34 Maybe
35 :is
36 :types
37 16 );
38
39 16 ▶use TUI::StdDlg::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
40 DIRECTORY
41 FA_DIREC
42 :MAX
43 16 );
44 16 ▶use TUI::StdDlg::Dos; # ffblk
Subroutine BEGIN: called CC=1 SCAR=0.0
45 16 ▶use TUI::StdDlg::Dir qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
46 getcurdir
47 getdisk
48 findfirst
49 fnmerge
50 fnsplit
51 16 );
52
53 my (
54 16 $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
BranchTrueFalseTotal
unless @_ == 2 0 46 46
66 46 ▶ assert ( is_Str $src );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($src) 0 46 46
67 46 ▶ assert ( is_Str $k );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($k) 0 46 46
68 46 ▶ while ( length( $src ) && substr( $src, 0, 1 ) eq $k ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $src and substr($src, 0, 1) eq $k) 2 46 48
Condition100%3/3
length $src and substr($src, 0, 1) eq $k
!ll&&!rl&&r
1452
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
ABresult
0X0
100
111
69 2 substr( $src, 0, 1, '' );
70 }
71 46 $_[0] = $src;
72 46 return;
73 16 };
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
BranchTrueFalseTotal
unless @_ == 1 0 8 8
78 8 ▶ assert ( is_Str $path );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($path) 0 8 8
79 8 ▶ assert ( not readonly $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($_[0]) 0 8 8
80
81 8 my $dest = '';
82 8 my $src = $path;
83 8 my $last = '';
84
85 8 ▶ while ( length $src ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $src) 356 8 364
86 356 ▶ if ( $last eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last eq "\\") 44 312 356
87 44 &$skip( $src, '\\' ); # skip repeated '\'
88 }
89 356 ▶ if ( ( !$last || $last eq '\\' ) && substr( $src, 0, 1 ) eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!$last || $last eq '\\' and substr($src, 0, 1) eq '.') { } 8 348 356
Condition100%6/6
!$last || $last eq "\\" and substr($src, 0, 1) eq "."
!ll&&!rl&&r
268808
not $last or $last eq "\\"
l!l&&r!l&&!r
4444268
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 "."
ABCresult
00X0
1X00
0100
1X11
0111
90 8 substr( $src, 0, 1, '' );
91
92 # have a '.' or '.\'
93 8 ▶ if ( !length( $src ) || substr( $src, 0, 1 ) eq '\\' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not length $src or substr($src, 0, 1) eq '\\') { } 1 7 8
elsif (substr($src, 0, 1) eq '.' and length $src == 1 || substr($src, 1, 1) eq '\\') { } 1 6 7
Condition66%2/3
not length $src or substr($src, 0, 1) eq "\\"
l!l&&r!l&&!r
017
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 "\\"
ABresult
1X1
011
000
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 "\\"
!ll&&!rl&&r
601
length $src == 1 or substr($src, 1, 1) eq "\\"
l!l&&r!l&&!r
010
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 "\\"
ABCresult
0XX0
1000
11X1
1011
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
BranchTrueFalseTotal
if length $dest 1 0 1
108
109 # back up to previous '\'
110 1 ▶ while ( length( $dest ) && substr( $dest, -1, 1 ) ne '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $dest and substr($dest, -1, 1) ne "\\") 1 1 2
Condition66%2/3
length $dest and substr($dest, -1, 1) ne "\\"
!ll&&!rl&&r
011
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 "\\"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
length $dest ? : 1 0 1
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 16 }; #/ 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
BranchTrueFalseTotal
unless @_ == 1 0 23 23
138 23 ▶ assert ( is_Str $c );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($c) 0 23 23
139 23 ▶ return ( $c eq '\\' || $c eq '/' );
Condition100%3/3
$c eq '\\' || $c eq '/'
l!l&&r!l&&!r
9311
MC/DC100%2/2
$c eq '\\' || $c eq '/'
$c eq '\\' $c eq '/'
Truth table100%3/3
A || B
A= $c eq '\\'B= $c eq '/'
ABresult
1X1
011
000
140 16 };
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
BranchTrueFalseTotal
unless @_ == 1 0 6 6
145 6 ▶ assert ( is_Str $path );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($path) 0 6 6
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])
!ll&&!rl&&r
501
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])
ABresult
0X0
100
111
148 16 };
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
BranchTrueFalseTotal
unless @_ == 1 0 4 4
153 4 ▶ assert ( is_Str $path );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($path) 0 4 4
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])
l!l&&r!l&&!r
040
$path[0] and $path[1] eq ":" and &$isSep($path[2])
!ll&&!rl&&r
004
$path[0] and $path[1] eq ":"
!ll&&!rl&&r
004
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])
ABCDresult
1XXX1
01111
00XX0
010X0
01100
156 || ( $path[0] && $path[1] eq ':' && &$isSep( $path[2] ) );
157 16 };
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
BranchTrueFalseTotal
unless @_ == 2 0 5 5
162 5 ▶ assert ( is_Str $path );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($path) 0 5 5
163 5 ▶ assert ( is_Int $size );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($size) 0 5 5
164 5 ▶ assert ( not readonly $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($_[0]) 0 5 5
165 5 ▶ if ( $size < 1 && length( $path ) < $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size < 1 and length $path < $size) 0 5 5
Condition33%1/3
$size < 1 and length $path < $size
!ll&&!rl&&r
500
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
ABresult
0X0
100
111
166 0 $path .= '\\';
167 0 $_[0] = $path;
168 }
169 5 return;
170 16 };
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
BranchTrueFalseTotal
unless @_ == 1 0 32 32
175 32 ▶ assert ( is_Str $path );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($path) 0 32 32
176 32 my @path = ( split( //, $path ), ('') x 2 )[ 0 .. 1 ];
177 32 ▶ if ( $path[0] && $path[1] eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path[0] and $path[1] eq ":") 14 18 32
Condition66%2/3
$path[0] and $path[1] eq ":"
!ll&&!rl&&r
01814
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 ":"
ABresult
0X0
100
111
178 14 my $drive = ord( uc $path[0] ) - ord( 'A' );
179 14 ▶ if ( 0 <= $drive && $drive <= ord( 'Z' ) - ord( 'A' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $drive and $drive <= 25) 14 0 14
Condition33%1/3
0 <= $drive and $drive <= 25
!ll&&!rl&&r
0014
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
ABresult
0X0
100
111
180 14 return $drive;
181 }
182 }
183 18 return -1;
184 16 };
185
186 2 ▶sub driveValid { # $bool ($drive)
Subroutine driveValid: called CC=4 SCAR=19.1
Pod documented
187 2 state $sig = signature(
188 pos => [Str],
189 );
190 2 my ( $drive ) = $sig->( @_ );
191 2 $drive = uc( $drive );
192 2 ▶ assert ( $drive =~ /^[A-Z]$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $drive =~ /^[A-Z]$/ 0 2 2
193
194 # Unless it's Windows, we will emulate there's only one disk:
195 # the one returned by getdisk(), which is C by default.
196 2 ▶ return $drive eq chr( ord( 'A' ) + getdisk() )
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "MSWin32" 2 0 2
197 if $^O ne 'MSWin32';
198
199 0 my $mask = 1 << ( ord( $drive ) - ord( 'A' ) );
200 return ( Win32API::File::GetLogicalDrives() & $mask ) != 0
201 0 ▶ if eval { require Win32API::File; !$@ };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { require Win32API::File; not $@ } } 0 0 0
202
203 0 my $path = "$drive:/";
204 0 return -d $path;
205 }
206
207 0 ▶sub isDir { # $bool ($str)
Subroutine isDir: not called CC=2 SCAR=17.9
Pod documented
208 0 state $sig = signature(
209 pos => [Str],
210 );
211 0 my ( $str ) = $sig->( @_ );
212 0 my $ff = ffblk->new();
213 0 ▶ return findfirst( $str, $ff, FA_DIREC ) == 0
Condition0%0/3
findfirst($str, $ff, 16) == 0 && ($ff->ff_attrib & 16) != 0
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
214 && ( $ff->ff_attrib() & FA_DIREC ) != 0;
215 }
216
217 0 ▶sub pathValid { # $bool ($path)
Subroutine pathValid: not called CC=2 SCAR=17.9
Pod documented
218 0 state $sig = signature(
219 pos => [Str],
220 );
221 0 my ( $path ) = $sig->( @_ );
222 0 my $expPath = $path;
223 0 fexpand( $expPath );
224 0 my $len = length( $expPath );
225 0 ▶ if ( $len <= 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len <= 3) 0 0 0
226 0 return driveValid( substr( $expPath, 0, 1 ) );
227 }
228
229 0 $expPath =~ s/\\$//;
230
231 0 return isDir( $expPath );
232 }
233
234 0 ▶sub validFileName { # $bool ($fileName)
Subroutine validFileName: not called CC=7 SCAR=40.3
Pod documented
235 0 state $sig = signature(
236 pos => [Str],
237 );
238 0 my ( $fileName ) = $sig->( @_ );
239
240 0 state $illegalChars = qr/[;,=+<>|"\[\] \\]/;
241
242 0 my $path = '';
243 0 my $dir = '';
244 0 my $name = '';
245 0 my $ext = '';
246
247 0 fnsplit( $fileName, $path, $dir, $name, $ext );
248 0 $path .= $dir;
249 0 ▶ return false
Branch: 1 branch
BranchTrueFalseTotal
if $dir ne "" and not pathValid($path) 0 0 0
Condition0%0/3
$dir ne "" and not pathValid($path)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
250 if $dir ne ''
251 && !pathValid( $path );
252
253 0 ▶ my $ext1 = $ext ne '' ? substr( $ext, 1 ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$ext ne '' ? : 0 0 0
254 0 ▶ return false
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /$illegalChars/ or $ext1 =~ /$illegalChars/ or index($ext1, ".") != -1 0 0 0
Condition0%0/6
$name =~ /$illegalChars/ or $ext1 =~ /$illegalChars/ or index($ext1, ".") != -1
l!l&&r!l&&!r
000
$name =~ /$illegalChars/ or $ext1 =~ /$illegalChars/
l!l&&r!l&&!r
000
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
ABCresult
1XX1
01X1
0011
0000
255 if $name =~ $illegalChars
256 || $ext1 =~ $illegalChars
257 || index( $ext1, '.' ) != -1;
258
259 0 return true;
260 }
261
262 1 ▶sub getHomeDir { # $bool ($drive, $dir)
Subroutine getHomeDir: called CC=13 SCAR=37.5
Pod documented
263 1 state $sig = signature(
264 pos => [ Maybe[Str], Maybe[Str] ],
265 );
266 1 my ( $drive, $dir ) = $sig->( @_ );
267 1 ▶ assert ( !defined or !readonly $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ and &readonly($_[0]) 0 1 1
Condition33%1/3
defined $_ and &readonly($_[0])
!ll&&!rl&&r
100
MC/DC0%0/2
defined $_ and &readonly($_[0])
defined $_ &readonly($_[0])
Truth table33%1/3
A and B
A= defined $_B= &readonly($_[0])
ABresult
0X0
100
111
268 1 ▶ assert ( !defined or !readonly $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ and &readonly($_[1]) 0 1 1
Condition33%1/3
defined $_ and &readonly($_[1])
!ll&&!rl&&r
100
MC/DC0%0/2
defined $_ and &readonly($_[1])
defined $_ &readonly($_[1])
Truth table33%1/3
A and B
A= defined $_B= &readonly($_[1])
ABresult
0X0
100
111
269 1 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 1 1
270 0 my $homedrive = $ENV{"HOMEDRIVE"};
271 0 my $homepath = $ENV{"HOMEPATH"};
272 0 ▶ if ( $homedrive && $homepath ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($homedrive and $homepath) 0 0 0
Condition0%0/3
$homedrive and $homepath
!ll&&!rl&&r
000
MC/DC0%0/2
$homedrive and $homepath
$homedrive $homepath
Truth table0%0/3
A and B
A= $homedriveB= $homepath
ABresult
0X0
100
111
273 0 ▶ if ( defined $drive ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $drive) 0 0 0
274 0 $_[0] = $drive = substr( $homedrive, 0, MAXDRIVE );
275 }
276 0 ▶ if ( defined $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 0 0 0
277 0 $_[1] = $dir = substr( $homepath, 0, MAXDIR );
278 }
279 0 return true;
280 }
281 }
282 else {
283 1 my $home = $ENV{"HOME"};
284 1 ▶ if ( $home ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($home) 1 0 1
285 1 ▶ if ( defined $drive ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $drive) 1 0 1
286 1 $_[0] = $drive = '';
287 }
288 1 ▶ if ( defined $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 1 0 1
289 1 $_[1] = $dir = substr( $home, 0, MAXPATH );
290 }
291 1 return true;
292 }
293 }
294 0 return false;
295 }
296
297 8 ▶sub getCurDir { # void ($dir, $drive)
Subroutine getCurDir: called CC=6 SCAR=18.2
Pod documented
298 8 state $sig = signature(
299 pos => [
300 Str,
301 Int, { default => -1 },
302 ],
303 );
304 8 my ( $dir, $drive ) = $sig->( @_ );
305 8 ▶ assert ( not readonly $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($_[0]) 0 8 8
306 8 ▶ $drive = getdisk() unless 0 <= $drive && $drive <= ord( 'Z' ) - ord( 'A' );
Branch: 1 branch
BranchTrueFalseTotal
unless 0 <= $drive and $drive <= 25 7 1 8
Condition66%2/3
0 <= $drive and $drive <= 25
!ll&&!rl&&r
701
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
ABresult
0X0
100
111
307 8 $dir = chr( $drive + ord( 'A' ) ) . ':\\';
308 8 getcurdir( $drive + 1, my $tmp );
309 8 substr( $dir, 3 ) = $tmp;
310 8 ▶ $dir .= '\\' if length $tmp;
Branch: 1 branch
BranchTrueFalseTotal
if length $tmp 8 0 8
311 8 ▶ substr( $dir, MAXPATH ) = '' if length $dir > MAXPATH;
Branch: 1 branch
BranchTrueFalseTotal
if length $dir > 260 0 8 8
312 8 $_[0] = $dir;
313 8 return;
314 }
315
316 0 ▶sub isWild {
Subroutine isWild: not called CC=1 SCAR=6.9
Pod documented
317 0 state $sig = signature(
318 pos => [Str],
319 );
320 0 my ( $f ) = $sig->( @_ );
321 0 return $f =~ /[?*]/;
322 }
323
324 8 ▶sub fexpand { # void ($rpath, |$relativeTo)
Subroutine fexpand: called CC=16 SCAR=29.2
Pod documented
325 8 state $sig = signature(
326 pos => [
327 Str,
328 Str, { optional => 1 },
329 ],
330 );
331 8 my ( $rpath, $relativeTo ) = $sig->( @_ );
332 8 ▶ assert ( not readonly $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($_[0]) 0 8 8
333 8 ▶ unless ( defined $relativeTo ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $relativeTo) 8 0 8
334 8 $relativeTo = '';
335 8 getCurDir( $relativeTo, &$getPathDrive($rpath) );
336 }
337 8 my $fn = {
338 drive => '',
339 dir => '',
340 file => '',
341 ext => '',
342 };
343 8 my $path = '';
344
345 8 my $drv;
346 # Prioritize drive letter in 'rpath'.
347 8 ▶ if ( ( $drv = &$getPathDrive( $rpath ) ) == -1
Branch: 1 branch
BranchTrueFalseTotal
if (($drv = &$getPathDrive($rpath)) == -1 and ($drv = &$getPathDrive($relativeTo)) == -1) 0 8 8
Condition66%2/3
($drv = &$getPathDrive($rpath)) == -1 and ($drv = &$getPathDrive($relativeTo)) == -1
!ll&&!rl&&r
170
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
ABresult
0X0
100
111
348 && ( $drv = &$getPathDrive( $relativeTo ) ) == -1
349 ) {
350 0 $drv = getdisk();
351 }
352 8 $fn->{drive} = chr( ord('A') + $drv );
353 8 $fn->{drive} .= ':';
354
355 8 my $flags = fnsplit( $rpath, undef, $fn->{dir}, $fn->{file}, $fn->{ext} );
356 8 ▶ if ( ( $flags & DIRECTORY ) == 0 || !&$isSep( substr $fn->{dir}, 0, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($flags & 8) == 0 or not &$isSep(substr($fn->{"dir"}, 0, 1))) 6 2 8
Condition66%2/3
($flags & 8) == 0 or not &$isSep(substr($fn->{"dir"}, 0, 1))
l!l&&r!l&&!r
062
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))
ABresult
1X1
011
000
357 6 my $rbase = '';
358 6 ▶ if ( &$isHomeExpand( $fn->{dir} ) && getHomeDir( $fn->{drive}, $rbase ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$isHomeExpand($fn->{'dir'}) and getHomeDir($fn->{'drive'}, $rbase)) { } 1 5 6
Condition66%2/3
&$isHomeExpand($fn->{"dir"}) and getHomeDir($fn->{"drive"}, $rbase)
!ll&&!rl&&r
501
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)
ABresult
0X0
100
111
359 # Home expansion. Overwrite drive if necessary.
360 # 'dir' begins with "~/" or "~\", so we can reuse the separator.
361 1 $rbase .= substr( $fn->{dir}, 1 );
362 1 ▶ $rbase = substr( $rbase, 0, MAXDIR ) if length $rbase > MAXDIR;
Branch: 1 branch
BranchTrueFalseTotal
if length $rbase > 256 0 1 1
363 }
364 else {
365 # If 'rpath' is relative but contains a drive letter, just swap drives.
366 5 ▶ if ( &$getPathDrive( $rpath ) != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$getPathDrive($rpath) != -1) { } 1 4 5
367 1 ▶ if ( getcurdir( $drv + 1, $rbase ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (getcurdir($drv + 1, $rbase) != 0) 0 1 1
368 0 $rbase = '';
369 }
370 }
371 else {
372 # Expand 'relativeTo'.
373 4 $rbase = substr( $relativeTo, 0, MAXPATH );
374 4 ▶ if ( !&$isAbsolute( $rbase ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$isAbsolute($rbase)) 0 4 4
375 0 my $curpath = '';
376 0 getCurDir( $curpath, $drv );
377 0 fexpand( $rbase, $curpath );
378 }
379
380 # Skip drive letter in 'rbase' (remove "C:")
381 4 ▶ if ( &$getPathDrive( $rbase ) != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$getPathDrive($rbase) != -1) 4 0 4
382 4 substr( $rbase, 0, 2, '' );
383 }
384 }
385
386 # Ensure 'rbase' ends with a separator.
387 5 &$addFinalSep( $rbase, MAXPATH );
388 5 $rbase .= $fn->{dir};
389 5 ▶ $rbase = substr( $rbase, 0, MAXDIR ) if length $rbase > MAXDIR;
Branch: 1 branch
BranchTrueFalseTotal
if length $rbase > 256 0 5 5
390 } #/ else [ if ( &$isHomeExpand( $fn->{dir}...))]
391
392 6 ▶ if ( !&$isSep( substr( $rbase, 0, 1 ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$isSep(substr($rbase, 0, 1))) { } 1 5 6
393 1 $fn->{dir} = substr( '\\' . $rbase, 0, MAXDIR );
394 }
395 else {
396 5 $fn->{dir} = substr( $rbase, 0, MAXDIR );
397 }
398 } #/ if ( ( ( $flags & $DIRECTORY...)))
399
400 8 $fn->{dir} =~ tr{\/}{\\};
401 8 &$squeeze( $fn->{dir} );
402 8 fnmerge( $path, $fn->{drive}, $fn->{dir}, $fn->{file}, $fn->{ext} );
403 # $path = uc $path;
404 8 $_[0] = $rpath = substr( $path, 0, MAXPATH );
405 8 return;
406 }
407
408 16 1
409
410 __END__
« lib/TUI/toolkit/Params.pm ↑ Summary lib/TUI/Views/Scroller.pm »