lib/TUI/StdDlg/Util.pm

filter: Statementstmt 76.6% 187 / 244 Branchbran 53.2% 65 / 122 Conditioncond 46.9% 38 / 81 MC/DCmcdc 28.5% 14 / 49 Subroutinesub 80.0% 20 / 25 Podpod 100% 8 / 8 totaltotal 62.7% 332 / 529 CC 89 SCAR 28.6
CC
89
Cov
65%
validFileName
56.0
getHomeDir
42.7
driveValid
20.0
CRAP 17.5
« lib/TUI/MsgBox/MsgBoxText.pm ↑ Summary lib/TUI/Views/Scroller.pm »
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
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 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
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 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
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 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
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 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
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 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
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 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
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 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
BranchTrueFalseTotal
unless $drive =~ /^[A-Z]$/ 0 0 0
193 0 my $mask = 1 << ( ord( $drive ) - ord( 'A' ) );
194 0 ▶ if ( $^O eq 'MSWin32' && eval { require Win32API::File; !$@ } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32" and eval { do { require Win32API::File; not $@ } }) 0 0 0
Condition0%0/3
$^O eq "MSWin32" and eval { do { require Win32API::File; not $@ } }
!ll&&!rl&&r
000
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 $@ } }
ABresult
0X0
100
111
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
!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
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
BranchTrueFalseTotal
if ($len <= 3) 0 0 0
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
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
244 if $dir ne ''
245 && !pathValid( $path );
246
247 0 ▶ my $ext1 = $ext ne '' ? substr( $ext, 1 ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$ext ne '' ? : 0 0 0
248 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
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
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
262 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
263 1 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 1 1
264 0 my $homedrive = $ENV{"HOMEDRIVE"};
265 0 my $homepath = $ENV{"HOMEPATH"};
266 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
267 0 ▶ if ( defined $drive ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $drive) 0 0 0
268 0 $_[0] = $drive = substr( $homedrive, 0, MAXDRIVE );
269 }
270 0 ▶ if ( defined $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 0 0 0
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
BranchTrueFalseTotal
if ($home) 1 0 1
279 1 ▶ if ( defined $drive ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $drive) 1 0 1
280 1 $_[0] = $drive = '';
281 }
282 1 ▶ if ( defined $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 1 0 1
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
BranchTrueFalseTotal
if &readonly($_[0]) 0 8 8
300 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
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
BranchTrueFalseTotal
if length $tmp 8 0 8
305 8 ▶ substr( $dir, MAXPATH ) = '' if length $dir > MAXPATH;
Branch: 1 branch
BranchTrueFalseTotal
if length $dir > 260 0 8 8
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
BranchTrueFalseTotal
if &readonly($_[0]) 0 8 8
327 8 ▶ unless ( defined $relativeTo ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $relativeTo) 8 0 8
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
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
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
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
351 6 my $rbase = '';
352 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
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
BranchTrueFalseTotal
if length $rbase > 256 0 1 1
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
BranchTrueFalseTotal
if (&$getPathDrive($rpath) != -1) { } 1 4 5
361 1 ▶ if ( getcurdir( $drv + 1, $rbase ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (getcurdir($drv + 1, $rbase) != 0) 0 1 1
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
BranchTrueFalseTotal
unless (&$isAbsolute($rbase)) 0 4 4
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
BranchTrueFalseTotal
if (&$getPathDrive($rbase) != -1) 4 0 4
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
BranchTrueFalseTotal
if length $rbase > 256 0 5 5
384 } #/ else [ if ( &$isHomeExpand( $fn->{dir}...))]
385
386 6 ▶ if ( !&$isSep( substr( $rbase, 0, 1 ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$isSep(substr($rbase, 0, 1))) { } 1 5 6
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__
« lib/TUI/MsgBox/MsgBoxText.pm ↑ Summary lib/TUI/Views/Scroller.pm »