Doc patch by Thomas O Smailus :
[p5sagit/p5-mst-13.2.git] / lib / File / Path.pm
index f96dc06..793336e 100644 (file)
@@ -38,7 +38,8 @@ the numeric mode to use when creating the directories
 =back
 
 It returns a list of all directories (including intermediates, determined
-using the Unix '/' separator) created.
+using the Unix '/' separator) created.  In scalar context it returns
+the number of directories created.
 
 If a system error prevents a directory from being created, then the
 C<mkpath> function throws a fatal error with C<Carp::croak>. This error
@@ -81,8 +82,8 @@ than VMS is settled.  (defaults to FALSE)
 
 =back
 
-It returns the number of files successfully deleted.  Symlinks are
-simply deleted and not followed.
+It returns the number of files, directories and symlinks successfully
+deleted.  Symlinks are simply deleted and not followed.
 
 B<NOTE:> There are race conditions internal to the implementation of
 C<rmtree> making it unsafe to use on directory trees which may be
@@ -119,13 +120,12 @@ Charles Bailey <F<bailey@newman.upenn.edu>>
 =cut
 
 use 5.006;
-use Carp;
 use File::Basename ();
 use Exporter ();
 use strict;
 use warnings;
 
-our $VERSION = "1.07";
+our $VERSION = "1.08";
 our @ISA = qw( Exporter );
 our @EXPORT = qw( mkpath rmtree );
 
@@ -137,6 +137,16 @@ my $Is_MacOS = $^O eq 'MacOS';
 my $force_writeable = ($^O eq 'os2' || $^O eq 'dos' || $^O eq 'MSWin32' ||
                       $^O eq 'amigaos' || $^O eq 'MacOS' || $^O eq 'epoc');
 
+sub carp {
+    require Carp;
+    goto &Carp::carp;
+}
+
+sub croak {
+    require Carp;
+    goto &Carp::croak;
+}
+
 sub mkpath {
     my($paths, $verbose, $mode) = @_;
     # $paths   -- either a path string or ref to list of paths
@@ -152,9 +162,6 @@ sub mkpath {
        if ($Is_VMS) {
            next if $path eq '/';
            $path = VMS::Filespec::unixify($path);
-           if ($path =~ m:^(/[^/]+)/?\z:) {
-               $path = $1.'/000000';
-           }
        }
        next if -d $path;
        my $parent = File::Basename::dirname($path);
@@ -165,7 +172,7 @@ sub mkpath {
        unless (mkdir($path,$mode)) {
            my $e = $!;
            # allow for another process to have created it meanwhile
-           croak "mkdir $path: $e" unless -d $path;
+           $! = $e, croak ("mkdir $path: $e") unless -d $path;
        }
        push(@created, $path);
     }
@@ -183,7 +190,7 @@ sub rmtree {
       $roots = [$roots] unless ref $roots;
     }
     else {
-      carp "No root path(s) specified\n";
+      carp ("No root path(s) specified\n");
       return 0;
     }
 
@@ -203,7 +210,7 @@ sub rmtree {
            # to recurse in which case we are better than rm -rf for 
            # subtrees with strange permissions
            chmod($rp | 0700, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
-             or carp "Can't make directory $root read+writeable: $!"
+             or carp ("Can't make directory $root read+writeable: $!")
                unless $safe;
 
            if (opendir my $d, $root) {
@@ -217,7 +224,7 @@ sub rmtree {
                closedir $d;
            }
            else {
-               carp "Can't read $root: $!";
+               carp ("Can't read $root: $!");
                @files = ();
            }
 
@@ -237,14 +244,14 @@ sub rmtree {
                next;
            }
            chmod $rp | 0700, $root
-             or carp "Can't make directory $root writeable: $!"
+             or carp ("Can't make directory $root writeable: $!")
                if $force_writeable;
            print "rmdir $root\n" if $verbose;
            if (rmdir $root) {
                ++$count;
            }
            else {
-               carp "Can't remove directory $root: $!";
+               carp ("Can't remove directory $root: $!");
                chmod($rp, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
                    or carp("and can't restore permissions to "
                            . sprintf("0%o",$rp) . "\n");
@@ -259,13 +266,13 @@ sub rmtree {
                next;
            }
            chmod $rp | 0600, $root
-             or carp "Can't make file $root writeable: $!"
+             or carp ("Can't make file $root writeable: $!")
                if $force_writeable;
            print "unlink $root\n" if $verbose;
            # delete all versions under VMS
            for (;;) {
                unless (unlink $root) {
-                   carp "Can't unlink file $root: $!";
+                   carp ("Can't unlink file $root: $!");
                    if ($force_writeable) {
                        chmod $rp, $root
                            or carp("and can't restore permissions to "