我应该如何控制 Perl Moose 对象的版本?
我是一个 Moose
新手,我想知道 Common 是否
our $VERSION = "0.001";
$VERSION = eval $VERSION;
也应该在 Moose 包中使用,或者 Moose
有一些替代的版本控制方式。在 Moose
文档中找不到参考。
I'm a Moose
newbie and I wonder if the common
our $VERSION = "0.001";
$VERSION = eval $VERSION;
should also be used in Moose packages, or Moose
has some alternative way for version control. Couldn't find a reference in Moose
docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与所有 Perl 包一样,在其中定义
$VERSION
通常是个好主意。这允许其他东西正确地依赖于它们的版本及其所需的所有功能,可以通过在其Makefile.PL
或等效文件中声明依赖项,或者直接在使用use 加载模块时进行一些模块 1.23;
。您显示的
eval
构造是一个拼凑。模块的常规版本和开发版本之间存在区别。传统上,这由带有下划线的$VERSION
来指示。这意味着像0.001
这样的版本将是正常、稳定的版本,而像0.001_01
这样的版本将是开发版本。eval 用于在运行时删除该下划线,同时仍将其保留在各种工具(包括 PAUSE、Perl Authors Upload SErver)提取的版本字符串中。这是为了避免诸如
0.001_01 is not numeric in ...
之类的警告。您会在很多代码中发现这种习惯用法。幸运的是,有一个很好的替代方案。您也可以在发布 tarball 中使用
-TRIAL
标志上传到 CPAN,而不是在各个模块的版本号中指示开发与非开发状态。您可以将其重命名为
My-Distribution-0.001-TRIAL.tar.gz
,而不是将其上传为My-Distribution-0.001.tar.gz
。 CPAN 工具将接收该信息并将其视为相应的开发版本。请注意,-TRIAL
不是$VERSION
的一部分,而只是 tarball 名称的一部分。因此,eval
拼凑就变得不必要了。另请注意,还有其他方法可以声明包的
$VERSION
。从 perl 5.12.0 开始,您可以在包声明中正确声明它:但是,这些都不是特定于
Moose
的。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 theirMakefile.PL
or equivalent, or directly when loading the module usinguse 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 like0.001
would be a normal, stable release, while something like0.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 as0.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 toMy-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 theeval
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:However, none of this is specific to
Moose
in any way.