Use or not to use the namespace::sweep and/or Modern::Perl

感情迁移 提交于 2019-12-05 22:16:58

On your question about namespace::sweep:

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

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.

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.

Secondly, it says that namespace::sweep can be used instead of 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.

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

  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.

Specifying use 5.014; (or other version >= 5.011) will automatically do use strict; and enable all features of that version for you; IMO this is some of the reason Modern::Perl has not gained a whole lot of traction.

I've always disliked Modern::Perl because it doesn't describe what it does; it is someone else's idea of "modern" as of some fixed point in the past.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!