Skip to content
Browse files

splitpath done

  • Loading branch information...
1 parent 5093a1c commit 57cf40116785ec0368ed8dfea3e5e60f7880ddd0 @FROGGS committed Sep 14, 2012
Showing with 48 additions and 23 deletions.
  1. +1 −1 README.md
  2. +18 −18 lib/File/Spec.pm
  3. +13 −2 lib/File/Spec/Unix.pm
  4. +16 −2 t/01_unix.t
View
2 README.md
@@ -22,7 +22,7 @@ Methods (current state):
file_name_is_absolute done
path done
join done
- splitpath
+ splitpath done
splitdir
catpath
abs2rel
View
36 lib/File/Spec.pm
@@ -18,24 +18,24 @@ my $module = "File::Spec::" ~ ($module{$*OS} // 'Unix');
require $module;
class File::Spec {
- method canonpath( $path ) { ::($module).canonpath( $path ) }
- method catdir( *@parts ) { ::($module).catdir( @parts ) }
- method catfile( *@parts ) { ::($module).catfile( @parts ) }
- method curdir { ::($module).curdir() }
- method devnull { ::($module).devnull() }
- method rootdir { ::($module).rootdir() }
- method tmpdir { ::($module).tmpdir() }
- method updir { ::($module).updir() }
- method no_upwards( *@paths ) { ::($module).no_upwards( @paths ) }
- method case_tolerant { ::($module).case_tolerant() }
- method file_name_is_absolute( $file ) { ::($module).file_name_is_absolute( $file ) }
- method path { ::($module).path() }
- method join( *@parts ) { ::($module).join( @parts ) }
- method splitpath { ::($module).splitpath() }
- method splitdir { ::($module).splitdir() }
- method catpath { ::($module).catpath() }
- method abs2rel { ::($module).abs2rel() }
- method rel2abs { ::($module).rel2abs() }
+ method canonpath( $path ) { ::($module).canonpath( $path ) }
+ method catdir( *@parts ) { ::($module).catdir( @parts ) }
+ method catfile( *@parts ) { ::($module).catfile( @parts ) }
+ method curdir { ::($module).curdir() }
+ method devnull { ::($module).devnull() }
+ method rootdir { ::($module).rootdir() }
+ method tmpdir { ::($module).tmpdir() }
+ method updir { ::($module).updir() }
+ method no_upwards( *@paths ) { ::($module).no_upwards( @paths ) }
+ method case_tolerant { ::($module).case_tolerant() }
+ method file_name_is_absolute( $file ) { ::($module).file_name_is_absolute( $file ) }
+ method path { ::($module).path() }
+ method join( *@parts ) { ::($module).join( @parts ) }
+ method splitpath( $path, $no_file = 0 ) { ::($module).splitpath( $path, $no_file ) }
+ method splitdir { ::($module).splitdir() }
+ method catpath { ::($module).catpath() }
+ method abs2rel { ::($module).abs2rel() }
+ method rel2abs { ::($module).rel2abs() }
}
1;
View
15 lib/File/Spec/Unix.pm
@@ -88,8 +88,19 @@ class File::Spec::Unix {
self.catfile( @parts )
}
- method splitpath {
-
+ method splitpath( $path, $nofile ) {
+ my ( $volume, $directory, $file ) = ( '', '', '' );
+
+ if $nofile {
+ $directory = $path;
+ }
+ else {
+ $path ~~ m/^ ( [ .* \/ [ \.\.?$ ]? ]? ) (<-[\/]>*) /;
+ $directory = $0;
+ $file = $1;
+ }
+
+ return ( $volume, $directory, $file );
}
method splitdir {
View
18 t/01_unix.t
@@ -3,7 +3,7 @@ use lib 'lib';
use Test;
use File::Spec;
-plan 37;
+plan 46;
if $*OS ~~ any(<MacOS MSWin32 os2 VMS epoc NetWare symbian dos cygwin>) {
skip_rest 'this is not Unix\'ish'
@@ -68,7 +68,21 @@ else {
is File::Spec.join('c'), 'c', "join: 'c' -> 'c'";
is File::Spec.join('./c'), 'c', "join: './c' -> 'c'";
- #splitpath
+ my %splitpath = (
+ 'file' => ('', '', 'file'),
+ '/d1/d2/d3/' => ('', '/d1/d2/d3/', ''),
+ 'd1/d2/d3/' => ('', 'd1/d2/d3/', ''),
+ '/d1/d2/d3/.' => ('', '/d1/d2/d3/.', ''),
+ '/d1/d2/d3/..' => ('', '/d1/d2/d3/..', ''),
+ '/d1/d2/d3/.file' => ('', '/d1/d2/d3/', '.file'),
+ 'd1/d2/d3/file' => ('', 'd1/d2/d3/', 'file'),
+ '/../../d1/' => ('', '/../../d1/', ''),
+ '/././d1/' => ('', '/././d1/', ''),
+ );
+ for %splitpath.kv -> $get, $want {
+ is File::Spec.splitpath( $get ), $want, "splitpath: '$get' -> '$want'";
+ }
+
#splitdir
#catpath
#abs2rel

0 comments on commit 57cf401

Please sign in to comment.
Something went wrong with that request. Please try again.