Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: PERL modules named differently than the package won't export

by dsheroh (Parson)
on May 15, 2012 at 10:00 UTC ( #970589=note: print w/ replies, xml ) Need Help??


in reply to PERL modules named differently than the package won't export

I'll second the "don't do this". Given that you don't need to include the package name when referencing an exported symbol, what do you hope to achieve by having two separate source files, with two separate names, which contain alternate implementations of the same package?


Comment on Re: PERL modules named differently than the package won't export
Re^2: PERL modules named differently than the package won't export
by kovacsbv (Novice) on May 15, 2012 at 13:59 UTC

    Version control of PMs where different callers (that is, different .pl files) can each choose which version of the PM they want by simply changing the use statement, not multiferous lines that call into the module.

    That is my goal.

Re^2: PERL modules named differently than the package won't export
by kovacsbv (Novice) on May 15, 2012 at 16:40 UTC

    Oh, yeah one more thing.

    Most functions are not exported; they have to be explicitly referenced (to avoid too much namespace pollution). But there are two or three that are used so often it just makes more clutter to require explicit reference.

      I see. I guess that makes (some) sense.

      How about this approach, then:

      As Eliya mentioned, use Utils1; is equivalent to

      BEGIN { require Utils1; Utils1->import; }
      You should, therefore, be able to make the import from the Utils package transparent by editing Utils1.pm to do something along the lines of
      package Utils1; sub import { Utils->export_to_level(1, @_); } package Utils; ...
      This will (assuming I remembered the incantation correctly) make Utils1->import equivalent to Utils->import.


      Although, really, the better approach would likely be to put the two versions of Utils.pm into different library directories (e.g., /usr/local/devel/Utils.pm and /usr/local/stable/Utils.pm), then manipulating @INC (by setting PERL5LIB in the shell or with use lib in the code) so that each program will load the appropriate version.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://970589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-07-26 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls