使用或不使用 namespace::sweep 和/或 Modern::Perl [英] Use or not to use the namespace::sweep and/or Modern::Perl

查看:61
本文介绍了使用或不使用 namespace::sweep 和/或 Modern::Perl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的最后一个问题中@Borodin评论了我的问题:

In my last question @Borodin commented my question with:

您应该首先删除 Modern::Perl 和 namespace::sweep.应避免使用作为 pragma 的模块.

You should start by removing Modern::Perl and namespace::sweep. Modules that behave as pragma should be avoided.

我有点困惑,因为:

  • in the LATEST Moose BestPractices manual recommending to use namespace::autoclean.

use namespace::autoclean 位只是良好的代码卫生,因为它在结束时从类的命名空间中删除导入的符号包的编译周期,包括 Moose 关键字.一旦上课已经建好了,就不需要这些关键字了.(这是首选不要在包裹的末端放置驼鹿).

The use namespace::autoclean bit is simply good code hygiene, as it removes imported symbols from your class's namespace at the end of your package's compile cycle, including Moose keywords. Once the class has been built, these keywords are not needed. (This is preferred to placing no Moose at the end of your package).

Intermediate perl 书中也推荐使用namespace::autoclean.

是的,我使用了 autoclean 而不是 sweep 模块 - 因为再次 来自文档

Yes, I'm used the instead of the autoclean the sweep module - because again from the doccu

编写此 pragma 是为了解决优秀的命名空间::自动清理.特别是,namespace::autoclean 将删除由重载安装的特殊符号,因此您不能使用namespace::autoclean 在重载 Perl 运算符的对象上.

This pragma was written to address some problems with the excellent namespace::autoclean. In particular, namespace::autoclean will remove special symbols that are installed by overload, so you can't use namespace::autoclean on objects that overload Perl operators.

......

在大多数情况下,namespace::sweep 应该作为替代品用于命名空间::自动清理.发布后,此 pragma 通过所有namespace::autoclean 的测试,以及它自己的测试.

In most cases, namespace::sweep should work as a drop-in replacement for namespace::autoclean. Upon release, this pragma passes all of namespace::autoclean's tests, in addition to its own.

而且因为我是一个 perl 初学者,所以我真的很困惑.对我来说,当我阅读:这个模块解决另一个模块的一些问题 - 意思是:使用这个.

And because I'm an perl beginner, i'm really confused. For me, when i reading: this module addressing some problems of another module - mean: use this one.

'手册(我应该从哪里学习)说使用它"和来自 stackoverflow teling 的专家:不要使用它.

'Manual (where from I should learn) says "use it" and expert from stackoverflow teling: don't use it.

所以请有人解释一下:

  • 使用 namespace::sweep 是否正确,或者我应该使用 namespace::autoclean 还是不使用它们?
  • 如果没有,为什么 BestPractices 推荐它?
  • it is correct to use namespace::sweep or I should use namespace::autoclean or none of them?
  • if none, why the BestPractices recommends it?

对于`ModernPerl'.当然,我可能没有深入了解和确切地"了解它的作用.我所知道的,(再次来自 doccu)

For the `ModernPerl'. Sure, I'm probably don't understand deeply and "exactly" what is does. What i know, (again from it's doccu)

这将启用严格和警告编译指示,以及所有Perl 5.10 中可用的功能.它还支持 C3 方法解析按照 perldoc mro 中记录的顺序并加载 IO::File 和 IO::Handle以便您可以调用文件句柄上的方法.未来,它可能包括额外的核心模块和编译指示.

This enables the strict and warnings pragmas, as well as all of the features available in Perl 5.10. It also enables C3 method resolution order as documented in perldoc mro and loads IO::File and IO::Handle so that you may call methods on filehandles. In the future, it may include additional core modules and pragmas.

当然,不深入了解mro,只认为它是多重继承情况下死亡钻石"问题的答案.

Sure, don't deeply understand to mro, only think it is an answer to the "deadly diamond of death" problem in cases of multiple inheritance.

直到今天,我对它真的很满意,因为它对我来说缺少所需的编译指示:

Up to today, i was really happy with it, because it is shorting for me the needed pragmas:

use strict;
use warnings;
use feature 'say';

那么,Modern::Perl"(以及其他类似的 cpanm 模块)的状态"是什么?是否允许使用?

So, what is a "status" of the "Modern::Perl" (and other similar cpanm modules)? Allowed to use, or not?

推荐答案

关于namespace::sweep的问题:

On your question about namespace::sweep:

首先,注意namespace::sweep 解决的实际问题.

Firstly, take note of the actual problem that namespace::sweep resolves.

特别是,namespace::autoclean 将删除由重载安装的特殊符号,因此您不能在重载 Perl 运算符的对象上使用 namespace::autoclean.

In particular, namespace::autoclean will remove special symbols that are installed by overload, so you can't use namespace::autoclean on objects that overload Perl operators.

这意味着如果您的类具有重载运算符,如果您还使用 namespace::autoclean,它们将无法工作.但是这个问题只有在你使用重载时才会出现.除此之外,namespace::autoclean 就足够了.

What this means is that if your class has overloaded operators they won't work if you also use namespace::autoclean. But this problem only occurs if you use overload. Other than that, namespace::autoclean will suffice.

其次,它说可以使用 namespace::sweep 代替 namespace::autoclean:

Secondly, it says that namespace::sweep can be used instead of namespace::autoclean:

在大多数情况下,namespace::sweep 应该作为 namespace::autoclean 的直接替代品.发布时,此 pragma 除了自己的测试外,还通过了 namespace::autoclean 的所有测试.

In most cases, namespace::sweep should work as a drop-in replacement for namespace::autoclean. Upon release, this pragma passes all of namespace::autoclean's tests, in addition to its own.

所以要回答你的问题,使用 namespace::sweep 还是我应该使用 namespace::autoclean 或都不使用它们是正确的吗?"

So to answer your question, "is it correct to use namespace::sweep or I should use namespace::autoclean or none of them?"

  1. 您应该至少使用 Moose Best Practices 推荐的其中一种.
  2. 使用 namespace::sweep 通常是可以的,因为它说它旨在这样做并且它通过了所有 namespace::autoclean 的测试.
  3. 尽管有上述第 2 点,如果您不使用重载,那么使用 namespace::autoclean 就没有问题,因此您可以在这种情况下使用它.
  1. You should use at least one of them as recommended by Moose Best Practices.
  2. It is generally ok to use namespace::sweep since it says it is designed to do so and it passes all of namespace::autoclean's tests.
  3. In spite of point 2 above, if you don't use overload then you don't have a problem with using namespace::autoclean, so you could just use that in this case.

这篇关于使用或不使用 namespace::sweep 和/或 Modern::Perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆