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.


In reply to Re: Multiple versions of a module by ferreira
in thread Multiple versions of a module by newest_newbie

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.