如何在 Perl 中指定包版本?

发布于 2024-07-30 01:55:54 字数 448 浏览 3 评论 0 原文

我对 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");

我们是否退步了,或者这背后有什么原因吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唐婉 2024-08-06 01:55:54

您引用的Perl 最佳实践不太正确。 bare 形式的 vstring

our $VERSION = v1.0.3;

具体来说,不鼓励使用 。 在最新版本的 version.pm 中,建议使用真实字符串:

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

添加此功能是为了提高可读性,同时特别避免描述的裸字符串陷阱 此处

正如您链接到的文档页面所说,您可以使用 Perl 5.10 中的内置逻辑来使用没有前置“v”的版本:

如果您有一个使用十进制 $VERSION(浮点)的模块,并且您不打算更改它,则该模块不适合您。 version.pm 不会比简单的 $VERSION 分配给您带来任何好处。

所以你的问题的答案是:如果你正在编写使用 version.pm 的新代码,请使用新的“v1.0.3”语法。 如果您的旧代码是这样编写的,或者您不想显式依赖 module.pm,请坚持使用普通数字。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文