in reply to Re: Deleting a package
in thread Deleting a package
Update: in searching for caveats to Symbol::delete_package, I encountered Mark-Jason Dominus's scrub_package:
This is very similar to what delete_package does, at least in 5.8.1, but both have the unfortunate side effect of also deleting any imported subroutine -- so if &mypackage::glort is aliased to &main::glort, then you won't be able to call main::glort() after deleting "mypackage". If you use the above commented out line (*$fullname = sub {}), you will avoid this issue.sub scrub_package { no strict 'refs'; my $pack = shift; die "Shouldn't delete main package" if $pack eq "" || $pack eq "main"; my $stash = *{$pack . '::'}{HASH}; my $name; foreach $name (keys %$stash) { my $fullname = $pack . '::' . $name; # Get rid of everything with that name. undef $$fullname; undef @$fullname; undef %$fullname; undef &$fullname; # or *$fullname = sub { } undef *$fullname; } }
Which says to me: "here be dragons". But I guess I knew that already. I hope they're friendly ones.
Update2: But in actually testing the above problem, it does not appear to happen with 5.8.1's Symbol::delete_package (version 1.04). So never mind. It's only a problem with the above code. Life is good.
|
|---|