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):
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!
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 :)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; } }
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!
|
---|
Back to
Seekers of Perl Wisdom