blib/lib/File/Spec/VMS.pm

filter: Statementstmt 57.2% 118 / 206 Branchbran 35.3% 46 / 130 Conditioncond 25.0% 20 / 80 MC/DCmcdc 10.2% 5 / 49 Subroutinesub 72.7% 16 / 22 Podpod 100% 16 / 16 totaltotal 43.9% 221 / 503 CC 95 SCAR 37.7
CC
95
Cov
44%
catpath
134.4
abs2rel
91.8
rel2abs
69.3
CRAP 43.4
« blib/lib/File/Spec/Cygwin.pm ↑ Summary blib/lib/File/Spec/Unix.pm »
1 package File::Spec::VMS;
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 require File::Spec::Unix;
6  
7 our $VERSION = '3.75';
8 $VERSION =~ tr/_//d;
9  
10 our @ISA = qw(File::Spec::Unix);
11  
12 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use VMS::Filespec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 File::Spec::VMS - methods for VMS file specs
18  
19 =head1 SYNOPSIS
20  
21 require File::Spec::VMS; # Done internally by File::Spec if needed
22  
23 =head1 DESCRIPTION
24  
25 See File::Spec::Unix for a documentation of the methods provided
26 there. This package overrides the implementation of these methods, not
27 the semantics.
28  
29 The default behavior is to allow either VMS or Unix syntax on input and to
30 return VMS syntax on output unless Unix syntax has been explicitly requested
31 via the C<DECC$FILENAME_UNIX_REPORT> CRTL feature.
32  
33 =over 4
34  
35 =cut
36  
37 # Need to look up the feature settings. The preferred way is to use the
38 # VMS::Feature module, but that may not be available to dual life modules.
39  
40 my $use_feature;
41 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.8
42 1 ▶ if (eval { local $SIG{__DIE__};
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { local $SIG{"__DIE__"}; local(@INC) = @INC; pop @INC if $INC[-1] eq "."; require VMS::Feature } }) 0 1 1
43 1 local @INC = @INC;
44 1 ▶ pop @INC if $INC[-1] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 1 0 1
45 1 require VMS::Feature; }) {
46 0 $use_feature = 1;
47 }
48 }
49  
50 # Need to look up the UNIX report mode. This may become a dynamic mode
51 # in the future.
52 131 ▶sub _unix_rpt {
Subroutine _unix_rpt: called CC=3 SCAR=11.8
53 131 my $unix_rpt;
54 131 ▶ if ($use_feature) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_feature) { } 0 131 131
55 0 $unix_rpt = VMS::Feature::current("filename_unix_report");
56 } else {
57 131 ▶ my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
Condition50%1/2
$ENV{'DECC$FILENAME_UNIX_REPORT'} || ''
l!l
0131
MC/DC0%0/1
$ENV{'DECC$FILENAME_UNIX_REPORT'} || ''
$ENV{'DECC$FILENAME_UNIX_REPORT'}
Truth table50%1/2
A
A= $ENV{'DECC$FILENAME_UNIX_REPORT'}
Aresult
11
00
58 131 $unix_rpt = $env_unix_rpt =~ /^[ET1]/i;
59 }
60 131 return $unix_rpt;
61 }
62  
63 =item canonpath (override)
64  
65 Removes redundant portions of file specifications and returns results
66 in native syntax unless Unix filename reporting has been enabled.
67  
68 =cut
69  
70  
71 91 ▶sub canonpath {
Subroutine canonpath: called CC=9 SCAR=22.1
Pod documented
72 91 my($self,$path) = @_;
73  
74 91 ▶ return undef unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 91 91
75  
76 91 my $unix_rpt = $self->_unix_rpt;
77  
78 91 ▶ if ($path =~ m|/|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[/]) 1 90 91
79 1 my $pathify = $path =~ m|/\Z(?!\n)|;
80 1 $path = $self->SUPER::canonpath($path);
81  
82 1 ▶ return $path if $unix_rpt;
Branch: 1 branch
BranchTrueFalseTotal
if $unix_rpt 0 1 1
83 1 ▶ $path = $pathify ? vmspath($path) : vmsify($path);
Branch: 1 branch
BranchTrueFalseTotal
$pathify ? : 0 1 1
84 }
85  
86 90 $path =~ s/(?<!\^)</[/; # < and > ==> [ and ]
87 90 $path =~ s/(?<!\^)>/]/;
88 90 $path =~ s/(?<!\^)\]\[\./\.\]\[/g; # ][. ==> .][
89 90 $path =~ s/(?<!\^)\[000000\.\]\[/\[/g; # [000000.][ ==> [
90 90 $path =~ s/(?<!\^)\[000000\./\[/g; # [000000. ==> [
91 90 $path =~ s/(?<!\^)\.\]\[000000\]/\]/g; # .][000000] ==> ]
92 90 $path =~ s/(?<!\^)\.\]\[/\./g; # foo.][bar ==> foo.bar
93 90 ▶ 1 while ($path =~ s/(?<!\^)([\[\.])(-+)\.(-+)([\.\]])/$1$2$3$4/);
Branch: 1 branch
BranchTrueFalseTotal
$path =~ s/(?<!\^)([\[\.])(-+)\.(-+)([\.\]])/$1$2$3$4/ and do { '???' } 2 90 92
94 # That loop does the following
95 # with any amount of dashes:
96 # .-.-. ==> .--.
97 # [-.-. ==> [--.
98 # .-.-] ==> .--]
99 # [-.-] ==> [--]
100 90 ▶ 1 while ($path =~ s/(?<!\^)([\[\.])(?:\^.|[^\]\.])+\.-(-+)([\]\.])/$1$2$3/);
Branch: 1 branch
BranchTrueFalseTotal
$path =~ s/(?<!\^)([\[\.])(?:\^.|[^\]\.])+\.-(-+)([\]\.])/$1$2$3/ and do { '???' } 17 90 107
101 # That loop does the following
102 # with any amount (minimum 2)
103 # of dashes:
104 # .foo.--. ==> .-.
105 # .foo.--] ==> .-]
106 # [foo.--. ==> [-.
107 # [foo.--] ==> [-]
108 #
109 # And then, the remaining cases
110 90 $path =~ s/(?<!\^)\[\.-/[-/; # [.- ==> [-
111 90 $path =~ s/(?<!\^)\.(?:\^.|[^\]\.])+\.-\./\./g; # .foo.-. ==> .
112 90 $path =~ s/(?<!\^)\[(?:\^.|[^\]\.])+\.-\./\[/g; # [foo.-. ==> [
113 90 $path =~ s/(?<!\^)\.(?:\^.|[^\]\.])+\.-\]/\]/g; # .foo.-] ==> ]
114 # [foo.-] ==> [000000]
115 90 $path =~ s/(?<!\^)\[(?:\^.|[^\]\.])+\.-\]/\[000000\]/g;
116 # [] ==>
117 90 ▶ $path =~ s/(?<!\^)\[\]// unless $path eq '[]';
Branch: 1 branch
BranchTrueFalseTotal
unless $path eq "[]" 90 0 90
118 90 ▶ return $unix_rpt ? unixify($path) : $path;
Branch: 1 branch
BranchTrueFalseTotal
$unix_rpt ? : 0 90 90
119 }
120  
121 =item catdir (override)
122  
123 Concatenates a list of file specifications, and returns the result as a
124 native directory specification unless the Unix filename reporting feature
125 has been enabled. No check is made for "impossible" cases (e.g. elements
126 other than the first being absolute filespecs).
127  
128 =cut
129  
130 27 ▶sub catdir {
Subroutine catdir: called CC=11 SCAR=27.6
Pod documented
131 27 my $self = shift;
132 27 my $dir = pop;
133  
134 27 my $unix_rpt = $self->_unix_rpt;
135  
136 27 ▶ my @dirs = grep {defined() && length()} @_;
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
0429
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
137  
138 27 my $rslt;
139 27 ▶ if (@dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs) { } 24 3 27
140 24 ▶ my $path = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs));
Branch: 1 branch
BranchTrueFalseTotal
@dirs == 1 ? : 19 5 24
141 19 my ($spath,$sdir) = ($path,$dir);
142 19 $spath =~ s/\.dir\Z(?!\n)//i; $sdir =~ s/\.dir\Z(?!\n)//i;
143  
144 19 ▶ if ($unix_rpt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unix_rpt) 0 19 19
145 0 ▶ $spath = unixify($spath) unless $spath =~ m#/#;
Branch: 1 branch
BranchTrueFalseTotal
unless $spath =~ m[/] 0 0 0
146 0 ▶ $sdir= unixify($sdir) unless $sdir =~ m#/#;
Branch: 1 branch
BranchTrueFalseTotal
unless $sdir =~ m[/] 0 0 0
147 0 return $self->SUPER::catdir($spath, $sdir)
148 }
149  
150 19 $rslt = vmspath( unixify($spath) . '/' . unixify($sdir));
151  
152 # Special case for VMS absolute directory specs: these will have
153 # had device prepended during trip through Unix syntax in
154 # eliminate_macros(), since Unix syntax has no way to express
155 # "absolute from the top of this device's directory tree".
156 0 ▶ if ($spath =~ /^[\[<][^.\-]/s) { $rslt =~ s/^[^\[<]+//s; }
Branch: 1 branch
BranchTrueFalseTotal
if ($spath =~ /^[\[<][^.\-]/s) 0 0 0
157  
158 } else {
159 # Single directory. Return an empty string on null input; otherwise
160 # just return a canonical path.
161  
162 3 ▶ if (not defined $dir or not length $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dir && length $dir) { } 1 2 3
Condition66%2/3
defined $dir && length $dir
!ll&&!rl&&r
012
MC/DC50%1/2
defined $dir && length $dir
defined $dir length $dir
Truth table66%2/3
A && B
A= defined $dirB= length $dir
ABresult
0X0
100
111
163 1 $rslt = '';
164 } else {
165 2 ▶ $rslt = $unix_rpt ? $dir : vmspath($dir);
Branch: 1 branch
BranchTrueFalseTotal
$unix_rpt ? : 0 2 2
166 }
167 }
168 1 return $self->canonpath($rslt);
169 }
170  
171 =item catfile (override)
172  
173 Concatenates a list of directory specifications with a filename specification
174 to build a path.
175  
176 =cut
177  
178 13 ▶sub catfile {
Subroutine catfile: called CC=13 SCAR=34.5
Pod documented
179 13 my $self = shift;
180 13 my $tfile = pop();
181 13 my $file = $self->canonpath($tfile);
182 13 ▶ my @files = grep {defined() && length()} @_;
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
183  
184 13 my $unix_rpt = $self->_unix_rpt;
185  
186 13 my $rslt;
187 13 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 11 2 13
188 11 ▶ my $path = (@files == 1 ? $files[0] : $self->catdir(@files));
Branch: 1 branch
BranchTrueFalseTotal
@files == 1 ? : 1 10 11
189 1 my $spath = $path;
190  
191 # Something building a VMS path in pieces may try to pass a
192 # directory name in filename format, so normalize it.
193 1 $spath =~ s/\.dir\Z(?!\n)//i;
194  
195 # If the spath ends with a directory delimiter and the file is bare,
196 # then just concatenate them.
197 1 ▶ if ($spath =~ /^(?<!\^)[^\)\]\/:>]+\)\Z(?!\n)/s && basename($file) eq $file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spath =~ m<^(?<!\^)[^\)\]/:>]+\)\Z(?!\n)>s and basename($file) eq $file) { } 0 1 1
Condition33%1/3
$spath =~ m<^(?<!\^)[^\)\]/:>]+\)\Z(?!\n)>s and basename($file) eq $file
!ll&&!rl&&r
100
MC/DC0%0/2
$spath =~ m<^(?<!\^)[^\)\]/:>]+\)\Z(?!\n)>s and basename($file) eq $file
$spath =~ m<^(?<!\^)[^\)\]/:>]+\)\Z(?!\n)>s basename($file) eq $file
Truth table33%1/3
A and B
A= $spath =~ m<^(?<!\^)[^\)\]/:>]+\)\Z(?!\n)>sB= basename($file) eq $file
ABresult
0X0
100
111
198 0 $rslt = "$spath$file";
199 } else {
200 1 $rslt = unixify($spath);
201 0 ▶ $rslt .= (defined($rslt) && length($rslt) ? '/' : '') . unixify($file);
Branch: 1 branch
BranchTrueFalseTotal
defined $rslt && length $rslt ? : 0 0 0
Condition0%0/3
defined $rslt and length $rslt
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rslt and length $rslt
defined $rslt length $rslt
Truth table0%0/3
A and B
A= defined $rsltB= length $rslt
ABresult
0X0
100
111
202 0 ▶ $rslt = vmsify($rslt) unless $unix_rpt;
Branch: 1 branch
BranchTrueFalseTotal
unless $unix_rpt 0 0 0
203 }
204 }
205 else {
206 # Only passed a single file?
207 2 ▶ my $xfile = (defined($file) && length($file)) ? $file : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $file && length $file ? : 2 0 2
Condition33%1/3
defined $file and length $file
!ll&&!rl&&r
002
MC/DC0%0/2
defined $file and length $file
defined $file length $file
Truth table33%1/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
208  
209 2 ▶ $rslt = $unix_rpt ? $xfile : vmsify($xfile);
Branch: 1 branch
BranchTrueFalseTotal
$unix_rpt ? : 0 2 2
210 }
211 0 ▶ return $self->canonpath($rslt) unless $unix_rpt;
Branch: 1 branch
BranchTrueFalseTotal
unless $unix_rpt 0 0 0
212  
213 # In Unix report mode, do not strip off redundant path information.
214 0 return $rslt;
215 }
216  
217  
218 =item curdir (override)
219  
220 Returns a string representation of the current directory: '[]' or '.'
221  
222 =cut
223  
224 0 ▶sub curdir {
Subroutine curdir: not called CC=2 SCAR=17.9
Pod documented
225 0 my $self = shift @_;
226 0 ▶ return '.' if ($self->_unix_rpt);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_unix_rpt 0 0 0
227 0 return '[]';
228 }
229  
230 =item devnull (override)
231  
232 Returns a string representation of the null device: '_NLA0:' or '/dev/null'
233  
234 =cut
235  
236 0 ▶sub devnull {
Subroutine devnull: not called CC=2 SCAR=17.9
Pod documented
237 0 my $self = shift @_;
238 0 ▶ return '/dev/null' if ($self->_unix_rpt);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_unix_rpt 0 0 0
239 0 return "_NLA0:";
240 }
241  
242 =item rootdir (override)
243  
244 Returns a string representation of the root directory: 'SYS$DISK:[000000]'
245 or '/'
246  
247 =cut
248  
249 0 ▶sub rootdir {
Subroutine rootdir: not called CC=4 SCAR=30.0
Pod documented
250 0 my $self = shift @_;
251 0 ▶ if ($self->_unix_rpt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_unix_rpt) 0 0 0
252 # Root may exist, try it first.
253 0 my $try = '/';
254 0 my ($dev1, $ino1) = stat('/');
255 0 my ($dev2, $ino2) = stat('.');
256  
257 # Perl falls back to '.' if it can not determine '/'
258 0 ▶ if (($dev1 != $dev2) || ($ino1 != $ino2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dev1 != $dev2 or $ino1 != $ino2) 0 0 0
Condition0%0/3
$dev1 != $dev2 or $ino1 != $ino2
l!l&&r!l&&!r
000
MC/DC0%0/2
$dev1 != $dev2 or $ino1 != $ino2
$dev1 != $dev2 $ino1 != $ino2
Truth table0%0/3
A or B
A= $dev1 != $dev2B= $ino1 != $ino2
ABresult
1X1
011
000
259 0 return $try;
260 }
261 # Fall back to UNIX format sys$disk.
262 0 return '/sys$disk/';
263 }
264 0 return 'SYS$DISK:[000000]';
265 }
266  
267 =item tmpdir (override)
268  
269 Returns a string representation of the first writable directory
270 from the following list or '' if none are writable:
271  
272 /tmp if C<DECC$FILENAME_UNIX_REPORT> is enabled.
273 sys$scratch:
274 $ENV{TMPDIR}
275  
276 If running under taint mode, and if $ENV{TMPDIR}
277 is tainted, it is not used.
278  
279 =cut
280  
281 0 ▶sub tmpdir {
Subroutine tmpdir: not called CC=3 SCAR=24.8
Pod documented
282 0 my $self = shift @_;
283 0 my $tmpdir = $self->_cached_tmpdir('TMPDIR');
284 0 ▶ return $tmpdir if defined $tmpdir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tmpdir 0 0 0
285 0 ▶ if ($self->_unix_rpt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_unix_rpt) { } 0 0 0
286 0 $tmpdir = $self->_tmpdir('/tmp', '/sys$scratch', $ENV{TMPDIR});
287 }
288 else {
289 0 $tmpdir = $self->_tmpdir( 'sys$scratch:', $ENV{TMPDIR} );
290 }
291 0 $self->_cache_tmpdir($tmpdir, 'TMPDIR');
292 }
293  
294 =item updir (override)
295  
296 Returns a string representation of the parent directory: '[-]' or '..'
297  
298 =cut
299  
300 0 ▶sub updir {
Subroutine updir: not called CC=2 SCAR=17.9
Pod documented
301 0 my $self = shift @_;
302 0 ▶ return '..' if ($self->_unix_rpt);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_unix_rpt 0 0 0
303 0 return '[-]';
304 }
305  
306 =item case_tolerant (override)
307  
308 VMS file specification syntax is case-tolerant.
309  
310 =cut
311  
312 1 ▶sub case_tolerant {
Subroutine case_tolerant: called CC=1 SCAR=0.0
Pod documented
313 1 return 1;
314 }
315  
316 =item path (override)
317  
318 Translate logical name DCL$PATH as a searchlist, rather than trying
319 to C<split> string value of C<$ENV{'PATH'}>.
320  
321 =cut
322  
323 0 ▶sub path {
Subroutine path: not called CC=2 SCAR=17.9
Pod documented
324 0 my (@dirs,$dir,$i);
325 0 ▶ while ($dir = $ENV{'DCL$PATH;' . $i++}) { push(@dirs,$dir); }
Branch: 1 branch
BranchTrueFalseTotal
if ($dir = $ENV{'DCL$PATH;' . $i++}) 0 0 0
326 0 return @dirs;
327 }
328  
329 =item file_name_is_absolute (override)
330  
331 Checks for VMS directory spec as well as Unix separators.
332  
333 =cut
334  
335 46 ▶sub file_name_is_absolute {
Subroutine file_name_is_absolute: called CC=5 SCAR=17.2
Pod documented
336 46 my ($self,$file) = @_;
337 # If it's a logical name, expand it.
338 46 ▶ $file = $ENV{$file} while $file =~ /^[\w\$\-]+\Z(?!\n)/s && $ENV{$file};
Branch: 1 branch
BranchTrueFalseTotal
$file =~ /^[\w\$\-]+\Z(?!\n)/s and $ENV{$file} and do { $file = $ENV{$file} } 0 46 46
Condition33%1/3
$file =~ /^[\w\$\-]+\Z(?!\n)/s and $ENV{$file}
!ll&&!rl&&r
4600
MC/DC0%0/2
$file =~ /^[\w\$\-]+\Z(?!\n)/s and $ENV{$file}
$file =~ /^[\w\$\-]+\Z(?!\n)/s $ENV{$file}
Truth table33%1/3
A and B
A= $file =~ /^[\w\$\-]+\Z(?!\n)/sB= $ENV{$file}
ABresult
0X0
100
111
339 46 ▶ return scalar($file =~ m!^/!s ||
Condition83%5/6
$file =~ m[^/]s || $file =~ /[<\[][^.\-\]>]/ || $file =~ /^[A-Za-z0-9_\$\-\~]+(?<!\^):/
l!l&&r!l&&!r
3925
$file =~ m[^/]s or $file =~ /[<\[][^.\-\]>]/
l!l&&r!l&&!r
0397
MC/DC66%2/3
$file =~ m[^/]s || $file =~ /[<\[][^.\-\]>]/ || $file =~ /^[A-Za-z0-9_\$\-\~]+(?<!\^):/
$file =~ m[^/]s $file =~ /[<\[][^.\-\]>]/ $file =~ /^[A-Za-z0-9_\$\-\~]+(?<!\^):/
Truth table75%3/4
A or B || C
A= $file =~ m[^/]sB= $file =~ /[<\[][^.\-\]>]/C= $file =~ /^[A-Za-z0-9_\$\-\~]+(?<!\^):/
ABCresult
1XX1
01X1
0011
0000
340 $file =~ m![<\[][^.\-\]>]! ||
341 $file =~ /^[A-Za-z0-9_\$\-\~]+(?<!\^):/);
342 }
343  
344 =item splitpath (override)
345  
346 ($volume,$directories,$file) = File::Spec->splitpath( $path );
347 ($volume,$directories,$file) = File::Spec->splitpath( $path,
348 $no_file );
349  
350 Passing a true value for C<$no_file> indicates that the path being
351 split only contains directory components, even on systems where you
352 can usually (when not supporting a foreign syntax) tell the difference
353 between directories and files at a glance.
354  
355 =cut
356  
357 81 ▶sub splitpath {
Subroutine splitpath: called CC=7 SCAR=36.7
Pod documented
358 81 my($self,$path, $nofile) = @_;
359 81 my($dev,$dir,$file) = ('','','');
360 81 my $vmsify_path = vmsify($path);
361  
362 0 ▶ if ( $nofile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nofile) { } 0 0 0
363 #vmsify('d1/d2/d3') returns '[.d1.d2]d3'
364 #vmsify('/d1/d2/d3') returns 'd1:[d2]d3'
365 0 ▶ if( $vmsify_path =~ /(.*)\](.+)/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($vmsify_path =~ /(.*)\](.+)/) 0 0 0
366 0 $vmsify_path = $1.'.'.$2.']';
367 }
368 0 $vmsify_path =~ /(.+:)?(.*)/s;
369 0 ▶ $dir = defined $2 ? $2 : ''; # dir can be '0'
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 0 0
370 0 ▶ return ($1 || '',$dir,$file);
Condition0%0/2
$1 || ''
l!l
00
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
371 }
372 else {
373 0 $vmsify_path =~ /(.+:)?([\[<].*[\]>])?(.*)/s;
374 0 ▶ return ($1 || '',$2 || '',$3);
Condition0%0/4
$1 || ''
l!l
00
$2 || ''
l!l
00
MC/DC0%0/1
$1 || ''
$1
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $1
Aresult
11
00
Truth table0%0/2
A
A= $2
Aresult
11
00
375 }
376 }
377  
378 =item splitdir (override)
379  
380 Split a directory specification into the components.
381  
382 =cut
383  
384 15 ▶sub splitdir {
Subroutine splitdir: called CC=5 SCAR=16.3
Pod documented
385 15 my($self,$dirspec) = @_;
386 15 my @dirs = ();
387 15 ▶ return @dirs if ( (!defined $dirspec) || ('' eq $dirspec) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $dirspec or "" eq $dirspec 1 14 15
Condition66%2/3
not defined $dirspec or "" eq $dirspec
l!l&&r!l&&!r
0114
MC/DC50%1/2
not defined $dirspec or "" eq $dirspec
not defined $dirspec "" eq $dirspec
Truth table66%2/3
not(A) or B
A= not defined $dirspecB= "" eq $dirspec
ABresult
1X1
011
000
388  
389 14 $dirspec =~ s/(?<!\^)</[/; # < and > ==> [ and ]
390 14 $dirspec =~ s/(?<!\^)>/]/;
391 14 $dirspec =~ s/(?<!\^)\]\[\./\.\]\[/g; # ][. ==> .][
392 14 $dirspec =~ s/(?<!\^)\[000000\.\]\[/\[/g; # [000000.][ ==> [
393 14 $dirspec =~ s/(?<!\^)\[000000\./\[/g; # [000000. ==> [
394 14 $dirspec =~ s/(?<!\^)\.\]\[000000\]/\]/g; # .][000000] ==> ]
395 14 $dirspec =~ s/(?<!\^)\.\]\[/\./g; # foo.][bar ==> foo.bar
396 14 ▶ while ($dirspec =~ s/(^|[\[\<\.])\-(\-+)($|[\]\>\.])/$1-.$2$3/g) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($dirspec =~ s/(^|[\[\<\.])\-(\-+)($|[\]\>\.])/$1-.$2$3/g) 2 14 16
397 # That loop does the following
398 # with any amount of dashes:
399 # .--. ==> .-.-.
400 # [--. ==> [-.-.
401 # .--] ==> .-.-]
402 # [--] ==> [-.-]
403 14 ▶ $dirspec = "[$dirspec]" unless $dirspec =~ /(?<!\^)[\[<]/; # make legal
Branch: 1 branch
BranchTrueFalseTotal
unless $dirspec =~ /(?<!\^)[\[<]/ 3 11 14
404 14 $dirspec =~ s/^(\[|<)\./$1/;
405 14 @dirs = split /(?<!\^)\./, vmspath($dirspec);
406 0 $dirs[0] =~ s/^[\[<]//s; $dirs[-1] =~ s/[\]>]\Z(?!\n)//s;
407 0 @dirs;
408 }
409  
410  
411 =item catpath (override)
412  
413 Construct a complete filespec.
414  
415 =cut
416  
417 13 ▶sub catpath {
Subroutine catpath: called CC=12 SCAR=49.0
Pod documented
418 13 my($self,$dev,$dir,$file) = @_;
419
420 # We look for a volume in $dev, then in $dir, but not both
421 13 my ($dir_volume, $dir_dir, $dir_file) = $self->splitpath($dir);
422 0 ▶ $dev = $dir_volume unless length $dev;
Branch: 1 branch
BranchTrueFalseTotal
unless length $dev 0 0 0
423 0 ▶ $dir = length $dir_file ? $self->catfile($dir_dir, $dir_file) : $dir_dir;
Branch: 1 branch
BranchTrueFalseTotal
length $dir_file ? : 0 0 0
424
425 0 ▶ if ($dev =~ m|^(?<!\^)/+([^/]+)|) { $dev = "$1:"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($dev =~ m[^(?<!\^)/+([^/]+)]) { } 0 0 0
426 0 ▶ else { $dev .= ':' unless $dev eq '' or $dev =~ /:\Z(?!\n)/; }
Branch: 1 branch
BranchTrueFalseTotal
unless $dev eq "" or $dev =~ /:\Z(?!\n)/ 0 0 0
Condition0%0/3
$dev eq "" or $dev =~ /:\Z(?!\n)/
l!l&&r!l&&!r
000
MC/DC0%0/2
$dev eq "" or $dev =~ /:\Z(?!\n)/
$dev eq "" $dev =~ /:\Z(?!\n)/
Truth table0%0/3
A or B
A= $dev eq ""B= $dev =~ /:\Z(?!\n)/
ABresult
1X1
011
000
427 0 ▶ if (length($dev) or length($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $dev or length $dir) 0 0 0
Condition0%0/3
length $dev or length $dir
l!l&&r!l&&!r
000
MC/DC0%0/2
length $dev or length $dir
length $dev length $dir
Truth table0%0/3
A or B
A= length $devB= length $dir
ABresult
1X1
011
000
428 0 ▶ $dir = "[$dir]" unless $dir =~ /(?<!\^)[\[<\/]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir =~ m((?<!\^)[\[</]) 0 0 0
429 0 $dir = vmspath($dir);
430 }
431 0 ▶ $dir = '' if length($dev) && ($dir eq '[]' || $dir eq '<>');
Branch: 1 branch
BranchTrueFalseTotal
if length $dev and $dir eq "[]" || $dir eq "<>" 0 0 0
Condition0%0/6
length $dev and $dir eq "[]" || $dir eq "<>"
!ll&&!rl&&r
000
$dir eq "[]" or $dir eq "<>"
l!l&&r!l&&!r
000
MC/DC0%0/3
length $dev and $dir eq "[]" || $dir eq "<>"
length $dev $dir eq "[]" $dir eq "<>"
Truth table0%0/4
A and B or C
A= length $devB= $dir eq "[]"C= $dir eq "<>"
ABCresult
0XX0
1000
11X1
1011
432 0 "$dev$dir$file";
433 }
434  
435 =item abs2rel (override)
436  
437 Attempt to convert an absolute file specification to a relative specification.
438  
439 =cut
440  
441 18 ▶sub abs2rel {
Subroutine abs2rel: called CC=13 SCAR=45.2
Pod documented
442 18 my $self = shift;
443 18 my($path,$base) = @_;
444  
445 18 ▶ $base = Cwd::getcwd() unless defined $base and length $base;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base and length $base 0 18 18
Condition33%1/3
defined $base and length $base
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $base and length $base
defined $base length $base
Truth table33%1/3
A and B
A= defined $baseB= length $base
ABresult
0X0
100
111
446  
447 # If there is no device or directory syntax on $base, make sure it
448 # is treated as a directory.
449 18 ▶ $base = vmspath($base) unless $base =~ m{(?<!\^)[\[<:]};
Branch: 1 branch
BranchTrueFalseTotal
unless $base =~ /(?<!\^)[\[<:]/ 2 16 18
450  
451 16 for ($path, $base) { $_ = $self->rel2abs($_) }
452  
453 # Are we even starting $path on the same (node::)device as $base? Note that
454 # logical paths or nodename differences may be on the "same device"
455 # but the comparison that ignores device differences so as to concatenate
456 # [---] up directory specs is not even a good idea in cases where there is
457 # a logical path difference between $path and $base nodename and/or device.
458 # Hence we fall back to returning the absolute $path spec
459 # if there is a case blind device (or node) difference of any sort
460 # and we do not even try to call $parse() or consult %ENV for $trnlnm()
461 # (this module needs to run on non VMS platforms after all).
462
463 16 my ($path_volume, $path_directories, $path_file) = $self->splitpath($path);
464 0 my ($base_volume, $base_directories, $base_file) = $self->splitpath($base);
465 0 ▶ return $self->canonpath( $path ) unless lc($path_volume) eq lc($base_volume);
Branch: 1 branch
BranchTrueFalseTotal
unless lc $path_volume eq lc $base_volume 0 0 0
466  
467 # Now, remove all leading components that are the same
468 0 my @pathchunks = $self->splitdir( $path_directories );
469 0 my $pathchunks = @pathchunks;
470 0 ▶ unshift(@pathchunks,'000000') unless $pathchunks[0] eq '000000';
Branch: 1 branch
BranchTrueFalseTotal
unless $pathchunks[0] eq "000000" 0 0 0
471 0 my @basechunks = $self->splitdir( $base_directories );
472 0 my $basechunks = @basechunks;
473 0 ▶ unshift(@basechunks,'000000') unless $basechunks[0] eq '000000';
Branch: 1 branch
BranchTrueFalseTotal
unless $basechunks[0] eq "000000" 0 0 0
474  
475 0 ▶ while ( @pathchunks &&
Branch: 1 branch
BranchTrueFalseTotal
if (@pathchunks and @basechunks and lc $pathchunks[0] eq lc $basechunks[0]) 0 0 0
Condition0%0/6
@pathchunks and @basechunks and lc $pathchunks[0] eq lc $basechunks[0]
!ll&&!rl&&r
000
@pathchunks and @basechunks
!ll&&!rl&&r
000
MC/DC0%0/3
@pathchunks and @basechunks and lc $pathchunks[0] eq lc $basechunks[0]
@pathchunks @basechunks lc $pathchunks[0] eq lc $basechunks[0]
Truth table0%0/4
A and B and C
A= @pathchunksB= @basechunksC= lc $pathchunks[0] eq lc $basechunks[0]
ABCresult
0XX0
10X0
1100
1111
476 @basechunks &&
477 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
478 ) {
479 0 shift @pathchunks ;
480 0 shift @basechunks ;
481 }
482  
483 # @basechunks now contains the directories to climb out of,
484 # @pathchunks now has the directories to descend in to.
485 0 ▶ if ((@basechunks > 0) || ($basechunks != $pathchunks)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@basechunks > 0 or $basechunks != $pathchunks) { } 0 0 0
Condition0%0/3
@basechunks > 0 or $basechunks != $pathchunks
l!l&&r!l&&!r
000
MC/DC0%0/2
@basechunks > 0 or $basechunks != $pathchunks
@basechunks > 0 $basechunks != $pathchunks
Truth table0%0/3
A or B
A= @basechunks > 0B= $basechunks != $pathchunks
ABresult
1X1
011
000
486 0 $path_directories = join '.', ('-' x @basechunks, @pathchunks) ;
487 }
488 else {
489 0 $path_directories = join '.', @pathchunks;
490 }
491 0 $path_directories = '['.$path_directories.']';
492 0 return $self->canonpath( $self->catpath( '', $path_directories, $path_file ) ) ;
493 }
494  
495  
496 =item rel2abs (override)
497  
498 Return an absolute file specification from a relative one.
499  
500 =cut
501  
502 38 ▶sub rel2abs {
Subroutine rel2abs: called CC=15 SCAR=42.4
Pod documented
503 38 my $self = shift ;
504 38 my ($path,$base ) = @_;
505 38 ▶ return undef unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 38 38
506 38 ▶ if ($path =~ m/\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[/]) 0 38 38
507 0 ▶ $path = ( -d $path || $path =~ m/\/\z/ # educated guessing about
Branch: 1 branch
BranchTrueFalseTotal
-d $path || $path =~ m[/\z] ? : 0 0 0
Condition0%0/3
-d $path or $path =~ m[/\z]
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $path or $path =~ m[/\z]
-d $path $path =~ m[/\z]
Truth table0%0/3
A or B
A= -d $pathB= $path =~ m[/\z]
ABresult
1X1
011
000
508 ? vmspath($path) # whether it's a directory
509 : vmsify($path) );
510 }
511 38 ▶ $base = vmspath($base) if defined $base && $base =~ m/\//;
Branch: 1 branch
BranchTrueFalseTotal
if defined $base and $base =~ m[/] 0 38 38
Condition66%2/3
defined $base and $base =~ m[/]
!ll&&!rl&&r
3260
MC/DC0%0/2
defined $base and $base =~ m[/]
defined $base $base =~ m[/]
Truth table66%2/3
A and B
A= defined $baseB= $base =~ m[/]
ABresult
0X0
100
111
512  
513 # Clean up and split up $path
514 38 ▶ if ( ! $self->file_name_is_absolute( $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->file_name_is_absolute($path)) 5 33 38
515 # Figure out the effective $base and clean it up.
516 5 ▶ if ( !defined( $base ) || $base eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $base or $base eq '') { } 0 5 5
elsif (not $self->file_name_is_absolute($base)) { } 0 5 5
Condition33%1/3
not defined $base or $base eq ""
l!l&&r!l&&!r
005
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
517 0 $base = Cwd::getcwd();
518 }
519 elsif ( ! $self->file_name_is_absolute( $base ) ) {
520 0 $base = $self->rel2abs( $base ) ;
521 }
522 else {
523 5 $base = $self->canonpath( $base ) ;
524 }
525  
526 # Split up paths
527 5 my ( $path_directories, $path_file ) =
528 ($self->splitpath( $path ))[1,2] ;
529  
530 0 my ( $base_volume, $base_directories ) =
531 $self->splitpath( $base ) ;
532  
533 0 ▶ $path_directories = '' if $path_directories eq '[]' ||
Branch: 1 branch
BranchTrueFalseTotal
if $path_directories eq "[]" or $path_directories eq "<>" 0 0 0
Condition0%0/3
$path_directories eq "[]" or $path_directories eq "<>"
l!l&&r!l&&!r
000
MC/DC0%0/2
$path_directories eq "[]" or $path_directories eq "<>"
$path_directories eq "[]" $path_directories eq "<>"
Truth table0%0/3
A or B
A= $path_directories eq "[]"B= $path_directories eq "<>"
ABresult
1X1
011
000
534 $path_directories eq '<>';
535 0 my $sep = '' ;
536 0 ▶ $sep = '.'
Branch: 1 branch
BranchTrueFalseTotal
if $base_directories =~ /[^.\]>]\Z(?!\n)/ and $path_directories =~ /^[^.\[<]/s 0 0 0
Condition0%0/3
$base_directories =~ /[^.\]>]\Z(?!\n)/ and $path_directories =~ /^[^.\[<]/s
!ll&&!rl&&r
000
MC/DC0%0/2
$base_directories =~ /[^.\]>]\Z(?!\n)/ and $path_directories =~ /^[^.\[<]/s
$base_directories =~ /[^.\]>]\Z(?!\n)/ $path_directories =~ /^[^.\[<]/s
Truth table0%0/3
A and B
A= $base_directories =~ /[^.\]>]\Z(?!\n)/B= $path_directories =~ /^[^.\[<]/s
ABresult
0X0
100
111
537 if ( $base_directories =~ m{[^.\]>]\Z(?!\n)} &&
538 $path_directories =~ m{^[^.\[<]}s
539 ) ;
540 0 $base_directories = "$base_directories$sep$path_directories";
541 0 $base_directories =~ s{\.?[\]>][\[<]\.?}{.};
542  
543 0 $path = $self->catpath( $base_volume, $base_directories, $path_file );
544 }
545  
546 33 return $self->canonpath( $path ) ;
547 }
548  
549  
550 =back
551  
552 =head1 COPYRIGHT
553  
554 Copyright (c) 2004-14 by the Perl 5 Porters. All rights reserved.
555  
556 This program is free software; you can redistribute it and/or modify
557 it under the same terms as Perl itself.
558  
559 =head1 SEE ALSO
560  
561 See L<File::Spec> and L<File::Spec::Unix>. This package overrides the
562 implementation of these methods, not the semantics.
563  
564 An explanation of VMS file specs can be found at
565 L<http://h71000.www7.hp.com/doc/731FINAL/4506/4506pro_014.html#apps_locating_naming_files>.
566  
567 =cut
568  
569 1;
« blib/lib/File/Spec/Cygwin.pm ↑ Summary blib/lib/File/Spec/Unix.pm »