开发者

What is setting $VERSION good for?

开发者 https://www.devze.com 2023-01-14 01:28 出处:网络
Lot\'s of ways to set your modules $VERSION in perl, some even have advantages. What I don\'t know is why we do it? I mean the META.yml has a version... which is what cpan开发者_如何学JAVA uses? so wh

Lot's of ways to set your modules $VERSION in perl, some even have advantages. What I don't know is why we do it? I mean the META.yml has a version... which is what cpan开发者_如何学JAVA uses? so why do we set it in the module? what's the point?


So you can say

use Module::Name 4.5.6;

And the code will fail if you don't have at least version 4.5.6 of Module::Name installed.

It is also helpful when you need to know what version is installed, you can just say:

perl -MScalar::Util=99999999999999

This is roughly equivalent to

#!/usr/bin/perl

use Scalar::Util 99999999999999;

It will fail (becuase Scalar::Util is nowhere near version 99999999999999) and tell you the version number. In my case it says:

Scalar::Util version v.Inf required--this is only version 1.22 at
/Users/cowens/apps/perlbrew/perls/perl-5.12.1/lib/5.12.1/Exporter/Heavy.pm
line 120.
BEGIN failed--compilation aborted.


From perlmodlib: Guidelines for Module Creation:

To be fully compatible with the Exporter and MakeMaker modules you should store your module's version number in a non-my package variable called $VERSION.

To supplement the Answers given by others, here is the link to use MODULE VERSION


So if your module is widely used and actively maintained, people can reference the version easily in their code to activate/deactivate their code depending on what version they use. Just a guess.


$VERSION is available in code. For example, a user of your module can write

use YourModule 2.3;

to ensure that a minimum version of YourModule is available. This is important for API changes, bug fixes, etc.


This might be a little off topic, but since perl 5.12 you can set your modules VERSION simply by doing

package Foo::Bar 1.23;

See perl 5.12 changes.

The version number must adhere to the "strict" format though, see $version::STRICT in version::Internals.

0

精彩评论

暂无评论...
验证码 换一张
取 消