use strict;
use vars qw( $STORAGE_VAR );
-use Sub::Name 0.04 qw(subname);
-use Sub::Identify 0.04 qw(sub_fullname);
use Package::Stash 0.22;
use B::Hooks::EndOfScope 0.07;
=cut
-my $RemoveSubs = sub {
+my $sub_utils_loaded;
+my $DebuggerRename = sub {
+ my ($f, $sub, $cleanee_stash, $deleted_stash) = @_;
+
+ if (! defined $sub_utils_loaded ) {
+ $sub_utils_loaded = do {
+ my $sn_ver = 0.04;
+ eval { require Sub::Name; Sub::Name->VERSION($sn_ver) }
+ or die "Sub::Name $sn_ver required when running under -d or equivalent: $@";
+
+ my $si_ver = 0.04;
+ eval { require Sub::Identify; Sub::Identify->VERSION($si_ver) }
+ or die "Sub::Identify $si_ver required when running under -d or equivalent: $@";
+ 1;
+ } ? 1 : 0;
+ }
+
+ if ( Sub::Identify::sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
+ my $new_fq = $deleted_stash->name . "::$f";
+ Sub::Name::subname($new_fq, $sub);
+ $deleted_stash->add_symbol("&$f", $sub);
+ }
+};
+
+my $RemoveSubs = sub {
my $cleanee = shift;
my $store = shift;
my $cleanee_stash = Package::Stash->new($cleanee);
- my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee");
+ my $deleted_stash;
+
SYMBOL:
for my $f (@_) {
- my $variable = "&$f";
+
# ignore already removed symbols
next SYMBOL if $store->{exclude}{ $f };
- next SYMBOL unless $cleanee_stash->has_symbol($variable);
+ my $sub = $cleanee_stash->get_symbol("&$f")
+ or next SYMBOL;
- if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
+ if ($^P and 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";
- subname($new_fq, $sub);
- $deleted_stash->add_symbol($variable, $sub);
- }
+ $DebuggerRename->(
+ $f,
+ $sub,
+ $cleanee_stash,
+ $deleted_stash ||= Package::Stash->new("namespace::clean::deleted::$cleanee"),
+ );
}
my @symbols = map {