Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the pros and cons about declaring package version methods in Perl?

Modules are cool especially when they come with versioning. You can define minimum module version to prevent leak of methods you want to use. But with every light side there comes a dark side which means Perl's TIMTOWTDI.

After nearly seven years as a Perl developer I saw and wrote version declarations in many ways. Some are easily to point as bad, some not. As no one can know a language completely I would like to ask you guys whats the pros and cons of the following software versioning in Perl is.

Please don't hesitate to comment more ways of version definition if you find one leaking ;)

Please respect:

  • weird require/use of module that may cause trouble detecting module's version (compile vs runtime)
  • PAUSE/CPAN parsing (and other common services)
  • readability for end users
  • maintainability for developers

What are the pros and cons about declaring package version methods in Perl?

Method 1

package PackageName;
BEGIN {
  use version 0.77; our $VERSION = version->new('v0.0_1');
}

Method 2

package PackageName;
BEGIN {
  our $VERSION = 0.000_01;
}

Method 3

package PackageName;
BEGIN {
  our $VERSION = 0.0.1;
}

Method 4

package PackageName;
use version 0.77; our $VERSION = version->new('v0.0_1');

Method 5

package PackageName;
our $VERSION = 0.000_01;

Method 6

package PackageName;
our $VERSION = 0.0.1;
like image 414
burnersk Avatar asked Jul 12 '13 13:07

burnersk


1 Answers

The correct answer is, do this:

package My::Thing;
our $VERSION = "0.001";

The version should always be a decimal number, using the three-digit split convention. The above version would be shortened to v0.1.0, to change the 3rd step in that abbreviated form you would define your version like this: 0.001001, which would be v0.1.1 abbreviated.

Do not put underscores into your version number to mark dev releases. The Perl toolchain has since adopted the -TRIAL mechanism, as exemplified by Dist::Zilla 4.101800-TRIAL. The advantage of that is that the version numbers in your code need no changes. Only the release filename and meta files are modified from the norm by adding -TRIAL.

Edit:

After reading daxim's answer and pondering a bit, i have to agree on putting the version number in quotes. It does not change the functionality in any way, but reduces the chances of 0.00101 being mistaken for v0.1.1, when it is in fact v0.1.10 and is more clearly read as 0.001010.

like image 137
Mithaldu Avatar answered Oct 07 '22 16:10

Mithaldu