More module versioning pain

Yeah, I know, I am always complaining about module versioning. But I think this is something we need to take care when releasing.

This time, it seems that Mail::SPF (JMEHNLE/mail-spf/Mail-SPF-v2.8.0.tar.gz) was indexed by CPAN as v2.8.0, but identifies itself as v2.008. Oh, joy!

4 Comments

My first thought is that there ought to be a test for this.

My second thought was that if the version module was involved, they are actually the same version number, appearances to the contrary notwithstanding. And sure enough, Mail::SPF contains


use version; our $VERSION = qv('2.008');

So there is actually nothing wrong with Mail::SPF in a purely technical sense. But doing things this way certainly seems to violate the law of least surprise.

Yes, the fact that Mail::SPF->VERSION prints v2.008 seems weird, but it is a valid dotted-decimal string. Those leading zeros between the dot and the 8 are optional, so it condenses down to v2.8.0

$ perl -Mversion -E 'say version->parse('v2.008') == version->parse('v2.8.0') ? 1 : 0'
1
$ perl -Mversion -E 'say version->parse('v2.8') == version->parse('v2.8.0') ? 1 : 0'
1

The zeros are only optional in dotted-decimal; if that v was not there, though, they are still the same version, though, but the leading zeros are no longer optional.

$ perl -Mversion -E 'say version->parse('2.008') == version->parse('v2.8.0') ? 1 : 0'
1
$ perl -Mversion -E 'say version->parse('2.8') == version->parse('v2.8.0') ? 1 : 0'
0

The qv() used in the module (which is deprecated) adds an implicit v to the beginning of the version string, I believe.

If you just use:

BEGIN {
  $Your::Module::AUTHORITY  = 'cpan:JOEBLOGGS';
  $Your::Module::VERSION    = '1.234';
}

... somewhere near the top of your module, that tends to be pretty reliable. That is: use a decimal number, string quoted, with either three or six decimal places. This is the path of least resistance. Any other creative things with version numbers is a recipe for disaster.

And yet perlmodstyle suggests that you use two decimal places for module version numbers, and that this is the most widely used.

Leave a comment

About Alberto Simões

user-pic I blog about Perl. D'uh!