On Feb 7, 4:32 am, [EMAIL PROTECTED] (Craig A. Berry) wrote: > Your approach makes sense, but I think the intention and documentation would > need to be clarified. Basically we're saying $no_file really means > $the_whole_thing_consists_only_of_directory_components even on systems where > you can usually (when not supporting a foreign syntax) tell the difference > between directories and files at a glance.
Thanks for the comments. Potential patch below. When adding test cases for splitpath('d1/d2/d3',1) and splitpath('/d1/ d2/d3',1) I discovered vmsify (used within splitpath) returns [.d1.d2]d3 and d1:[d2]d3 so I catch this in a basic way (see below). I also added some tests for dirs and files named "0" as I've been bitten by this before, this uncovered I needed to check the dir component is defined and not just true. While I was adding splitpath tests I also added some tests for '[]', '[-]', '[]file' and '[-]file'. I'm not sure what behaviour to implement and add tests for when: splitpath('[.d1]file',1) is called, currently because $no_file is not used this returns dir=[.d1] and file=file, but with the patch below this behaviour would change to return dir=[.d1.file] and empty file. I'm thinking it would be safer to preserve current behaviour. I think the question boils down to if $no_file=1 is passed in and the path is in VMS syntax and we can differentiate the $dir and $file components should we: i.) return dir=dir file=file (current behaviour) j.) return dir=dir+file file=empty (this patch behaviour) k.) return dir=dir file=empty l.) return something else I then think, what about: splitpath('[.d1]d2.dir',1)* Depending on what behaviour is implemented for splitpath('[.d1]file', 1) I'm thinking this might be an exception, hmm, and then there is ODS-5 to think about, it's going to be simpler to use (and implement and doc) if $no_file=1 over-rides / has higher precedence than the path being in VMS syntax and being able to differentiate dir and file components. Cheers, Peter (Stig) Edwards * this patch also returns dir='[.d1.file.txt]' file=empty for splitpath('[.d1]file.txt',1) and splitpath('d1/file.txt',1), maybe the code should only do this when the path contains a file component that could also be a valid directory (no periods). ==== pathtools-3_27/lib/file/spec/vms.pm#1 - pathtools-3_27.lib.file.spec]vms.pm ==== 245c245,251 < Splits using VMS syntax. --- > ($volume,$directories,$file) = File::Spec->splitpath( $path ); > ($volume,$directories,$file) = File::Spec->splitpath( $path, $no_file ); > > Splits a path into volume, directory, and filename portions. > > On VMS, assumes that the last part of the path is a filename unless > $no_file is true. 250,254c256,272 < my($self,$path) = @_; < my($dev,$dir,$file) = ('','',''); < < vmsify($path) =~ /(.+:)?([\[<].*[\]>])?(.*)/s; < return ($1 || '',$2 || '',$3); --- > my($self,$path, $nofile) = @_; > my($dev,$dir,$file) = ('','',''); > my $vmsify_path = vmsify($path); > if ( $nofile ){ > #vmsify('d1/d2/d3') returns '[.d1.d2]d3' > #vmsify('/d1/d2/d3') returns 'd1:[d2]d3' > if( $vmsify_path =~ /(.*)\](.+)/ ){ > $vmsify_path = $1.'.'.$2.']'; > } > $vmsify_path =~ /(.+:)?(.*)/s; > $dir = defined $2 ? $2 : ''; # dir can be '0' > return ($1 || '',$dir,$file); > } > else { > $vmsify_path =~ /(.+:)?([\[<].*[\]>])?(.*)/s; > return ($1 || '',$2 || '',$3); > } ==== pathtools-3_27/t/spec.t#1 - pathtools-3_27.t]spec.t ==== 311a312,349 > [ "VMS->splitpath('[]')", ',[],' > ], > [ "VMS->splitpath('[-]')", ',[-],' > ], > [ "VMS->splitpath('[]file')", ',[],file' > ], > [ "VMS->splitpath('[-]file')", ',[-],file' > ], > [ "VMS->splitpath('')", ',,' > ], > [ "VMS->splitpath('0')", ',,0' > ], > [ "VMS->splitpath('[0]')", ',[0],' > ], > [ "VMS->splitpath('[.0]')", ',[.0],' > ], > [ "VMS->splitpath('[0.0.0]')", ',[0.0.0],' > ], > [ "VMS->splitpath('[.0.0.0]')", > ',[.0.0.0],' ], > [ "VMS->splitpath('[0]0')", ',[0],0' > ], > [ "VMS->splitpath('[0.0.0]0')", > ',[0.0.0],0' ], > [ "VMS->splitpath('[.0.0.0]0')", > ',[.0.0.0],0' ], > [ "VMS->splitpath('0/0')", ',[.0],0' > ], > [ "VMS->splitpath('0/0/0')", ',[.0.0],0' > ], > [ "VMS->splitpath('/0/0')", > '0:,[000000],0' ], > [ "VMS->splitpath('/0/0/0')", '0:,[0],0' > ], > [ "VMS->splitpath('d1',1)", ',d1,' > ], > # $no_file tests > [ "VMS->splitpath('[d1.d2.d3]',1)", > ',[d1.d2.d3],' ], > [ "VMS->splitpath('[.d1.d2.d3]',1)", > ',[.d1.d2.d3],' ], > [ "VMS->splitpath('d1/d2/d3',1)", > ',[.d1.d2.d3],' ], > [ "VMS->splitpath('/d1/d2/d3',1)", > 'd1:,[d2.d3],' ], > [ "VMS->splitpath('node::volume:[d1.d2.d3]',1)", > 'node::volume:,[d1.d2.d3],' ], > [ "VMS->splitpath('node\"access_spec\"::volume:[d1.d2.d3]',1)", > 'node"access_spec"::volume:,[d1.d2.d3],' ], > [ "VMS->splitpath('[]',1)", ',[],' > ], > [ "VMS->splitpath('[-]',1)", ',[-],' > ], > [ "VMS->splitpath('',1)", ',,' > ], > [ "VMS->splitpath('0',1)", ',0,' > ], > [ "VMS->splitpath('[0]',1)", ',[0],' > ], > [ "VMS->splitpath('[.0]',1)", ',[.0],' > ], > [ "VMS->splitpath('[0.0.0]',1)", ',[0.0.0],' > ], > [ "VMS->splitpath('[.0.0.0]',1)", > ',[.0.0.0],' ], > [ "VMS->splitpath('0/0',1)", ',[.0.0],' > ], > [ "VMS->splitpath('0/0/0',1)", > ',[.0.0.0],' ], > [ "VMS->splitpath('/0/0',1)", > '0:,[000000.0],' ], > [ "VMS->splitpath('/0/0/0',1)", '0:,[0.0],' > ], >