in reply to Deleting a package

See. delete_package() from Symbol which does the necessary trickery to ensure a package is properly deleted.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Deleting a package
by sfink (Deacon) on Apr 27, 2004 at 17:02 UTC
    Excellent, that's exactly what I was looking for. Now I just need to figure out how to apply it properly, and what constraints I'll need to impose on the users.

    Update: in searching for caveats to Symbol::delete_package, I encountered Mark-Jason Dominus's scrub_package:

    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; } }
    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.

    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.