in reply to Module development: concurrent versions (Updated)

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.

Replies are listed 'Best First'.
Re^2: Module development: concurrent versions (Updated)
by BrowserUk (Patriarch) on Dec 24, 2010 at 10:13 UTC
    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.

    On Windows it is possible to dynamically load two dlls with the same name and exporting the same entrypoints (from different directories at least) at the C level.

    The problems that arise appear to come from the Perl internal mappings?

    How perl's dynaloader works, is one of those areas of dark, cross-platform voodoo that I find totally impenetrable.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.