Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/namespace/clean.pm
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ my $RemoveSubs = sub {
my $store = shift;
my $cleanee_stash = Package::Stash->new($cleanee);
my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee");
my $cleanee_stash_name = $cleanee_stash->name;
my $deleted_stash_name = $deleted_stash->name;
my $cleanee_stash_namespace = $cleanee_stash->namespace;
SYMBOL:
for my $f (@_) {
my $variable = "&$f";
Expand All @@ -152,28 +155,29 @@ my $RemoveSubs = sub {

next SYMBOL unless $cleanee_stash->has_symbol($variable);

if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
if (ref(\$cleanee_stash_namespace->{$f}) eq 'GLOB') {
# convince the Perl debugger to work
# it assumes that sub_fullname($sub) can always be used to find the CV again
# since we are deleting the glob where the subroutine was originally
# defined, that assumption no longer holds, so we need to move it
# elsewhere and point the CV's name to the new glob.
my $sub = $cleanee_stash->get_symbol($variable);
if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
my $new_fq = $deleted_stash->name . "::$f";
if ( sub_fullname($sub) eq ($cleanee_stash_name . "::$f") ) {
my $new_fq = $deleted_stash_name . "::$f";
subname($new_fq, $sub);
$deleted_stash->add_symbol($variable, $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;
}
};

Expand Down