From: Florian Ragwitz Date: Sat, 11 Jul 2009 15:31:30 +0000 (+0200) Subject: Fix restoring of non-code symbols when cleaning. X-Git-Tag: 0.12~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=61c4bce7e7b6585613a8b01119cfe88ede232bca;p=p5sagit%2Fnamespace-clean.git Fix restoring of non-code symbols when cleaning. Curtesy of Ben Morrows. --- diff --git a/lib/namespace/clean.pm b/lib/namespace/clean.pm index 93ecb9f..1f370fe 100644 --- a/lib/namespace/clean.pm +++ b/lib/namespace/clean.pm @@ -166,15 +166,19 @@ my $RemoveSubs = sub { next SYMBOL if $store->{exclude}{ $f }; no strict 'refs'; + local *__tmp; + # keep original value to restore non-code slots { no warnings 'uninitialized'; # fix possible unimports - local *__tmp = *{ ${ "${cleanee}::" }{ $f } }; + *__tmp = *{ ${ "${cleanee}::" }{ $f } }; delete ${ "${cleanee}::" }{ $f }; } SLOT: - # restore non-code slots to symbol - for my $t (qw( SCALAR ARRAY HASH IO FORMAT )) { + # restore non-code slots to symbol. + # omit the FORMAT slot, since perl erroneously puts it into the + # SCALAR slot of the new glob. + for my $t (qw( SCALAR ARRAY HASH IO )) { next SLOT unless defined *__tmp{ $t }; *{ "${cleanee}::$f" } = *__tmp{ $t }; } @@ -312,6 +316,12 @@ sub get_functions { }; } +=head1 BUGS + +C will clobber any formats that have the same name as +a deleted sub. This is due to a bug in perl that makes it impossible to +re-assign the FORMAT ref into a new glob. + =head1 IMPLEMENTATION DETAILS This module works through the effect that a