This is the same problem as package name clashes. Ideally, instead of pulling in a package and making its name globally available to the whole program, the loading mechanism should allow the puller to associate with the loaded file a name that is local to its namespace. In this case it should be possible to "alias" the same module to different namespaces within the calling module. Internally perl could maintain the list of loaded files and avoid loading the same file multiple times. This approach would remove the need for unique package names.
But there's no sense to talk about "ideal ways" here. In the current setup, one has to play with package namespaces. Something like
BEGIN{ # load Pack1 defining "package Abc;" require Pack1; # copy the Abc namespace to Cde namespace my $ref = $main::{'Abc::'}; foreach my $n (keys %$ref) { *{"Cde::$n"} = $ref->{$n}; } # remove Abc namespace delete $main::{'Abc::'}; } BEGIN { # load Pack2 also defining "package Abc;" require Pack2; } # now the first version is in Cde package, # the second version is in Abc package Cde::test(); Abc::test();
Actually, there might be some catches with the shared libraries. I don't know exactly how they are loaded. On Linux, one can load multiple shared libraries defining the same function names and then obtain pointers to functions in desired library. But I don't know if it is done this way everywhere.
In reply to Re: Module development: concurrent versions (Updated)
by andal
in thread Module development: concurrent versions (Updated)
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |