From: Olivier Mengué Date: Sun, 8 May 2011 13:54:27 +0000 (+0200) Subject: Mini $RemoveSubs refactoring: less loops, less concat X-Git-Tag: 0.21~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d64ad6f8cbc52ce415cf81ca0bb61a122bf008c8;p=p5sagit%2Fnamespace-clean.git Mini $RemoveSubs refactoring: less loops, less concat Small refactoring in $RemoveSubs in the cleanup of the GLOB entry: - grep for undefined symbols just once - less string concatenation --- diff --git a/lib/namespace/clean.pm b/lib/namespace/clean.pm index 6afa1d8..57d96cb 100644 --- a/lib/namespace/clean.pm +++ b/lib/namespace/clean.pm @@ -166,14 +166,15 @@ my $RemoveSubs = sub { } } - my ($scalar, $array, $hash, $io) = map { - $cleanee_stash->get_symbol($_ . $f) + my @symbols = map { + my $name = $_ . $f; + my $def = $cleanee_stash->get_symbol($name); + defined($def) ? [$name, $def] : () } '$', '@', '%', ''; + $cleanee_stash->remove_glob($f); - for my $var (['$', $scalar], ['@', $array], ['%', $hash], ['', $io]) { - next unless defined $var->[1]; - $cleanee_stash->add_symbol($var->[0] . $f, $var->[1]); - } + + $cleanee_stash->add_symbol(@$_) for @symbols; } };