Fix careless handling of the hinthash in PP mode (RT#73402)
[p5sagit/namespace-clean.git] / lib / namespace / clean.pm
index 5e23ab2..1e6d51a 100644 (file)
@@ -19,7 +19,7 @@ BEGIN {
   # when changing also change in Makefile.PL
   my $b_h_eos_req = '0.07';
 
-  if (eval {
+  if (! $ENV{NAMESPACE_CLEAN_USE_PP} and eval {
     require B::Hooks::EndOfScope;
     B::Hooks::EndOfScope->VERSION($b_h_eos_req);
     1
@@ -80,7 +80,10 @@ EOE
       push @$stack, namespace::clean::_ScopeGuard->arm(shift);
     }
     else {
+      my %old_contents = %^H;
+      %^H = ();
       tie( %^H, 'namespace::clean::_TieHintHash', namespace::clean::_ScopeGuard->arm(shift) );
+      $^H{$_} = $old_contents{$_} for keys %old_contents;
     }
   }
 
@@ -246,10 +249,13 @@ my $DebuggerFixup = sub {
   if (RENAME_SUB) {
     if (! defined $sub_utils_loaded ) {
       $sub_utils_loaded = do {
+
+        # when changing version also change in Makefile.PL
         my $sn_ver = 0.04;
         eval { require Sub::Name; Sub::Name->VERSION($sn_ver) }
           or die "Sub::Name $sn_ver required when running under -d or equivalent: $@";
 
+        # when changing version also change in Makefile.PL
         my $si_ver = 0.04;
         eval { require Sub::Identify; Sub::Identify->VERSION($si_ver) }
           or die "Sub::Identify $si_ver required when running under -d or equivalent: $@";