From: Peter Rabbitson Date: Wed, 3 Aug 2011 20:19:27 +0000 (+0200) Subject: Try harder to detect tie(%^H) clashes X-Git-Tag: 0.21~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1cd61d2e1a0205727210aee27a70000e74b9f417;hp=c8e3fb7eb609ee23dbf5034577e44d374b409b77;p=p5sagit%2Fnamespace-clean.git Try harder to detect tie(%^H) clashes --- diff --git a/lib/namespace/clean.pm b/lib/namespace/clean.pm index ae147cc..ab08964 100644 --- a/lib/namespace/clean.pm +++ b/lib/namespace/clean.pm @@ -12,9 +12,13 @@ our $VERSION = '0.20_01'; $STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE'; BEGIN { + + # when changing also change in Makefile.PL + my $b_h_eos_req = '0.07'; + if (eval { require B::Hooks::EndOfScope; - B::Hooks::EndOfScope->VERSION('0.07'); # when changing also change in Makefile.PL + B::Hooks::EndOfScope->VERSION($b_h_eos_req); 1 } ) { B::Hooks::EndOfScope->import('on_scope_end'); @@ -22,6 +26,14 @@ BEGIN { else { eval <<'PP' or die $@; + use Tie::Hash (); + + { + package namespace::clean::_TieHintHash; + + use base 'Tie::ExtraHash'; + } + { package namespace::clean::_ScopeGuard; @@ -30,16 +42,36 @@ BEGIN { sub DESTROY { $_[0]->[0]->() } } - use Tie::Hash (); sub on_scope_end (&) { $^H |= 0x020000; if( my $stack = tied( %^H ) ) { + if ( (my $c = ref $stack) ne 'namespace::clean::_TieHintHash') { + die <arm(shift); } else { - tie( %^H, 'Tie::ExtraHash', namespace::clean::_ScopeGuard->arm(shift) ); + tie( %^H, 'namespace::clean::_TieHintHash', namespace::clean::_ScopeGuard->arm(shift) ); } }