I'm not sure, I think not. I think that you have to take care that the latest version is found first, because all perl does, is load the first instance it finds, and then check the version. Since $VERSION is just a plain variable that is set by perl code while loading the module, that seems to be the only way to do it that makes sense: you need to load the module to get at the version number.

I do recall that there has been discussion to add your requested feature to Perl6, that it will be possible to have multiple versions of modules with the same name, and you to select the version you want. I think it'll even possible to have multiple versions of a module loaded at the same time, in the same script, which most definitely isn't possible in perl5, is their package contents (they use the same package name) would clash.

Let's just say that for Perl5, Larry was a bit naive, assuming, just like Microsoft did with its versioning of system DLL's, that newer versions would always be backward compatible with older ones, and that all you ever needed was the newer version. However, this cannot be kept up in the long run. It has bitten me already, now that HTML::Parser version 3 isn't even compatible with version 2 any more, as the "text" callback has more arguments and thus the "last argument" is something entirely different between the two module versions. As a result, I can't upgrade without rewriting my scripts. BTW It uses HTML::TokeParser, not HTML::Parser directly, but the former gets all its arguments from the callback calls in the latter, so it is affected, too.

Let me take a look at the Exporter docs for require_version():

The Exporter module will convert an attempt to import a number from a module into a call to $module_name->require_version($value). This can be used to validate that the version of the module being used is greater than or equal to the required version.

The Exporter module supplies a default require_version method which checks the value of $VERSION in the exporting module.

What's not clear? It means that in case of your call,
use MIME::Types 1.005;
this will construct a call:
MIME::Types->require_version(1.005);
for which either the module has provided a method, which does the checking itself, or, if this method doesn't exist (I guess that's the more common case, it's the case for MIME::Types) this will call a fallback method through inheritance, which compares the argument given to the variable $VERSION of the package, in this case, to $MIME::Types::VERSION; and croak if the module is not new enough.

In reply to Re: Module Version Checking - Checking Multiple Installations of the Module by bart
in thread Module Version Checking - Checking Multiple Installations of the Module by skazat

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.