开发者

How should I control versions of my Perl Moose objects?

开发者 https://www.devze.com 2023-01-18 19:06 出处:网络
I\'m a Moose newbie and I wonder if the common our $VERSION = \"0.001\"; $VERSION = eval $VERSION; 开发者_如何学JAVA

I'm a Moose newbie and I wonder if the common

our $VERSION = "0.001";
$VERSION = eval $VERSION;
开发者_如何学JAVA

should also be used in Moose packages, or Moose has some alternative way for version control. Couldn't find a reference in Moose docs.


As with all perl packages, it is usually a good idea to have a $VERSION defined in them. This allows other things to properly depend on the version of them with all the features they need, either by declaring a dependency in their Makefile.PL or equivalent, or directly when loading the module using use SomeModule 1.23;.

The eval construct you're showing is a kludge. There is a distinction between regular releases of a module, and development releases. Traditionally that has been indicated by a $VERSION with an underscore in it. That means something like 0.001 would be a normal, stable release, while something like 0.001_01 would be a development release.

The eval is used to get rid of that underscore at runtime, while still preserving it in the version string that the various tools, including PAUSE, the Perl Authors Upload SErver, extract. This is to avoid warnings such as 0.001_01 is not numeric in ....

You'll find that idiom in lots of code. Luckily, there's a good alternative to it. Instead of indicating the development vs. non-development status in the version number of individual modules, you can also do that in the release tarball that you might upload to CPAN by using the -TRIAL flag.

Instead of uploading your distribution as My-Distribution-0.001.tar.gz, you can rename it to My-Distribution-0.001-TRIAL.tar.gz. The CPAN tools will pick that up and treat it as a development release accordingly. Note that -TRIAL is not part of the $VERSION, only of the tarball name. Therefore the eval kludge becomes unnecessary.

Also note that there are alternative ways to declare a package's $VERSION. As of perl 5.12.0, you are able to declare it right with in the package declaration:

package My::Package 0.001;

However, none of this is specific to Moose in any way.

0

精彩评论

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