Permalink
Browse files

catfile done

  • Loading branch information...
1 parent 413eaec commit 7bd66b3b9cf686bc19bc2a5ce82a75a5cf397810 @FROGGS committed Sep 14, 2012
Showing with 15 additions and 6 deletions.
  1. +1 −1 README.md
  2. +1 −1 lib/File/Spec.pm
  3. +6 −2 lib/File/Spec/Unix.pm
  4. +7 −2 t/01_unix.t
View
@@ -11,7 +11,7 @@ Methods (current state):
Unix Mac OS2 Win32 VMS
canonpath done
catdir done
- catfile
+ catfile done
curdir done done done
devnull done done done
rootdir done done
View
@@ -20,7 +20,7 @@ require $module;
class File::Spec {
method canonpath( $path ) { ::($module).canonpath( $path ) }
method catdir( *@parts ) { ::($module).catdir( @parts ) }
- method catfile { ::($module).catfile() }
+ method catfile( *@parts ) { ::($module).catfile( @parts ) }
method curdir { ::($module).curdir() }
method devnull { ::($module).devnull() }
method rootdir { ::($module).rootdir() }
View
@@ -29,8 +29,12 @@ class File::Spec::Unix {
method catdir( @parts ) { self.canonpath( (@parts, '').join('/') ) }
- method catfile {
-
+ method catfile( @parts is copy ) {
+ my $file = self.canonpath( @parts.pop );
+ return $file unless @parts.elems;
+ my $dir = self.catdir( @parts );
+ $dir ~= '/' unless $dir.substr(*-1) eq '/';
+ return $dir ~ $file;
}
method curdir {
View
@@ -3,7 +3,7 @@ use lib 'lib';
use Test;
use File::Spec;
-plan 14;
+plan 27;
if $*OS ~~ any(<MacOS MSWin32 os2 VMS epoc NetWare symbian dos cygwin>) {
skip_rest 'this is not Unix\'ish'
@@ -34,7 +34,12 @@ else {
is File::Spec.catdir( 'd1','d2','d3' ), 'd1/d2/d3', "catdir: ('d1','d2','d3') -> 'd1/d2/d3'";
is File::Spec.catdir( '/','d2/d3' ), '/d2/d3', "catdir: ('/','d2/d3') -> '/d2/d3'";
- #catfile
+ is File::Spec.catfile('a','b','c'), 'a/b/c', "catfile: ('a','b','c') -> 'a/b/c'";
+ is File::Spec.catfile('a','b','./c'), 'a/b/c', "catfile: ('a','b','./c') -> 'a/b/c'";
+ is File::Spec.catfile('./a','b','c'), 'a/b/c', "catfile: ('./a','b','c') -> 'a/b/c'";
+ is File::Spec.catfile('c'), 'c', "catfile: 'c' -> 'c'";
+ is File::Spec.catfile('./c'), 'c', "catfile: './c' -> 'c'";
+
is File::Spec.curdir, '.', 'curdir is "."';
is File::Spec.devnull, '/dev/null', 'devnull is /dev/null';
is File::Spec.rootdir, '/', 'rootdir is "/"';

0 comments on commit 7bd66b3

Please sign in to comment.