Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Multiple versions of a module

by ferreira (Chaplain)
on Mar 17, 2007 at 18:49 UTC ( [id://605298]=note: print w/replies, xml ) Need Help??


in reply to Multiple versions of a module

Usually using at the same time two versions of a module cannot be done because one version (the first found via the @INC path) would override the other(s). Even if you tried to require them via file paths instead of module names, they would fight for the same namespace with unpleasant consequences or with the last one to be loaded winning the game (if you're lucky).

But you may achieve this effect by using the CPAN module only.

use only Module 1.0; # or use only Module 2.0;
according to what you want in a certain piece of code. But... current only has a bunch of issues (as may be seen from the tests of the current distribution: 14 PASS x 19 FAIL x 1 NA) and demands a change in the installation mantra:
perl Makefile.PL make make test perl -Monly=install # substitute for 'make install'

So it may demand some effort to make it work right.

On the other hand, if what you're trying to achieve is just a module that has two faces according to how it is used, you may give up the idea of using the version to stand for this difference and use instead some argument to the import function. You'll see this in many modules via special import tags like :strict, which triggers a certain operating mode in the module. One such example is the strict mode in the XML::Simple module:

use XML::Simple qw(:strict);

As always, there are a bunch of issues/drawbacks with this approach, like not being able to use different modes in the same application running (even in different parts of the code). This restriction may be due to the implementation code which makes use of package variables (as it is common). Sometimes, you'll regret those operation modes of the module are not only operation modes of an object which can be more flexibly configured and handled.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-18 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found