Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement the hideous voodoo that makes this work

and fill the pod with reasons and examples.
  • Loading branch information...
commit d21b82295bf5139a0828771a666bd9a0403cce3b 1 parent 9c411b1
Randy Stauner authored
Showing with 45 additions and 1 deletion.
  1. +45 −1 lib/File/Spec/Native.pm
46 lib/File/Spec/Native.pm
View
@@ -3,12 +3,56 @@ use strict;
use warnings;
package File::Spec::Native;
-# ABSTRACT: undef
+# ABSTRACT: Use native OS implementation of File::Spec from a subclass
+
+use File::Spec (); #core
+our @ISA = qw(File::Spec);
+
+# TODO: import? -as => NATIVE
1;
+=for test_synopsis
+my ($win32_path, $file_path);
+
=head1 SYNOPSIS
+ # This serves little purpose on its own but can be useful in some situations
+
+ # For example:
+ use Path::Class 0.24;
+
+ # convert foreign file type into native type
+ # without having to know what the current OS is
+ foreign_file(Win32 => $win32_path)->as_foreign("Native");
+
+ # or to build a file-spec dynamically (possibly taking the type from input):
+ $type = get_requested_file_spec; # can return "Native"
+ foreign_file($type => $file_path);
+
+ # having $type be "Native" is an alternative to having to do:
+ my $file = $type ? foreign_file($type, $file_path) : file($file_path);
+
=head1 DESCRIPTION
+This module is a stupid hack to make the default L<File::Spec> behavior
+available from a subclass. This can be useful when using another module
+that expects a subclass of L<File::Spec> but you want to use
+the current, native OS format (automatically detected by L<File::Spec>).
+
+For example: L<Path::Class/as_foreign> (as of version 0.24)
+allows you to translate a L<Path::Class> object from one OS format to another.
+However, there is no way way to specify that you want to translate the path into
+the current, native OS format without guessing at what that format is
+(which may include peeking into C<@File::Spec::ISA>).
+
+This module C<@ISA> L<File::Spec>.
+
+=head1 SEE ALSO
+
+=for :list
+* L<File::Spec>
+* L<Path::Class>
+* L<https://rt.cpan.org/Ticket/Display.html?id=49721>
+
=cut
Please sign in to comment.
Something went wrong with that request. Please try again.