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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.