Unload a module, actually unload a package, is hard. You need to scan all the package to undef all the data types (SCALAR, ARRAY, HASH, GLOB) and close the IO too. Also you need to overload the subs with a DUMMY sub. But when you "undef" a package you can't use that package name again, or you will have a core dump easy in the future codes!

For XS code you can use some unload_file() method (I don't remember now the method name) of Dynaloader, but this only work for Linux and isn't stable. Soo, I have skiped that!

But the problem is that when you load a code, or module, it generally set new symbols in the other packages (in other symbols tables). Soo, I think that the best way is to create a Safe compartment and load your code there.

But to make your code load modules inside a Safe compartment is hard, since you need to implement by hand the output, %INC and @INC handlers. Soo, I have created Safe::World, that implements all the World and already have the CLEAN() resource that you are looking. It also has other cool things, but I will let them to be read in the POD.

Get it at: http://search.cpan.org/~gmpassos/Safe-World-0.03/

I will been releasing the 0.04 version in some days, soo be updated...

Graciliano M. P.
"Creativity is the expression of the liberty".


In reply to Re: Unloading a module completely by gmpassos
in thread Unloading a module completely by holo

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.