Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you specify a package version in Perl?

I'm a bit confused by conflicting advice between pre-5.10.0 documents and the more recent version module. Perl Best Practices makes it pretty clear that version strings ('v1.0.3') are bad and one is supposed to specify a version as follows:

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

but the version module says that we're back to using version strings:

use version 0.77; our $VERSION = qv("v1.2.3");

Have we regressed, or is there a reason behind this?

like image 620
Drew Stephens Avatar asked Aug 01 '09 07:08

Drew Stephens


1 Answers

Your quote from Perl Best Practices is not quite right. Specifically, bare vstrings of the form

our $VERSION = v1.0.3;

are discouraged. In the latest version of version.pm, the recommendation is to use true strings:

use version 0.77; our $VERSION = qv("v1.2.3");               # shorthand

This functionality has been added to aid readability, while specifically avoid the traps of bare strings described here.

As the doc page you linked to says, you can use versions without the pre-pending 'v' using built-in logic in Perl 5.10:

If you have a module that uses a decimal $VERSION (floating point), and you do not intend to ever change that, this module is not for you. There is nothing that version.pm gains you over a simple $VERSION assignment.

So the answer to your question is: use the new "v1.0.3" syntax if you are writing new code that uses version.pm. Stick to a plain number if that is how your old code was written, or if you don't want to depend explicitly on module.pm.

like image 183
ire_and_curses Avatar answered Nov 15 '22 03:11

ire_and_curses