How can I (safely) use packages of the same name but different versions?by xevian (Sexton)
|on Mar 11, 2008 at 20:24 UTC||Need Help??|
xevian has asked for the wisdom of the Perl Monks concerning the following question:
Here's the setup:
I have a system with a bunch of default packages installed.
I allow users to drop in newer versions of these packages to a well-known location on the disk (not in @INC).
I've defined a universal autoloader to redirect specific function calls to these newer versions... for example:
My::Package::foo() is a subroutine in the default install.
My::Package::foo() is a subroutine in the new version location.
The autoloader (simplified for this example):
There are two problems with this, and I'm grasping at straws now :)
Problem 1: If anything causes My::Package to load before they call NEW::My::Package::foo(), it will use the older version because it was already loaded.
Problem 2: If anything causes the My::Package module to load from the /newpkgs location, subsequent calls to My::Package::foo() (without the NEW:: prefix) will use the new package and not the old one.
What I really need is a way to local the entire symbol table and then clear it out so that calling "NEW::Package::foo()" will load whatever requirements it has first from the /newpkgs location and falling back to the other paths in @INC... and after the call is over ensuring that the symbol table is back to the "before-I-called-NEW::My::Package::foo()" state.
Any suggestions? Many thanks in advance!