=head1 VERSION
-This document describes version 2.00_01 of File::Path, released
-2007-xx-xx.
+This document describes version 2.00_02 of File::Path, released
+2007-06-06.
=head1 SYNOPSIS
use Exporter ();
use vars qw($VERSION @ISA @EXPORT);
-$VERSION = '2.00_01';
+$VERSION = '2.00_02';
@ISA = qw(Exporter);
@EXPORT = qw(mkpath rmtree);
sub mkpath {
my $new_style = (
- ref($_[0]) eq 'ARRAY'
+ UNIVERSAL::isa($_[0],'ARRAY')
or (@_ == 2 and $_[1] =~ /\A\d+\z/)
or (@_ == 3 and $_[1] =~ /\A\d+\z/ and $_[2] =~ /\A\d+\z/)
) ? 0 : 1;
my $paths;
if ($new_style) {
- if (ref $_[-1] eq 'HASH') {
+ if (@_ > 0 and UNIVERSAL::isa($_[-1], 'HASH')) {
$arg = pop @_;
exists $arg->{mask} and $arg->{mode} = delete $arg->{mask};
$arg->{mode} = 0777 unless exists $arg->{mode};
else {
my ($verbose, $mode);
($paths, $verbose, $mode) = @_;
- $paths = [$paths] unless ref($paths) eq 'ARRAY';
+ $paths = [$paths] unless UNIVERSAL::isa($paths,'ARRAY');
$arg->{verbose} = defined $verbose ? $verbose : 0;
$arg->{mode} = defined $mode ? $mode : 0777;
}
sub rmtree {
my $new_style = (
- ref($_[0]) eq 'ARRAY'
+ UNIVERSAL::isa($_[0],'ARRAY')
or (@_ == 2 and $_[1] =~ /\A\d+\z/)
or (@_ == 3 and $_[1] =~ /\A\d+\z/ and $_[2] =~ /\A\d+\z/)
) ? 0 : 1;
my $paths;
if ($new_style) {
- if (ref $_[-1] eq 'HASH') {
+ if (@_ > 0 and UNIVERSAL::isa($_[-1],'HASH')) {
$arg = pop @_;
${$arg->{error}} = [] if exists $arg->{error};
${$arg->{result}} = [] if exists $arg->{result};
else {
my ($verbose, $safe);
($paths, $verbose, $safe) = @_;
- $paths = [$paths] unless ref($paths) eq 'ARRAY';
$arg->{verbose} = defined $verbose ? $verbose : 0;
$arg->{safe} = defined $safe ? $safe : 0;
- }
- if (@$paths < 1) {
+ if (defined($paths) and length($paths)) {
+ $paths = [$paths] unless UNIVERSAL::isa($paths,'ARRAY');
+ }
+ else {
if ($arg->{error}) {
push @{${$arg->{error}}}, {'' => "No root path(s) specified"};
}
else {
- $arg->{verbose} and _carp ("No root path(s) specified\n");
+ _carp ("No root path(s) specified\n");
}
return 0;
}
+ }
return _rmtree($arg, $paths);
}
use strict;
-use Test::More tests => 72;
+use Test::More tests => 71;
BEGIN {
use_ok('File::Path');
my $count = rmtree({error => \$error});
is( $count, 0, 'rmtree of nothing, count of zero' );
-is( scalar(@$error), 1, 'one diagnostic captureed' );
-eval { ($file, $message) = each %{$error->[0]} }; # too early to die, just in case
-is( $@, '', 'decoded diagnostic' );
-is( $file, '', 'general diagnostic' );
-is( $message, 'No root path(s) specified', 'expected diagnostic received' );
+is( scalar(@$error), 0, 'no diagnostic captured' );
@created = mkpath($tmp_base, 0);
is(scalar(@created), 0, "skipped making existing directories (old style 1)")
is( $file, $dir, 'symlink reported in error' );
}
+{
+ $dir = catdir($tmp_base, 'Z');
+ @created = mkpath($dir);
+ is(scalar(@created), 1, "create a Z directory");
+
+ local @ARGV = ($dir);
+ rmtree( [grep -e $_, @ARGV], 0, 0 );
+ ok(!-e $dir, "blow it away via \@ARGV");
+}
+
SKIP: {
skip 'Test::Output not available', 10
unless $has_Test_Output;
+
SKIP: {
$dir = catdir('EXTRA', '3');
skip "extra scenarios not set up, see eg/setup-extra-tests", 2
$dir2 = catdir($base,'B');
stderr_like(
- sub { rmtree( [], 1 ) },
+ sub { rmtree( undef, 1 ) },
qr/\ANo root path\(s\) specified\b/,
"rmtree of nothing carps sensibly"
);