I'm noticing I can't load the two sets of functions without them overwriting each other
. . .
I was hoping I could do that, and then use a combination of use and no when I wanted to switch "versions" in the program.
As you've noticed from the other responses, there are several ways to get something close to what you want. From the quotes above and your wording in general (talking about "versioning" for instance) it seems that maybe you have existing code that you want to change as little as possible but you want to pull in the new "version" of some functions as needed? Are you debugging or trying to test a new module piecemeal?
If that's the case, you might want to manually import the subs you want when you want them. Some aliasing as simple as:
might do what you need. If you need a bit more flexibility, you could wrap that up in a sub like:{ no warnings 'redefine'; *foo = \&Interface1::foo; } print foo(); { no warnings 'redefine'; *foo = \&Interface2::foo; } print foo();
Which you could then use like:sub use_from { no strict 'refs'; no warnings 'redefine'; my $package = shift; *{ $_ } = *{ "$package\::$_" }{CODE} for @_; }
use_from('Interface1', 'foo', 'bar'); foo(); bar() use_from('Interface2', 'foo', 'bar') foo(); bar();
For the sake of maintainability, you probably wouldn't want to leave this stuff in production code. But it can be handy during development.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Calling same named functions from different modules
by sauoq
in thread Calling same named functions from different modules
by geckosan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |