This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Improve the BEGIN-time setup code for File::Find's tests.
authorNicholas Clark <nick@ccl4.org>
Wed, 3 Jul 2013 08:41:29 +0000 (10:41 +0200)
committerNicholas Clark <nick@ccl4.org>
Fri, 5 Jul 2013 18:26:25 +0000 (20:26 +0200)
In find.t merge the two BEGIN blocks and eliminate the redundant
C<use File::Spec;>
In both, don't attempt to change directory to t/ (which will be unhelpful
once File::Find is moved to ext/)
Only make paths in @INC absolute if $ENV{PERL_CORE} is set (which will ease
making File::Find dual-life, if we want to this.)

lib/File/Find/t/find.t
lib/File/Find/t/taint.t

index 96a1000..53ba648 100644 (file)
@@ -11,11 +11,21 @@ my ($warn_msg, @files, $file);
 
 BEGIN {
     require File::Spec;
-    chdir 't' if -d 't';
-    # May be doing dynamic loading while @INC is all relative
-    unshift @INC => File::Spec->rel2abs('../lib');
-
-    $SIG{'__WARN__'} = sub { $warn_msg = $_[0]; warn "# $_[0]"; }
+    if ($ENV{PERL_CORE}) {
+        # May be doing dynamic loading while @INC is all relative
+        @INC = map { $_ = File::Spec->rel2abs($_); /(.*)/; $1 } @INC;
+    }
+    $SIG{'__WARN__'} = sub { $warn_msg = $_[0]; warn "# $_[0]"; };
+
+    if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS') {
+        # This is a hack - at present File::Find does not produce native names
+        # on Win32 or VMS, so force File::Spec to use Unix names.
+        # must be set *before* importing File::Find
+        require File::Spec::Unix;
+        @File::Spec::ISA = 'File::Spec::Unix';
+    }
+    require File::Find;
+    import File::Find;
 }
 
 my $test_count = 98;
@@ -45,21 +55,6 @@ my $orig_dir = cwd();
 #     };
 # }
 
-
-BEGIN {
-    use File::Spec;
-    if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS')
-     {
-      # This is a hack - at present File::Find does not produce native names on 
-      # Win32 or VMS, so force File::Spec to use Unix names.
-      # must be set *before* importing File::Find
-      require File::Spec::Unix;
-      @File::Spec::ISA = 'File::Spec::Unix';
-     }
-     require File::Find;
-     import File::Find;
-}
-
 cleanup();
 
 $::count_commonsense = 0;
index 954c678..d6fb256 100644 (file)
@@ -16,11 +16,10 @@ my ($cwd, $cwd_untainted);
 
 BEGIN {
     require File::Spec;
-    chdir 't' if -d 't';
-    # May be doing dynamic loading while @INC is all relative
-    my $lib = File::Spec->rel2abs('../lib');
-    $lib = $1 if $lib =~ m/(.*)/;
-    unshift @INC => $lib;
+    if ($ENV{PERL_CORE}) {
+        # May be doing dynamic loading while @INC is all relative
+        @INC = map { $_ = File::Spec->rel2abs($_); /(.*)/; $1 } @INC;
+    }
 }
 
 use Config;