SPUG: Change a namespace after loading?

Jacinta Richardson jarich at perltraining.com.au
Sat Apr 14 22:42:56 PDT 2007

Bill Warner wrote:
> I don't want to edit the clients, nor do I want to edit the deprecated
> code. I want to load the deprecated code and change its namespace then
> write some new code that dispatches to the deprecated code in the
> altered namespace.

Just to state an assumption here: clients = scripts which use the to-be 
deprecated module.  As opposed to clients are scripts connecting to a server, or 
clients are people who pay you money...

Where are you planning to write the new code so that when clients attempt to 
"use" the deprecated module, they actually end up with what they need?  Where 
will that sit in the execution chain?

Further (if it were possible) would it be sufficient to trap the execution of:

	use Deprecated qw(list of various cool exported functions)

and replace that with

	use NewAndShiny qw(same list of exported functions);

or do you reference Deprecates' variables etc by fully qualified names in 
various places:


	my $object = Deprecated->new();

If your module is self-contained enough that it is possible to catch things like 
use Deprecated and swap for use NewAndShiny I think you could probably do this 
easily by moving Deprecated, changing it's package name only and having a 
pseudo-Deprecated module which sat in the middle and effectively did dispatch. 
In fact, it may be possible to get it to tie variables appropriately too. 
Sounds like fun.

All the best,


More information about the spug-list mailing list