P is for Practical | |
PerlMonks |
Re: Multiple versions of a moduleby ferreira (Chaplain) |
on Mar 17, 2007 at 18:49 UTC ( [id://605298]=note: print w/replies, xml ) | Need Help?? |
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. 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:
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:
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.
In Section
Seekers of Perl Wisdom
|
|