Browse files

remove all case-tolerant methods

Underused and less useful methods don't need to be in the core module -- especially if this could end up in CORE.setting
case-tolerant and default-case-tolerant were split into their own module, File::Spec::Case (for now) where it works almost the same way.
  • Loading branch information...
1 parent d305ff5 commit 95ad1746465be02636972a2f3d4ab3bc256997c3 @labster labster committed Apr 14, 2013
Showing with 16 additions and 122 deletions.
  1. +4 −18 README.md
  2. +0 −2 lib/File/Spec.pm
  3. +0 −1 lib/File/Spec/Cygwin.pm
  4. +0 −1 lib/File/Spec/Mac.pm
  5. +0 −59 lib/File/Spec/Unix.pm
  6. +0 −2 lib/File/Spec/VMS.pm
  7. +0 −2 lib/File/Spec/Win32.pm
  8. +3 −4 t/00_load.t
  9. +1 −3 t/01_cygwin.t
  10. +6 −7 t/01_mac.t
  11. +1 −14 t/01_unix.t
  12. +0 −2 t/01_vms.t
  13. +1 −7 t/01_win32.t
View
22 README.md
@@ -28,7 +28,6 @@ Methods (current state):
catfile done done done
abs2rel done done done
rel2abs done done done
- case-tolerant done done done done done
'~~' means partially implemented, but not passing tests.
@@ -40,27 +39,14 @@ See [Perl 5 File::Spec](http://search.cpan.org/~smueller/PathTools-3.40/lib/File
Method `no_updirs` is gone, because its use case is handled automatically by `dir()`. For the test that supplies dir with its functionality, see new method `no-parent-or-current-test`.
+Method `case_tolerant` has moved to its own module, [File::Spec::Case](https://github.com/labster/p6-File-Spec-Case), and slightly changed its interface.
+
## Changed methods
### join
The method `join` is no longer an alias for `catfile`, but instead a unique function similar to `catpath`. See the description of join in the New methods section.
-### case_tolerant
-Method `case_tolerant` now requires a path (default $*CWD), below which it tests for case sensitivity. A :no-write parameter may be passed if you want to disable writing of test files (which is tried last).
-
- File::Spec.case_tolerant('foo/bar');
- File::Spec.case_tolerant('/etc', :no-write);
-
-It will find case (in)sensitivity if any of the following are true, in increasing order of desperation:
-
-* The $path passed contains \<alpha\> and no symbolic links.
-* The $path contains \<alpha\> after the last symlink.
-* Any folders in the path (under the last symlink, if applicable) contain a file matching \<alpha\>.
-* Any folders in the path (under the last symlink, if applicable) are writable.
-
-Otherwise, it returns the platform default.
-
## New methods
### os
@@ -122,7 +108,7 @@ This method is the inverse of `.split`; the results can be passed to it to get t
### no-parent-or-current-test
-Returns a test as to whether a given path is identical to the parent or the current directory. This is used automatically by `dir()` for directory listings, so under normal circumstances you shouldn't need to use it directly.
+Returns a test as to whether a given path is identical to the parent or the current directory. The `dir()` function automatically removes these for you in directory listings, so under normal circumstances you shouldn't need to use it directly.
'file' ~~ File::Spec.no-parent-or-current-test #False
'.' ~~ File::Spec.no-parent-or-current-test #True
@@ -135,4 +121,4 @@ This can, however, be used to extend `dir()` through its `$test` parameter:
This example would return all files begining with a period that are not `.` or `..` directories.
-This replaces the functionality the old `no-updirs` method.
+This replaces the functionality of the old `no-updirs` method.
View
2 lib/File/Spec.pm
@@ -34,15 +34,13 @@ method rootdir { ::($module).rootdir()
method tmpdir { ::($module).tmpdir() }
method updir { ::($module).updir() }
method no-parent-or-current-test { ::($module).no-parent-or-current-test }
-method default-case-tolerant { ::($module).default-case-tolerant() }
method file-name-is-absolute( $file ) { ::($module).file-name-is-absolute( $file ) }
method path { ::($module).path() }
method splitpath( $path, $no_file = False ) { ::($module).splitpath( $path, $no_file ) }
method splitdir( $path ) { ::($module).splitdir( $path ) }
method catpath( $volume, $directory, $file) { ::($module).catpath( $volume, $directory, $file) }
method abs2rel( |c ) { ::($module).abs2rel( |c ) }
method rel2abs( |c ) { ::($module).rel2abs( |c ) }
-method case-tolerant( $path = $*CWD ) { ::($module).case-tolerant( $path ) }
method split ( $path ) { ::($module).split( $path ) }
method join ( $volume, $directory, $file ) { ::($module).join( $volume, $directory, $file ) }
View
1 lib/File/Spec/Cygwin.pm
@@ -48,4 +48,3 @@ method splitpath (|c) { File::Spec::Win32.splitpath(|c) }
method catpath (|c) { File::Spec::Win32.catpath(|c).subst(:global, '\\', '/') }
method split ($path) { File::Spec::Win32.split($path.subst(:global, '\\', '/')}
method join (|c) { File::Spec::Win32.join(|c).subst(:global, '\\', '/') }
-method default-case-tolerant { True }
View
1 lib/File/Spec/Mac.pm
@@ -20,7 +20,6 @@ method tmpdir {
method updir { '::' }
method no-parent-or-current-test { ::($module).no-parent-or-current-test }
-method case-tolerant { 1 }
method file-name-is-absolute ($path) {
do given $path {
when m/':'/ { ! ($path ~~ /^':'/) }
View
59 lib/File/Spec/Unix.pm
@@ -28,7 +28,6 @@ method curdir { '.' }
method updir { '..' }
method rootdir { '/' }
method devnull { '/dev/null' }
-method default-case-tolerant { so $*OS eq 'darwin'|'epoc' }
method _firsttmpdir( *@dirlist ) {
my $tmpdir = @dirlist.first: { .defined && .IO.d && .IO.w }
@@ -170,61 +169,3 @@ method rel2abs( $path, $base is copy = $*CWD) {
}
self.catdir( $base, $path );
}
-
-method case-tolerant (Str:D $path = $*CWD, $write_ok as Bool = True ) {
- # This code should be platform independent, but feel free to add local override
-
- $path.IO.e or fail "Invalid path given";
- my @dirs = self.splitdir(self.rel2abs($path));
- my @searchabledirs;
-
- # try looking at each component of $path to see if has letters
- loop (my $i = +@dirs; $i--; $i <= 0) {
- my $p = self.catdir(@dirs[0..$i]);
- push(@searchabledirs, $p) if $p.IO.d;
-
- last if $p.IO.l;
- next unless @dirs[$i] ~~ /<+alpha-[_]>/;
-
- return self!case-tolerant-folder: @dirs[0..($i-1)], @dirs[$i];
- }
-
- # If nothing in $path contains a letter, search for nearby files, including up the tree
- # This doesn't actually look recursively; don't want to add File::Find as a dependency
- for @searchabledirs -> $d {
- my @filelist = dir($d).grep(/<+alpha-[_]>/);
- next unless @filelist.elems;
-
- # anything with <alpha> will do
- return self!case-tolerant-folder: $d, @filelist[0];
- }
-
- # If we couldn't find anything suitable, try writing a test file
- if $write_ok {
- for @searchabledirs.grep({.IO.w}) -> $d {
- my $filelc = self.catdir( $d, 'filespec.tmp'); #because 8.3 filesystems...
- my $fileuc = self.catdir( $d, 'FILESPEC.TMP');
- if $filelc.IO.e or $fileuc.IO.e { die "Wait, where did the file matching <alpha> come from??"; }
- try {
- spurt $filelc, 'temporary test file for p6 File::Spec, feel free to delete';
- my $result = $fileuc.IO.e;
- unlink $filelc;
- return $result;
- }
- CATCH { unlink $filelc if $filelc.IO.e; }
- }
- }
-
- # Okay, we don't have write access... give up and just return the platform default
- return self.default-case-tolerant;
-
-}
-
-method !case-tolerant-folder( \updirs, $curdir ) {
- return False unless self.catdir( |updirs, $curdir.uc).IO.e
- && self.catdir( |updirs, $curdir.lc).IO.e;
- return +dir(self.catdir(|updirs)).grep(/:i ^ $curdir $/) <= 1;
- # this could be faster by comparing inodes of .uc and .lc
- # but we can't guarantee POSIXness of every platform that calls this
-}
-
View
2 lib/File/Spec/VMS.pm
@@ -136,8 +136,6 @@ method devnull { $unix_report ?? '/dev/null' !! "_NLA0:" }
method rootdir { ::($module).rootdir() }
method updir { $unix_report ?? '..' !! '[-]' }
method no-parent-or-current-test { ::($module).no-parent-or-current-test }
-method case_tolerant { True }
-method default_case_tolerant { True }
method splitdir { ::($module).splitdir() }
method abs2rel { ::($module).abs2rel() }
method rel2abs { ::($module).rel2abs() }
View
2 lib/File/Spec/Win32.pm
@@ -46,8 +46,6 @@ method path {
return @path;
}
-method default-case-tolerant { True }
-
method file-name-is-absolute ($path) {
# As of right now, this returns 2 if the path is absolute with a
# volume, 1 if it's absolute with no volume, 0 otherwise.
View
7 t/00_load.t
@@ -3,14 +3,13 @@ use Test;
use lib 'lib';
use File::Spec;
-plan 27;
+plan 25;
eval_lives_ok 'use File::Spec', 'we can use File::Spec';
ok $*OS, "your operating system is $*OS";
_can_ok $_ for <canonpath catdir catfile curdir devnull rootdir tmpdir
- updir no-parent-or-current-test case-tolerant default-case-tolerant
- file-name-is-absolute path splitpath splitdir catpath
- split join abs2rel rel2abs os>;
+ updir no-parent-or-current-test file-name-is-absolute
+ path splitpath splitdir catpath split join abs2rel rel2abs os>;
sub _can_ok( $method ) {
ok File::Spec.^methods.first( $method ), "we can call File::Spec.$method"
View
4 t/01_cygwin.t
@@ -4,7 +4,7 @@ use Test;
use File::Spec;
use File::Spec::Cygwin;
-plan 104;
+plan 102;
my $cygwin = File::Spec::Cygwin;
say "# File::Spec::Cygwin";
@@ -166,7 +166,6 @@ is $cygwin.curdir, '.', 'curdir is "."';
is $cygwin.devnull, '/dev/null', 'devnull is /dev/null';
is $cygwin.rootdir, '/', 'rootdir is "\\"';
is $cygwin.updir, '..', 'updir is ".."';
-is $cygwin.default-case-tolerant, True, 'default-case-tolerant is True';
if $*OS !~~ any(<cygwin>) {
@@ -176,7 +175,6 @@ else {
# double check a couple of things to see if File::Spec loaded correctly
is File::Spec.rootdir, '\\', 'File::Spec loads Cygwin';
ok {.IO.d && .IO.w}.(File::Spec.tmpdir), "tmpdir: {File::Spec.tmpdir} is a writable directory";
- is File::Spec.case-tolerant, True, 'case-tolerant is True';
}
done;
View
13 t/01_mac.t
@@ -34,7 +34,9 @@ my @splitpath_test =
'hd:file', 'hd:,,file';
say "# Test splitpath";
-for @splitpath_test -> $get, $want { is $Mac.splitpath(|$get).join(','), $want };
+for @splitpath_test -> $get, $want {
+ is $Mac.splitpath(|$get).join(','), $want, "splitpath: {$get.perl} -> '$want'";
+}
if $*OS !~~ 'MacOS' {
@@ -49,19 +51,16 @@ else {
#rootdir
#tmpdir
is File::Spec.updir, '::', 'updir is "::"';
- #no-upwards
-
- is File::Spec.case-tolerant, True, 'case-tolerant is True';
- is File::Spec.default-case-tolerant, True, 'default-case-tolerant is True';
+ #no-parent-or-current-test
#file-name-is-absolute
#path
#join
- is File::Spec.splitpath('hd:file'), 'hd:,,file';
+ #split
#splitdir
#catpath
#abs2rel
- #rel2ab
+ #rel2abs
}
done;
View
15 t/01_unix.t
@@ -4,7 +4,7 @@ use Test;
use File::Spec;
use File::Spec::Unix;
-plan 110;
+plan 109;
my $Unix := File::Spec::Unix;
@@ -50,11 +50,6 @@ isnt '..', $Unix.no-parent-or-current-test, "no-parent-or-current-test: '..'
is '.git', $Unix.no-parent-or-current-test, "no-parent-or-current-test: '.git'";
is 'file', $Unix.no-parent-or-current-test, "no-parent-or-current-test: 'file'";
-
-#my @get = <. .. .git blib lib t>;
-#my @want = <.git blib lib t>;
-#is_deeply $Unix.no-upwards( @get ), @want, 'no-upwards: (. .. .git blib lib t) -> (.git blib lib t)';
-
ok $Unix.file-name-is-absolute( '/abcd' ), 'file-name-is-absolute: ok "/abcd"';
nok $Unix.file-name-is-absolute( 'abcd' ), 'file-name-is-absolute: nok "abcd"';
@@ -173,14 +168,6 @@ else {
is File::Spec.MODULE, "File::Spec::Unix", "unix: loads correct module";
is File::Spec.rel2abs( File::Spec.curdir ), $*CWD, "rel2abs: \$*CWD test";
ok {.IO.d && .IO.w}.(File::Spec.tmpdir), "tmpdir: {File::Spec.tmpdir} is a writable directory";
- #case-tolerant
- if (cwd.IO ~~ :w) {
- "casetol.tmp".IO.e or spurt "casetol.tmp", "temporary test file, delete after reading";
- is $Unix.case-tolerant("casetol.tmp"), so "CASETOL.TMP".IO.e, "case-tolerant is {so "CASETOL.TMP".IO.e} in cwd";
- unlink "casetol.tmp";
- }
- else { skip "case-tolerant, no write access in cwd", 1; }
-
}
done;
View
2 t/01_vms.t
@@ -11,8 +11,6 @@ if $*OS !~~ 'VMS' {
else {
is File::Spec.curdir, '.', 'curdir is "."';
- is File::Spec.case-tolerant, 1, 'case-tolerant is 0';
-
}
done;
View
8 t/01_win32.t
@@ -263,7 +263,6 @@ is $win32.curdir, '.', 'curdir is "."';
is $win32.devnull, 'nul', 'devnull is nul';
is $win32.rootdir, '\\', 'rootdir is "\\"';
is $win32.updir, '..', 'updir is ".."';
-is $win32.default-case-tolerant, True, 'default-case-tolerant is True';
if $*OS !~~ any(<MSWin32 NetWare symbian>) {
@@ -273,12 +272,7 @@ else {
# double check a couple of things to see if File::Spec loaded correctly
is File::Spec.devnull, 'nul', 'devnull is nul';
is File::Spec.rootdir, '\\', 'rootdir is "\\"';
- #tmpdir
- #no-upwards
- is File::Spec.case-tolerant, 1, 'case-tolerant is 1';
-
- #join
-
+ ok {.IO.d && .IO.w}.(File::Spec.tmpdir), "tmpdir: {File::Spec.tmpdir} is a writable directory";
}
done;

0 comments on commit 95ad174

Please sign in to comment.