blib/lib/ExtUtils/Helpers/VMS.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 68 CC 8 SCAR 37.4
CC
8
Cov
0%
detildefy
72.0
make_executable
2.0
BEGIN
2.0
CRAP 42.0
1 package ExtUtils::Helpers::VMS;
2 $ExtUtils::Helpers::VMS::VERSION = '0.028';
3 use strict;
4 use warnings FATAL => 'all';
5  
6 use Exporter 5.57 'import';
7 our @EXPORT = qw/make_executable split_like_shell detildefy/;
8  
9 use ExtUtils::Helpers::Unix qw/split_like_shell/; # Probably very wrong, but whatever
10 use File::Copy qw/copy/;
11  
12 sub make_executable {
13 my $filename = shift;
14 my $batchname = "$filename.com";
15 copy($filename, $batchname);
16 ExtUtils::Helpers::Unix::make_executable($batchname);
17 return;
18 }
19  
20 sub detildefy {
21 my $arg = shift;
22  
23 # Apparently double ~ are not translated.
24 return $arg if ($arg =~ /^~~/);
25  
26 # Apparently ~ followed by whitespace are not translated.
27 return $arg if ($arg =~ /^~ /);
28  
29 if ($arg =~ /^~/) {
30 my $spec = $arg;
31  
32 # Remove the tilde
33 $spec =~ s/^~//;
34  
35 # Remove any slash following the tilde if present.
36 $spec =~ s#^/##;
37  
38 # break up the paths for the merge
39 my $home = VMS::Filespec::unixify($ENV{HOME});
40  
41 # In the default VMS mode, the trailing slash is present.
42 # In Unix report mode it is not. The parsing logic assumes that
43 # it is present.
44 $home .= '/' unless $home =~ m#/$#;
45  
46 # Trivial case of just ~ by it self
47 if ($spec eq '') {
48 $home =~ s#/$##;
49 return $home;
50 }
51  
52 my ($hvol, $hdir, $hfile) = File::Spec::Unix->splitpath($home);
53 if ($hdir eq '') {
54 # Someone has tampered with $ENV{HOME}
55 # So hfile is probably the directory since this should be
56 # a path.
57 $hdir = $hfile;
58 }
59  
60 my ($vol, $dir, $file) = File::Spec::Unix->splitpath($spec);
61  
62 my @hdirs = File::Spec::Unix->splitdir($hdir);
63 my @dirs = File::Spec::Unix->splitdir($dir);
64  
65 unless ($arg =~ m#^~/#) {
66 # There is a home directory after the tilde, but it will already
67 # be present in in @hdirs so we need to remove it by from @dirs.
68  
69 shift @dirs;
70 }
71 my $newdirs = File::Spec::Unix->catdir(@hdirs, @dirs);
72  
73 $arg = File::Spec::Unix->catpath($hvol, $newdirs, $file);
74 }
75 return $arg;
76 }
77  
78 # ABSTRACT: VMS specific helper bits
79  
80 __END__