Skip Menu |

This queue is for tickets about the PathTools CPAN distribution.

Report information
The Basics
Id: 22155
Status: rejected
Priority: 0/
Queue: PathTools

People
Owner: Nobody in particular
Requestors: hirose31 [...] gmail.com
Cc:
AdminCc:

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



Subject: [PATCH] expand tilde(~) to home directory
I modified File::Spec::Unix#rel2abs to add feature expanding tilde(~) to home directory. $ perl -MFile::Spec \ -e 'print File::Spec->rel2abs($_).qq{\n} for @ARGV' \ ~/file ~root/file /home/hirose31/file /root/file Would you like to apply my patch to main trunk?
Subject: PathTools-3.23_expand-tilde.patch
Index: lib/File/Spec/Unix.pm =================================================================== --- lib/File/Spec/Unix.pm (.../tags/3.23/trunk) (revision 9) +++ lib/File/Spec/Unix.pm (.../trunk) (revision 9) @@ -5,6 +5,8 @@ $VERSION = '1.5'; +use File::HomeDir; + =head1 NAME File::Spec::Unix - File::Spec for Unix, base for other File::Spec modules @@ -439,7 +441,12 @@ # Clean up $path if ( ! $self->file_name_is_absolute( $path ) ) { # Figure out the effective $base and clean it up. - if ( !defined( $base ) || $base eq '' ) { + my $re_tilde = qr{^~([^/]+)?}; + if ($path =~ m{$re_tilde} + && eval { $base = File::HomeDir->home( $1 || () ) }) { + $path =~ s{$re_tilde}{}; + } + elsif ( !defined( $base ) || $base eq '' ) { $base = $self->_cwd(); } elsif ( ! $self->file_name_is_absolute( $base ) ) { Index: Build.PL =================================================================== --- Build.PL (.../tags/3.23/trunk) (revision 9) +++ Build.PL (.../trunk) (revision 9) @@ -73,6 +73,7 @@ requires => { 'Carp' => 0, 'File::Basename' => 0, + 'File::HomeDir' => 0, }, build_requires => { 'File::Path' => 0,
From: RGARCIA [...] cpan.org
On Tue Oct 17 23:56:44 2006, HIROSE wrote: Show quoted text
> I modified File::Spec::Unix#rel2abs to add feature expanding tilde(~) to > home directory. > > $ perl -MFile::Spec \ > -e 'print File::Spec->rel2abs($_).qq{\n} for @ARGV' \ > ~/file ~root/file > /home/hirose31/file > /root/file > > Would you like to apply my patch to main trunk?
That feature is more appropriate to globbing functions; I don't think that File::Spec is an appropriate place for that. Tilde expansion is already handled by perl $ perl -wle 'print <~/foo>' /home/rafael/foo
HIROSE wrote: Show quoted text
> I modified File::Spec::Unix#rel2abs to add feature expanding > tilde(~) to home directory.
As Rafael just showed, you can do this with glob(), and if you want to do this in a more portable way, see File::HomeDir ยป http://search.cpan.org/dist/File-HomeDir/ -- Close the world, txEn eht nepO.