summaryrefslogtreecommitdiff
path: root/lib/Cwd.pm
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2003-12-27 17:20:23 +0000
committerNicholas Clark <nick@ccl4.org>2003-12-27 17:20:23 +0000
commita9939470558f41efaae5bf23fe0c76fc3a2402ea (patch)
tree4fc5684b35fbe07416cd3461b9f483b6ca2a79f5 /lib/Cwd.pm
parent028f8eaac9a8e1c5eecaca563e816ed1d443dc17 (diff)
downloadperl-a9939470558f41efaae5bf23fe0c76fc3a2402ea.tar.gz
Assimilate Cwd 2.12 from CPAN. Cwd wasn't in Maintainers, so change
21646 was only applied to core (must punt this back and thereby unfork) Need to fix test boilerplate properly for PERL_CORE p4raw-id: //depot/perl@21972
Diffstat (limited to 'lib/Cwd.pm')
-rw-r--r--lib/Cwd.pm66
1 files changed, 30 insertions, 36 deletions
diff --git a/lib/Cwd.pm b/lib/Cwd.pm
index 984375fb0f..51ca5b6f54 100644
--- a/lib/Cwd.pm
+++ b/lib/Cwd.pm
@@ -1,5 +1,4 @@
package Cwd;
-use 5.006;
=head1 NAME
@@ -137,12 +136,14 @@ L<File::chdir>
=cut
use strict;
+use Exporter;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
-our $VERSION = '2.08';
+$VERSION = '2.12';
-use base qw/ Exporter /;
-our @EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
-our @EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath);
+@ISA = qw/ Exporter /;
+@EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
+@EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath);
# sys_cwd may keep the builtin command
@@ -150,16 +151,19 @@ our @EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath);
# there is no sense to process the rest of the file.
# The best choice may be to have this in BEGIN, but how to return from BEGIN?
-if ($^O eq 'os2' && defined &sys_cwd && defined &sys_abspath) {
+if ($^O eq 'os2') {
local $^W = 0;
- *cwd = \&sys_cwd;
- *getcwd = \&cwd;
- *fastgetcwd = \&cwd;
- *fastcwd = \&cwd;
- *abs_path = \&sys_abspath;
- *fast_abs_path = \&abs_path;
- *realpath = \&abs_path;
- *fast_realpath = \&abs_path;
+
+ *cwd = defined &sys_cwd ? \&sys_cwd : \&_os2_cwd;
+ *getcwd = \&cwd;
+ *fastgetcwd = \&cwd;
+ *fastcwd = \&cwd;
+
+ *fast_abs_path = \&sys_abspath if defined &sys_abspath;
+ *abs_path = \&fast_abs_path;
+ *realpath = \&fast_abs_path;
+ *fast_realpath = \&fast_abs_path;
+
return 1;
}
@@ -191,6 +195,10 @@ unless ($pwd_cmd) {
}
}
+# Lazy-load Carp
+sub _carp { require Carp; Carp::carp(@_) }
+sub _croak { require Carp; Carp::croak(@_) }
+
# The 'natural and safe form' for UNIX (pwd may be setuid root)
sub _backtick_pwd {
local @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};
@@ -358,8 +366,7 @@ sub _perl_abs_path
unless (@cst = stat( $start ))
{
- require Carp;
- Carp::carp ("stat($start): $!");
+ _carp("stat($start): $!");
return '';
}
$cwd = '';
@@ -371,14 +378,12 @@ sub _perl_abs_path
local *PARENT;
unless (opendir(PARENT, $dotdots))
{
- require Carp;
- Carp::carp ("opendir($dotdots): $!");
+ _carp("opendir($dotdots): $!");
return '';
}
unless (@cst = stat($dotdots))
{
- require Carp;
- Carp::carp ("stat($dotdots): $!");
+ _carp("stat($dotdots): $!");
closedir(PARENT);
return '';
}
@@ -392,8 +397,7 @@ sub _perl_abs_path
{
unless (defined ($dir = readdir(PARENT)))
{
- require Carp;
- Carp::carp ("readdir($dotdots): $!");
+ _carp("readdir($dotdots): $!");
closedir(PARENT);
return '';
}
@@ -426,13 +430,11 @@ sub fast_abs_path {
($cwd) = $cwd =~ /(.*)/;
if (!CORE::chdir($path)) {
- require Carp;
- Carp::croak ("Cannot chdir to $path: $!");
+ _croak("Cannot chdir to $path: $!");
}
my $realpath = getcwd();
if (! ((-d $cwd) && (CORE::chdir($cwd)))) {
- require Carp;
- Carp::croak ("Cannot chdir back to $cwd: $!");
+ _croak("Cannot chdir back to $cwd: $!");
}
$realpath;
}
@@ -461,8 +463,7 @@ sub _vms_abs_path {
my $path = VMS::Filespec::pathify($_[0]);
if (! defined $path)
{
- require Carp;
- Carp::croak("Invalid path name $_[0]")
+ _croak("Invalid path name $_[0]")
}
return VMS::Filespec::rmsexpand($path);
}
@@ -545,14 +546,6 @@ sub _epoc_cwd {
*abs_path = \&fast_abs_path;
*realpath = \&fast_abs_path;
}
- elsif ($^O eq 'os2') {
- # sys_cwd may keep the builtin command
- *cwd = defined &sys_cwd ? \&sys_cwd : \&_os2_cwd;
- *getcwd = \&cwd;
- *fastgetcwd = \&cwd;
- *fastcwd = \&cwd;
- *abs_path = \&fast_abs_path;
- }
elsif ($^O eq 'dos') {
*cwd = \&_dos_cwd;
*getcwd = \&_dos_cwd;
@@ -573,6 +566,7 @@ sub _epoc_cwd {
*fastgetcwd = \&cwd;
*fastcwd = \&cwd;
*abs_path = \&fast_abs_path;
+ *realpath = \&abs_path;
}
elsif ($^O eq 'epoc') {
*cwd = \&_epoc_cwd;