Permalink
Browse files

another approach without roles nor handles

  • Loading branch information...
1 parent 29bcc72 commit 41591786934cd782e73d8c881d90da9531e94e80 @FROGGS committed Sep 14, 2012
Showing with 53 additions and 27 deletions.
  1. +31 −16 lib/File/Spec.pm
  2. +21 −5 lib/File/Spec/Mac.pm
  3. +1 −6 lib/File/Spec/Unix.pm
View
@@ -1,26 +1,41 @@
module File::Spec;
-BEGIN {
- my %module = (
- 'MacOS' => 'Mac',
- 'MSWin32' => 'Win32',
- 'os2' => 'OS2',
- 'VMS' => 'VMS',
- 'epoc' => 'Epoc',
- 'NetWare' => 'Win32', # Yes, File::Spec::Win32 works on NetWare.
- 'symbian' => 'Win32', # Yes, File::Spec::Win32 works on symbian.
- 'dos' => 'OS2', # Yes, File::Spec::OS2 works on DJGPP.
- 'cygwin' => 'Cygwin'
- );
+my %module = (
+ 'MacOS' => 'Mac',
+ 'MSWin32' => 'Win32',
+ 'os2' => 'OS2',
+ 'VMS' => 'VMS',
+ 'epoc' => 'Epoc',
+ 'NetWare' => 'Win32', # Yes, File::Spec::Win32 works on NetWare.
+ 'symbian' => 'Win32', # Yes, File::Spec::Win32 works on symbian.
+ 'dos' => 'OS2', # Yes, File::Spec::OS2 works on DJGPP.
+ 'cygwin' => 'Cygwin'
+);
- my $module = $module{$*OS} // 'Unix';
+my $module = "File::Spec::" ~ ($module{$*OS} // 'Unix');
- require "File::Spec::$module";
-};
+require $module;
class File::Spec {
- also does File::Spec::OS;
+ method canonpath { ::($module).canonpath() }
+ method catdir { ::($module).catdir() }
+ method catfile { ::($module).catfile() }
+ method curdir { ::($module).curdir() }
+ method devnull { ::($module).devnull() }
+ method rootdir { ::($module).rootdir() }
+ method tmpdir { ::($module).tmpdir() }
+ method updir { ::($module).updir() }
+ method no_upwards { ::($module).no_upwards() }
+ method case_tolerant { ::($module).case_tolerant() }
+ method file_name_is_absolute { ::($module).file_name_is_absolute() }
+ method path { ::($module).path() }
+ method join { ::($module).join() }
+ method splitpath { ::($module).splitpath() }
+ method splitdir { ::($module).splitdir() }
+ method catpath { ::($module).catpath() }
+ method abs2rel { ::($module).abs2rel() }
+ method rel2ab { ::($module).rel2ab() }
}
1;
View
@@ -1,22 +1,38 @@
module File::Spec::Mac;
-BEGIN require "File::Spec::Unix";
+my $module = "File::Spec::Unix";
+require $module;
-role File::Spec::OS {
- # use Unix as a base
- also does File::Spec::Unix;
+class File::Spec::Mac {
+ method canonpath { ::($module).canonpath() }
+ method catdir { ::($module).catdir() }
+ method catfile { ::($module).catfile() }
- # and add Mac specific stuff
method curdir {
':'
}
+ method devnull { ::($module).devnull() }
+ method rootdir { ::($module).rootdir() }
+
my $tmpdir;
method tmpdir {
return $tmpdir if $tmpdir.defined;
$tmpdir = self._tmpdir( %*ENV{'TMPDIR'} );
}
+
+ method updir { ::($module).updir() }
+ method no_upwards { ::($module).no_upwards() }
+ method case_tolerant { ::($module).case_tolerant() }
+ method file_name_is_absolute { ::($module).file_name_is_absolute() }
+ method path { ::($module).path() }
+ method join { ::($module).join() }
+ method splitpath { ::($module).splitpath() }
+ method splitdir { ::($module).splitdir() }
+ method catpath { ::($module).catpath() }
+ method abs2rel { ::($module).abs2rel() }
+ method rel2ab { ::($module).rel2ab() }
}
1;
@@ -1,8 +1,7 @@
module File::Spec::Unix;
-# we need that so File::Spec::Mac can use it
-role File::Spec::Unix {
+class File::Spec::Unix {
method curdir {
'.'
}
@@ -31,8 +30,4 @@ role File::Spec::Unix {
method updir { '..' }
}
-role File::Spec::OS {
- also does File::Spec::Unix;
-}
-
1;

0 comments on commit 4159178

Please sign in to comment.