如何在 Perl 中指定包版本?
我对 5.10.0 之前的文档和更新的 版本 模块。 Perl 最佳实践 非常清楚地表明版本字符串('v1.0.3')是不好的并且是一个应该指定一个版本,如下所示:
use version; our $VERSION = qv('1.0.3');
但是版本模块说我们又回到使用版本字符串了:
use version 0.77; our $VERSION = qv("v1.2.3");
我们是否退步了,或者这背后有什么原因吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您引用的Perl 最佳实践不太正确。 bare 形式的 vstring
具体来说,不鼓励使用 。 在最新版本的 version.pm 中,建议使用真实字符串:
添加此功能是为了提高可读性,同时特别避免描述的裸字符串陷阱 此处。
正如您链接到的文档页面所说,您可以使用 Perl 5.10 中的内置逻辑来使用没有前置“v”的版本:
所以你的问题的答案是:如果你正在编写使用 version.pm 的新代码,请使用新的“v1.0.3”语法。 如果您的旧代码是这样编写的,或者您不想显式依赖 module.pm,请坚持使用普通数字。
Your quote from Perl Best Practices is not quite right. Specifically, bare vstrings of the form
are discouraged. In the latest version of version.pm, the recommendation is to use true strings:
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:
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.