xenoterracide
xenoterracide

Reputation: 16837

What is setting $VERSION good for?

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 uses? so why do we set it in the module? what's the point?

Upvotes: 4

Views: 288

Answers (5)

Chas. Owens
Chas. Owens

Reputation: 64919

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.

Upvotes: 10

Øyvind Skaar
Øyvind Skaar

Reputation: 2328

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.

Upvotes: 3

toolic
toolic

Reputation: 62037

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

Upvotes: 5

Michael Carman
Michael Carman

Reputation: 30831

$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.

Upvotes: 3

Andy
Andy

Reputation: 3170

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.

Upvotes: 3

Related Questions