Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Path-Class CPAN distribution.

Maintainer(s)' notes

I prefer that bugs & patches are filed on GitHub rather than on RT: https://github.com/kenahoo/Path-Class/issues. Thanks.

Report information
The Basics
Id: 49721
Status: open
Priority: 0/
Queue: Path-Class

People
Owner: Nobody in particular
Requestors: norbi [...] nix.hu
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.17
Fixed in: (no value)



Subject: $entity->as_native implementation
It would be very nice if the File::Path::Dir and File::Path::File instances created via ->new_foreign() could be converted to instances working with the native semantics (currently they only can be converted to different foreign instances).
Subject: Path-Class-as_native.diff
Index: t/02-foreign.t =================================================================== --- t/02-foreign.t (revision 193) +++ t/02-foreign.t (working copy) @@ -1,6 +1,6 @@ use Test; use strict; -BEGIN { plan tests => 28 }; #30, todo => [29,30] }; +BEGIN { plan tests => 31 }; #33, todo => [32,33] }; use Path::Class qw(file dir foreign_file foreign_dir); ok(1); @@ -11,6 +11,7 @@ ok $file->as_foreign('Win32'), 'dir\foo.txt'; ok $file->as_foreign('Mac'), ':dir:foo.txt'; ok $file->as_foreign('OS2'), 'dir/foo.txt'; +ok $file->as_native, Path::Class::File->new('dir', 'foo.txt'); if ($^O eq 'VMS') { ok $file->as_foreign('VMS'), '[.dir]foo.txt'; @@ -22,6 +23,7 @@ ok $file, ':dir:foo.txt'; ok $file->as_foreign('Unix'), 'dir/foo.txt'; ok $file->dir, ':dir:'; +ok $file->as_native, Path::Class::File->new('dir', 'foo.txt'); my $dir = Path::Class::Dir->new_foreign('Unix', 'dir/subdir'); @@ -29,6 +31,7 @@ ok $dir->as_foreign('Win32'), 'dir\subdir'; ok $dir->as_foreign('Mac'), ':dir:subdir:'; ok $dir->as_foreign('OS2'), 'dir/subdir'; +ok $dir->as_native, Path::Class::Dir->new('dir', 'subdir'); if ($^O eq 'VMS') { ok $dir->as_foreign('VMS'), '[.dir.subdir]'; Index: lib/Path/Class/Entity.pm =================================================================== --- lib/Path/Class/Entity.pm (revision 193) +++ lib/Path/Class/Entity.pm (working copy) @@ -27,6 +27,8 @@ sub _spec_class { my ($class, $type) = @_; + return undef if $type eq 'NATIVE'; + die "Invalid system type '$type'" unless ($type) = $type =~ /^(\w+)$/; # Untaint my $spec = "File::Spec::$type"; eval "require $spec; 1" or die $@; @@ -80,6 +82,12 @@ return $self->new($self->_spec->abs2rel($self->stringify, @_)); } +sub as_native { + my $self = shift; + + return $self->as_foreign('NATIVE'); +} + sub stat { File::stat::stat("$_[0]") } sub lstat { File::stat::lstat("$_[0]") }
On Tue Sep 15 11:34:29 2009, norbi@nix.hu wrote: Show quoted text
> It would be very nice if the File::Path::Dir and File::Path::File > instances created via ->new_foreign() could be converted to instances > working with the native semantics (currently they only can be converted > to different foreign instances).
I, too, was looking for this, and was surprised that I couldn't do it. In my current implementation I think I can get away with this: $ff = foreign_file( $type => $file ); $path = file( $dir, $ff->dir->dir_list, $ff->basename ) Since I want to put the file in a temp directory I can discard the volume (if one exists). But it would be nice to have a method in the API.
I uploaded a module to work around this: http://beta.metacpan.org/module/File::Spec::Native If you install File::Spec::Native then you can specify foreign_file($type => $path)->as_foreign("Native") and since File::Spec::Native is no more than a subclass of File::Spec it uses whatever the native/current/detected OS is. It's a stupid hack, but it's handy in this case. Of course having the "->as_native()" method would be much more clear than "->as_foreign('Native')"...