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.


In reply to Re: Re: Deleting a package by sfink
in thread Deleting a package by sfink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.