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,