且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Perl:解释如何使用“uni::perl";模块 - 加载编译指示和其他模块

更新时间:2023-12-04 21:49:46

  1. 直接设置警告位会更快一些,并且具有更多可预测的行为(您可以看到应该发生的一切),但显然更难使用和维护.uni::perl 尝试加载的警告集可能通过位掩码更容易完成.

  1. Setting the warning bits directly is a bit faster, and has more predictable behavior (you can see everything that should happen), but it is obviously much harder to work with and maintain. It may be that the set of warnings that uni::perl is trying to load is easier done through the bitmasks.

m{ 使用严格;use warnings;}x; 只是 void 上下文中的正则表达式.如果启用了警告,它将抛出关于上下文或 $_ 未设置的错误.我不确定为什么要这样做,这可能是为了安抚一些寻找使用警告;使用严格"行的代码度量系统.我可能会写它 q{...} if 0; 至少更清楚一点.

m{ use strict; use warnings;}x; is simply a regex in void context. It would throw an error either about context or $_ not being set if warnings were enabled. I am not sure exactly why this is being done, it might be to appease some code metric system that looks for the lines "use warnings; use strict". I would have probably written it q{...} if 0; which is at least a little clearer.

这个 BEGIN 块正在创建 Carp 中函数的自定义版本.它使用 local *__ANON__ = ... 行来设置任何匿名子例程的名称,以便更容易跟踪 Carp 堆栈跟踪.BEGIN 块创建封装的 Carp 例程.然后导入子例程将这些新包装的例程加载到调用者的命名空间中.

This BEGIN block is creating custom versions of the functions in Carp. It is using the local *__ANON__ = ... line to set the name of any anonymous subroutines so that the Carp stack trace is easier to follow. The BEGIN block creates the wrapped Carp routines. The import subroutine then loads these new wrapped routines into the caller's namespace.

最后一段时间似乎正在为 uni::perl 加载额外的插件模块.

That last while seems to be loading additional plugin modules for uni::perl.

没有做同样的事情,请参阅 #3 的答案.(BEGIN 创建包装的例程,import 将它们安装到调用者的空间中)

The same thing is not being done, see the answer to #3. (BEGIN creates the wrapped routines, import installs them into the caller's space)