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):
sub AUTOLOAD
{
my $f = $AUTOLOAD;
if( $f =~ /^(My(::[a-zA-Z0-9_]+)*)(::|->)([a-zA-Z0-9_]+)$/ )
{
my $pkg = $1;
eval "require $pkg;";
}
if( $f =~ /^NEW::(.*)$/ )
{
my $func = $1;
unshift( @INC, "/newpkgs" );
return &{$func}(@_);
}
else
{
goto \&{$f};
return;
}
}
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!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.