Emphyrio has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a modular IRC bot.
I currently have a couple of modules which i can load 'on demand' by sending a command to it; it then require's the module, and fills a hash with some references to subs in the module, and hooks into the main code. cool. it works.
Now i need to _unload_ the code, so i can have a drop-in replacement system (cool for debugging, or upgrading a module). Is there a way to 'unload' code i require'd, or use'd, or otherwise imported ?
I know i can unset $INC{modulename}, but i still need the actual code replaced by the code in the module file..
If you eval a file (like with require), new subroutine definitions will replace old ones, usually just fine. Coderefs taken to old routines still refer to the old routines, however, and closures for those routines will remain alive.
If you want something fancier, perhaps you can "delete" the entire package. I've seen code to do that somewhere (perhaps even here).