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.
| [reply] [d/l] [select] |
use does a require, which finds the first occourance of the module in @INC, and then calls the module's import, passing it the approps args. The import can then do whatever it wants.
In other words, the '1.005' isn't magical here, it just gets passed to Mime::Types::import, which can do with it what it will. I don't think require_version has anything in to to keep looking if $Mime::Types::VERSION is too low.
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] |
Im afraid not,
Exporter just calls UNIVERSAL->VERSION
quoting perldoc UNIVERSAL:
"VERSION" will return the value of the variable $VERSION in the package the object is blessed into. If "REQUIRE" is given then it will do a comparison and die if the package version is not greater than or equal to "REQUIRE".
So it won't search any further, it just dies.
+ Memento mori
--
Jaap Karssenberg || Pardus Larus <pardus@cpan.org>
>>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<
| [reply] |
As other replies have already detailed, it loads the first one it finds.
You might look at Exporter::VA, which is my solution to having multiple versions. It has them all in the single file, though, rather than multiple copies of the file name along different paths. You could make a proxy module, say Types_versioned, that looks at the version number passed, looks for all copies for Types, and loads the right one.
—John | [reply] |