File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,13 +58,23 @@ sub _error {
5858 }
5959}
6060
61+ sub __is_arg {
62+ my ($arg ) = @_ ;
63+ # If client code blessed an array ref to HASH, this will not work
64+ # properly. We could have done $arg->isa() wrapped in eval, but
65+ # that would be expensive. This implementation should suffice.
66+ # We could have also used Scalar::Util:blessed, but we choose not
67+ # to add this dependency
68+ return (ref $arg eq ' HASH' );
69+ }
70+
6171sub make_path {
62- push @_ , {} unless @_ and UNIVERSAL::isa ($_ [-1], ' HASH ' );
72+ push @_ , {} unless @_ and __is_arg ($_ [-1]);
6373 goto &mkpath;
6474}
6575
6676sub mkpath {
67- my $old_style = !(@_ and UNIVERSAL::isa ($_ [-1], ' HASH ' ));
77+ my $old_style = !(@_ and __is_arg ($_ [-1]));
6878
6979 my $arg ;
7080 my $paths ;
@@ -162,7 +172,7 @@ sub _mkpath {
162172}
163173
164174sub remove_tree {
165- push @_ , {} unless @_ and UNIVERSAL::isa ($_ [-1], ' HASH ' );
175+ push @_ , {} unless @_ and __is_arg ($_ [-1]);
166176 goto &rmtree;
167177}
168178
@@ -185,7 +195,7 @@ sub _is_subdir {
185195}
186196
187197sub rmtree {
188- my $old_style = !(@_ and UNIVERSAL::isa ($_ [-1], ' HASH ' ));
198+ my $old_style = !(@_ and __is_arg ($_ [-1]));
189199
190200 my $arg ;
191201 my $paths ;
Original file line number Diff line number Diff line change 1+ use strict;
2+ use warnings;
3+ use Test::More;
4+
5+ eval " require Path::Class" ;
6+ plan skip_all => " Test::Pod 1.00 required for testing POD" if $@ ;
7+
8+ use File::Path qw( remove_tree make_path) ;
9+ Path::Class-> import ;
10+
11+ my $name = ' test' ;
12+ my $dir = dir($name );
13+
14+ sub test {
15+ my ($dir , $pass_arg ) = @_ ;
16+
17+ my $args = [ $dir , ($pass_arg ? {} : ()) ];
18+ my $desc = sprintf (
19+ ' dir isa %s, second arg is %s' ,
20+ (ref ($dir ) || ' string' ),
21+ ($pass_arg ? ' {}' : ' not passed' )
22+ );
23+
24+ return ($args , $desc );
25+ }
26+
27+ for my $mk_dir ($name , dir($name )) {
28+ for my $mk_pass_arg (0, 1) {
29+
30+ for my $rm_dir ($name , dir($name )) {
31+ for my $rm_pass_arg (0, 1) {
32+ remove_tree($name ) if -e $name ;
33+
34+ my ($mk_args , $mk_desc ) = test($mk_dir , $mk_pass_arg );
35+ make_path(@$mk_args );
36+
37+ if (ok( -d $dir , " we made $dir ($mk_desc )" )) {
38+ my ($rm_args , $rm_desc ) = test($rm_dir , $rm_pass_arg );
39+ remove_tree(@$rm_args );
40+ ok( ! -d $dir , " ...then we removed $dir ($rm_desc )" );
41+ } else {
42+ fail(" ...can't remove it if we didn't create it" );
43+ }
44+ }
45+ }
46+ }
47+ }
48+
49+ done_testing;
You can’t perform that action at this time.
0 commit comments