perl - 为什么 "use namespace::autoclean"比 "no Moose"更受欢迎?

标签 perl moose

关于 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)."



Moose::Manual::BestPractices (强调我的)。

我了解上述引用的所有内容,除了一件事:为什么要使用 namespace::autoclean优先使用 no Moose在词法范围的末尾?

是不是因为namespace::autoclean更通用,允许更多的使用选项,或者它的实现方式有什么内在的东西(也许是专门为 Moose 类定制的)使它更可靠?

我没有找到任何文件来澄清这一点,我很想知道正确的答案。

最佳答案

no Moose仅删除由 use Moose 导入的那些函数. use namespace::autoclean摆脱所有导入的功能。

如果你总是使用 namespace::autoclean , 那么你就不用记得切换 no Mooseuse namespace::autoclean如果您稍后回来并从某个模块导入功能。否则,您可能会忘记这样做。

关于perl - 为什么 "use namespace::autoclean"比 "no Moose"更受欢迎?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9559064/

相关文章:

perl - 如何设置一个可以被同一基类(Perl/Moose)的所有子类访问的静态变量?

perl - 如何处理 Moose 中的模拟角色?

php - 类似于 CLOS 的 PHP 对象模型

regex - Perl 正则表达式 获取电子邮件地址

perl - 发现 Perl 应用程序当前定义的所有变量的最佳方法是什么?

mysql - 使用 perl 比较 2 个 mysql 表不更新或合并

postgresql - 在 Postgres 的 plperl 函数中访问 c​​urrent_settings 函数

mysql - 编译 Perl 的 DBD::mysql 时如何修复 "Symbol not found: _is_prefix"?

perl - Moose && utf8(包|方法)名称

perl - 使用 Type::Tiny 将类型参数化为另一种类型