Skip Menu |

This queue is for tickets about the PathTools CPAN distribution.

Report information
The Basics
Id: 12843
Status: open
Priority: 0/
Queue: PathTools

People
Owner: Nobody in particular
Requestors: abeltje [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: add vmstar_clean() to File::Spec::VMS
Hi, I feel it would help autors of cross-platform modules if they had a way to transform Unix-style paths into a valid VMS path. I used the vmstar source to do it. Modules like EU::MM and Archive::Tar (+CPANPLUS) should benefit from this. hth+ good luck. -- Abe.
diff -ruN --exclude=Filespec.pm PathTools-3.07.orig/MANIFEST PathTools-3.07/MANIFEST --- PathTools-3.07.orig/MANIFEST Fri May 6 14:47:34 2005 +++ PathTools-3.07/MANIFEST Mon May 16 16:51:30 2005 @@ -26,5 +26,6 @@ t/rel2abs2rel.t t/Spec.t t/taint.t +t/vmstar_cleanup.t t/win32.t SIGNATURE Added here by Module::Build Binary files PathTools-3.07.orig/PathTools-3.07.tar.gz and PathTools-3.07/PathTools-3.07.tar.gz differ diff -ruN --exclude=Filespec.pm PathTools-3.07.orig/lib/File/Spec/VMS.pm PathTools-3.07/lib/File/Spec/VMS.pm --- PathTools-3.07.orig/lib/File/Spec/VMS.pm Fri May 6 14:47:34 2005 +++ PathTools-3.07/lib/File/Spec/VMS.pm Mon May 16 16:42:58 2005 @@ -4,7 +4,7 @@ use vars qw(@ISA $VERSION); require File::Spec::Unix; -$VERSION = '1.4'; +$VERSION = '1.5'; @ISA = qw(File::Spec::Unix); @@ -516,6 +516,39 @@ } return $self->canonpath( $path ) ; +} + +=item vmstar_cleanup( $path ) + +This is a port of the vms_cleanup() routine in the vmstar distribution +(in F<tar2vms.c>). + +It transforms illegal characters (for VMS) in a unix style path C<$path> into +undescores and returns a VMS style path. + +=cut + +my $BADCHARS = q-!@#%^&*()+=|~`[]{}':;<>,?\\\"-; +my $TRANSLATE = q-__$______X_________________-; + +sub vmstar_cleanup { + shift; my( $path ) = @_; + + $path =~ s|^\./||; + + eval qq{ \$path =~ tr/$BADCHARS/$TRANSLATE/ }; + + my $fname = ( $path =~ m|/| ? "" : $path ); + $fname or ( $path, $fname ) = $path =~ m|(.+)/(.*)|; + + $path =~ s|^/|[|; # create an absolute path + $path =~ tr|.|_|; # change dots into underscore + $path =~ tr|/|.|; # change directory separator into dot + $path =~ s|^(?!\[)|[.|; # not an absolute path + + defined $fname or $fname = ""; + $fname =~ s/\.(?=.+\..*)/_/g; # change all but the last dot in fname + return "$path]$fname"; } diff -ruN --exclude=Filespec.pm PathTools-3.07.orig/t/vmstar_cleanup.t PathTools-3.07/t/vmstar_cleanup.t --- PathTools-3.07.orig/t/vmstar_cleanup.t Thu Jan 1 01:00:00 1970 +++ PathTools-3.07/t/vmstar_cleanup.t Mon May 16 16:41:35 2005 @@ -0,0 +1,48 @@ +#! perl -w +use strict; + +BEGIN { + if ($ENV{PERL_CORE}) { + @INC = '../lib'; + } +} + +use Test::More; +plan $^O eq 'VMS' ? (tests => 6) : (skip_all => 'this is not VMS'); + +use_ok 'File::Spec::VMS'; + +{ + my $upath = 'sub/dir@2/file.with.dots'; + my $vpath = File::Spec::VMS->vmstar_cleanup( $upath ); + is $vpath, '[.sub.dir_2]file_with.dots', "$upath -> $vpath"; + +} + +{ + my $upath = './sub/dir@2/file.with.dots'; + my $vpath = File::Spec::VMS->vmstar_cleanup( $upath ); + is $vpath, '[.sub.dir_2]file_with.dots', "$upath -> $vpath"; + +} + +{ + my $upath = '/sub/dir@2/file.with.dots'; + my $vpath = File::Spec::VMS->vmstar_cleanup( $upath ); + is $vpath, '[sub.dir_2]file_with.dots', "$upath -> $vpath"; + +} + +{ + my $upath = 'PathTools-3.07/lib/File/Spec/VMS.pm'; + my $vpath = File::Spec::VMS->vmstar_cleanup( $upath ); + is $vpath, '[.PathTools-3_07.lib.File.Spec]VMS.pm', "$upath -> $vpath"; + +} + +{ + my $upath = 'PathTools-3.07/lib/File/Spec/'; + my $vpath = File::Spec::VMS->vmstar_cleanup( $upath ); + is $vpath, '[.PathTools-3_07.lib.File.Spec]', "$upath -> $vpath"; + +}
Hi Abe, Path::Class is a front-end to File::Spec which can do what you want, I believe: perl -MPath::Class -le 'print dir("foo/bar.txt")->as_foreign("VMS")' Er, it looks like this is the one case that doesn't actually work - it requires VMS::Filespec, which apparently can only run on VMS. Do you know of a way to get it working, or to emulate what it's doing? -Ken
Oh, sorry, I hadn't noticed that you'd sent a patch, so I was kind of confused about what you wanted. I think VMS::Filespec is only installed as part of the core on VMS - at least, it doesn't seem to be part of my 5.8.1 install on OS X. That makes File::Spec::VMS unloadable directly too, since it uses VMS::Filespec. So in order for people who aren't on VMS to use your patch, I think more work would have to be done on VMS::Filespec to make it loadable on other platforms. -Ken
[KWILLIAMS - Mon May 30 00:06:55 2005]: Show quoted text
> I think VMS::Filespec is only installed as part of the core on VMS - > at least, it doesn't seem to > be part of my 5.8.1 install on OS X. That makes File::Spec::VMS > unloadable directly too, since > it uses VMS::Filespec. > > So in order for people who aren't on VMS to use your patch, I think > more work would have to > be done on VMS::Filespec to make it loadable on other platforms.
Correct, VMS::Filespec is only installed on VMS. There's no real reason why it couldn't be installed everywhere, the code is pure Perl, and it would make testing VMS-specific code a whole lot easier. I'm looking at making this so. Currently a lot of its tests are failing but they appear to be geniune bugs and not as a result of running on Unix. The tests would have to be fixed before I try making the module universe. I've queried vmsperl@perl.org to have a look.