Eric J. Roode on Fri, 27 Jun 2003 17:32:39 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Unload a module?


On Fri, Jun 27, 2003 at 08:39:15AM -0400, mjd-perl-pm@plover.com wrote:
 
> > So I thought I would delete all the subroutines and data by doing
> > %{$module.'::'} = ().  That seemed to work,
> 
> You ar eon thin ice here.  If I were you, I would use the standard
> 'Symbol' module, which has a delete_package function in it.  Then you
> would have someone else to blame if it did not work.

That's a good idea.  I hadn't known about that module (well, I think I
heard about it long ago, but had completely forgotten).  I will look
into that -- it's probably the right way to go.


I did try a couple other amusing things.  First, I thought I would be
able to find out what modules a given module depends upon by watching
what gets added to %INC.  I cleared %INC and then required the module.
But that seemed wasteful, since it reloads some packages that were
already loaded.  So I tied %INC to a class that kept track of additions
to it, as well as FETCHes and EXISTSs (on the theory that you have to
look at $INC{something} to decide whether or not to 'use' it.

It didn't work.  %INC must be modified directly (under the covers)
by 'use' and 'require'.  Oh well.

The other thing I tried was to put the code to be reloaded into a 
Safe compartment (with no restrictions on the compartment).  But
when the included code did a 'use IO::File', it bombed out with an
error that the IO module requires dynamically-loadable perl, and
it claimed that I only had static.  Does Safe somehow restrict the
loading of dynamic modules?  Apparently.

Thanks, Mark.

-- 
Eric J. Roode                                            sdn@comcast.net
$_ = reverse sort $/.r , qw p ekca ts lre reh
uJ p, map $_ . $" , qw e p h tona e and print

Attachment: pgprhMznhCjsq.pgp
Description: PGP signature