blib/lib/File/Spec/OS2.pm

filter: Statementstmt 77.3% 75 / 97 Branchbran 55.2% 21 / 38 Conditioncond 41.6% 10 / 24 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 78.5% 11 / 14 Podpod 100% 12 / 12 totaltotal 65.8% 131 / 199 CC 30 SCAR 21.9
CC
30
Cov
67%
rel2abs
17.3
abs2rel
14.2
path
12.0
CRAP 8.9
« blib/lib/File/Spec/Mac.pm ↑ Summary blib/lib/File/Spec/Win32.pm »
1 package File::Spec::OS2;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 require File::Spec::Unix;
6  
7 2 our $VERSION = '3.75';
8 2 $VERSION =~ tr/_//d;
9  
10 2 our @ISA = qw(File::Spec::Unix);
11  
12 0 ▶sub devnull {
Subroutine devnull: not called CC=1 SCAR=6.9
Pod documented
13 0 return "/dev/nul";
14 }
15  
16 1 ▶sub case_tolerant {
Subroutine case_tolerant: called CC=1 SCAR=0.0
Pod documented
17 1 return 1;
18 }
19  
20 23 ▶sub file_name_is_absolute {
Subroutine file_name_is_absolute: called CC=1 SCAR=0.0
Pod documented
21 23 my ($self,$file) = @_;
22 23 return scalar($file =~ m{^([a-z]:)?[\\/]}is);
23 }
24  
25 0 ▶sub path {
Subroutine path: not called CC=3 SCAR=24.8
Pod documented
26 0 my $path = $ENV{PATH};
27 0 $path =~ s:\\:/:g;
28 0 my @path = split(';',$path);
29 0 ▶ foreach (@path) { $_ = '.' if $_ eq '' }
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 0 0 0
30 0 return @path;
31 }
32  
33 0 ▶sub tmpdir {
Subroutine tmpdir: not called CC=2 SCAR=17.9
Pod documented
34 0 my $cached = $_[0]->_cached_tmpdir(qw 'TMPDIR TEMP TMP');
35 0 ▶ return $cached if defined $cached;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cached 0 0 0
36 0 my @d = @ENV{qw(TMPDIR TEMP TMP)}; # function call could autovivivy
37 0 $_[0]->_cache_tmpdir(
38 $_[0]->_tmpdir( @d, '/tmp', '/' ), qw 'TMPDIR TEMP TMP'
39 );
40 }
41  
42 20 ▶sub catdir {
Subroutine catdir: called CC=3 SCAR=11.0
Pod documented
43 20 my $self = shift;
44 20 my @args = @_;
45 20 foreach (@args) {
46 42 tr[\\][/];
47 # append a backslash to each argument unless it has one there
48 42 ▶ $_ .= "/" unless m{/$};
Branch: 1 branch
BranchTrueFalseTotal
unless m[/$] 25 17 42
49 }
50 20 return $self->canonpath(join('', @args));
51 }
52  
53 53 ▶sub canonpath {
Subroutine canonpath: called CC=4 SCAR=13.9
Pod documented
54 53 my ($self,$path) = @_;
55 53 ▶ return unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 2 51 53
56  
57 51 $path =~ s/^([a-z]:)/\l$1/s;
58 51 $path =~ s|\\|/|g;
59 51 $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
60 51 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
61 51 $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
62 51 ▶ $path =~ s|/\Z(?!\n)||
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[^([a-z]:)?/\Z(?!\n)]is 51 0 51
63 unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
64 51 $path =~ s{^/\.\.$}{/}; # /.. -> /
65 51 ▶ 1 while $path =~ s{^/\.\.}{}; # /../xx -> /xx
Branch: 1 branch
BranchTrueFalseTotal
$path =~ s[^/\.\.][] and do { '???' } 0 51 51
66 51 return $path;
67 }
68  
69  
70 20 ▶sub splitpath {
Subroutine splitpath: called CC=2 SCAR=6.9
Pod documented
71 20 my ($self,$path, $nofile) = @_;
72 20 my ($volume,$directory,$file) = ('','','');
73 20 ▶ if ( $nofile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nofile) { } 12 8 20
74 12 $path =~
75 m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
76 (.*)
77 }xs;
78 12 $volume = $1;
79 12 $directory = $2;
80 }
81 else {
82 8 $path =~
83 m{^ ( (?: [a-zA-Z]: |
84 (?:\\\\|//)[^\\/]+[\\/][^\\/]+
85 )?
86 )
87 ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
88 (.*)
89 }xs;
90 8 $volume = $1;
91 8 $directory = $2;
92 8 $file = $3;
93 }
94  
95 20 return ($volume,$directory,$file);
96 }
97  
98  
99 5 ▶sub splitdir {
Subroutine splitdir: called CC=1 SCAR=0.0
Pod documented
100 5 my ($self,$directories) = @_ ;
101 5 split m|[\\/]|, $directories, -1;
102 }
103  
104  
105 11 ▶sub catpath {
Subroutine catpath: called CC=7 SCAR=21.1
Pod documented
106 11 my ($self,$volume,$directory,$file) = @_;
107  
108 # If it's UNC, make sure the glue separator is there, reusing
109 # whatever separator is first in the $volume
110 11 ▶ $volume .= $1
Branch: 1 branch
BranchTrueFalseTotal
if $volume =~ m[^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)]s and $directory =~ m[^[^\\/]]s 0 11 11
Condition33%1/3
$volume =~ m[^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)]s and $directory =~ m[^[^\\/]]s
!ll&&!rl&&r
1100
MC/DC0%0/2
$volume =~ m[^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)]s and $directory =~ m[^[^\\/]]s
$volume =~ m[^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)]s $directory =~ m[^[^\\/]]s
Truth table33%1/3
A and B
A= $volume =~ m[^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)]sB= $directory =~ m[^[^\\/]]s
ABresult
0X0
100
111
111 if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
112 $directory =~ m@^[^\\/]@s
113 ) ;
114  
115 11 $volume .= $directory ;
116  
117 # If the volume is not just A:, make sure the glue separator is
118 # there, reusing whatever separator is first in the $volume if possible.
119 11 ▶ if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $volume =~ /^[a-zA-Z]:\Z(?!\n)/s and $volume =~ m[[^\\/]\Z(?!\n)] and $file =~ m[[^\\/]]) 2 9 11
Condition50%3/6
not $volume =~ /^[a-zA-Z]:\Z(?!\n)/s and $volume =~ m[[^\\/]\Z(?!\n)] and $file =~ m[[^\\/]]
!ll&&!rl&&r
092
not $volume =~ /^[a-zA-Z]:\Z(?!\n)/s and $volume =~ m[[^\\/]\Z(?!\n)]
!ll&&!rl&&r
0011
MC/DC33%1/3
not $volume =~ /^[a-zA-Z]:\Z(?!\n)/s and $volume =~ m[[^\\/]\Z(?!\n)] and $file =~ m[[^\\/]]
not $volume =~ /^[a-zA-Z]:\Z(?!\n)/s $volume =~ m[[^\\/]\Z(?!\n)] $file =~ m[[^\\/]]
Truth table50%2/4
not(A) and B and C
A= not $volume =~ /^[a-zA-Z]:\Z(?!\n)/sB= $volume =~ m[[^\\/]\Z(?!\n)]C= $file =~ m[[^\\/]]
ABCresult
0XX0
10X0
1100
1111
120 $volume =~ m@[^\\/]\Z(?!\n)@ &&
121 $file =~ m@[^\\/]@
122 ) {
123 2 $volume =~ m@([\\/])@ ;
124 2 ▶ my $sep = $1 ? $1 : '/' ;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 2 0 2
125 2 $volume .= $sep ;
126 }
127  
128 11 $volume .= $file ;
129  
130 11 return $volume ;
131 }
132  
133  
134 6 ▶sub abs2rel {
Subroutine abs2rel: called CC=11 SCAR=26.5
Pod documented
135 6 my($self,$path,$base) = @_;
136  
137 # Clean up $path
138 6 ▶ if ( ! $self->file_name_is_absolute( $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->file_name_is_absolute($path)) { } 0 6 6
139 0 $path = $self->rel2abs( $path ) ;
140 } else {
141 6 $path = $self->canonpath( $path ) ;
142 }
143  
144 # Figure out the effective $base and clean it up.
145 6 ▶ if ( !defined( $base ) || $base eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $base or $base eq '') { } 0 6 6
elsif (not $self->file_name_is_absolute($base)) { } 0 6 6
Condition33%1/3
not defined $base or $base eq ""
l!l&&r!l&&!r
006
MC/DC0%0/2
not defined $base or $base eq ""
not defined $base $base eq ""
Truth table33%1/3
not(A) or B
A= not defined $baseB= $base eq ""
ABresult
1X1
011
000
146 0 $base = Cwd::getcwd();
147 } elsif ( ! $self->file_name_is_absolute( $base ) ) {
148 0 $base = $self->rel2abs( $base ) ;
149 } else {
150 6 $base = $self->canonpath( $base ) ;
151 }
152  
153 # Split up paths
154 6 my ( $path_volume, $path_directories, $path_file ) = $self->splitpath( $path, 1 ) ;
155 6 my ( $base_volume, $base_directories ) = $self->splitpath( $base, 1 ) ;
156 6 ▶ return $path unless $path_volume eq $base_volume;
Branch: 1 branch
BranchTrueFalseTotal
unless $path_volume eq $base_volume 4 2 6
157  
158 # Now, remove all leading components that are the same
159 2 my @pathchunks = $self->splitdir( $path_directories );
160 2 my @basechunks = $self->splitdir( $base_directories );
161  
162 2 ▶ while ( @pathchunks &&
Branch: 1 branch
BranchTrueFalseTotal
if (@pathchunks and @basechunks and lc $pathchunks[0] eq lc $basechunks[0]) 4 2 6
Condition66%4/6
@pathchunks and @basechunks and lc $pathchunks[0] eq lc $basechunks[0]
!ll&&!rl&&r
204
@pathchunks and @basechunks
!ll&&!rl&&r
024
MC/DC33%1/3
@pathchunks and @basechunks and lc $pathchunks[0] eq lc $basechunks[0]
@pathchunks @basechunks lc $pathchunks[0] eq lc $basechunks[0]
Truth table50%2/4
A and B and C
A= @pathchunksB= @basechunksC= lc $pathchunks[0] eq lc $basechunks[0]
ABCresult
0XX0
10X0
1100
1111
163 @basechunks &&
164 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
165 ) {
166 4 shift @pathchunks ;
167 4 shift @basechunks ;
168 }
169  
170 # No need to catdir, we know these are well formed.
171 2 $path_directories = CORE::join( '/', @pathchunks );
172 2 $base_directories = CORE::join( '/', @basechunks );
173  
174 # $base_directories now contains the directories the resulting relative
175 # path must ascend out of before it can descend to $path_directory. So,
176 # replace all names with $parentDir
177  
178 #FA Need to replace between backslashes...
179 2 $base_directories =~ s|[^\\/]+|..|g ;
180  
181 # Glue the two together, using a separator if necessary, and preventing an
182 # empty result.
183  
184 #FA Must check that new directories are not empty.
185 2 ▶ if ( $path_directories ne '' && $base_directories ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path_directories ne '' and $base_directories ne '') { } 0 2 2
Condition33%1/3
$path_directories ne "" and $base_directories ne ""
!ll&&!rl&&r
020
MC/DC0%0/2
$path_directories ne "" and $base_directories ne ""
$path_directories ne "" $base_directories ne ""
Truth table33%1/3
A and B
A= $path_directories ne ""B= $base_directories ne ""
ABresult
0X0
100
111
186 0 $path_directories = "$base_directories/$path_directories" ;
187 } else {
188 2 $path_directories = "$base_directories$path_directories" ;
189 }
190  
191 2 return $self->canonpath(
192 $self->catpath( "", $path_directories, $path_file )
193 ) ;
194 }
195  
196  
197 10 ▶sub rel2abs {
Subroutine rel2abs: called CC=5 SCAR=28.5
Pod documented
198 10 my ($self,$path,$base ) = @_;
199  
200 10 ▶ if ( ! $self->file_name_is_absolute( $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->file_name_is_absolute($path)) 0 10 10
201  
202 0 ▶ if ( !defined( $base ) || $base eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $base or $base eq '') { } 0 0 0
elsif (not $self->file_name_is_absolute($base)) { } 0 0 0
Condition0%0/3
not defined $base or $base eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $base or $base eq ""
not defined $base $base eq ""
Truth table0%0/3
not(A) or B
A= not defined $baseB= $base eq ""
ABresult
1X1
011
000
203 0 $base = Cwd::getcwd();
204 }
205 elsif ( ! $self->file_name_is_absolute( $base ) ) {
206 0 $base = $self->rel2abs( $base ) ;
207 }
208 else {
209 0 $base = $self->canonpath( $base ) ;
210 }
211  
212 0 my ( $path_directories, $path_file ) =
213 ($self->splitpath( $path, 1 ))[1,2] ;
214  
215 0 my ( $base_volume, $base_directories ) =
216 $self->splitpath( $base, 1 ) ;
217  
218 0 $path = $self->catpath(
219 $base_volume,
220 $self->catdir( $base_directories, $path_directories ),
221 $path_file
222 ) ;
223 }
224  
225 10 return $self->canonpath( $path ) ;
226 }
227  
228 2 1;
229 __END__
« blib/lib/File/Spec/Mac.pm ↑ Summary blib/lib/File/Spec/Win32.pm »