Fix careless handling of the hinthash in PP mode (RT#73402)
[p5sagit/namespace-clean.git] / lib / namespace / clean.pm
index 84d203e..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;
     }
   }