MooseX::Declare 和 MooseX::Method::Signatures 产品准备好了吗? [英] Are MooseX::Declare and MooseX::Method::Signatures production ready?

查看:43
本文介绍了MooseX::Declare 和 MooseX::Method::Signatures 产品准备好了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 当前版本 (0.98)Moose::Manual::MooseX 中的 a> 是以下几行:

From the current version (0.98) of the Moose::Manual::MooseX are the lines:

我们对未来寄予厚望MooseX::Method::SignaturesMooseX::Declare.然而,这些模块,虽然经常用于由一些更疯狂的人制作社区成员,仍然标记为 alpha 以防万一倒退需要进行不兼容的更改.

We have high hopes for the future of MooseX::Method::Signatures and MooseX::Declare. However, these modules, while used regularly in production by some of the more insane members of the community, are still marked alpha just in case backwards incompatible changes need to be made.

我注意到对于 MooseX::Method::Signatures 9 月的变更日志2009 年提到删除了可怕的 ALPHA 免责声明".
那么,这些仍然是alpha"吗?
我还会被认为是使用它们的更疯狂"的人之一吗?

I noticed that for MooseX::Method::Signatures the change log for September 2009 mentions the removal of the "scary ALPHA disclaimer".
So, are these still "alpha"?
Would I still be considered one of the "more insane" to use them?

推荐答案

我想说它们已准备好投入生产 - 我正在使用它们在生产中 - 但有几件事需要考虑:

I'd say they are production ready - I'm using them in production - but there are several things to consider:

MooseX::Declare 和依赖项编译时几乎所有的魔法.根据程序的大小,您可能会发现半秒到几秒的额外初始化开销.如果这是一个问题,请不要使用 MooseX::Declare.

在运行时,主要的开销是类型和参数检查,您(理想情况下)无论如何都应该这样做.也就是说,Moose 类型约束有一些开销,即强制和更复杂的(MooseX::Types::Structured-style)约束.如果性能有问题,请不要使用这些.

At runtime, the main overhead is type and argument checking, which you should (ideally) be doing anyway. That said, Moose type constraints have some overheads, namely coercion and the more complex (MooseX::Types::Structured-style) constraints. Don't use these if performance is an issue.

MooseX::DeclareMooseX::Method::Signature 的 外部语法现已稳定.但重要的是要知道内部会发生极端变化.(幸运的是,变好了)

MooseX::Declare and MooseX::Method::Signature's external syntax is now stable. But it is important to know that the internals are subject to extreme change. (fortunately, changes for the better)

为了给你一个想法,签名本身是使用从 Perl 标记器 (toke.c) 窃取的一大块 C 代码来获取的.这在某些情况下可能会中断,因为它实际上并没有解析任何东西.括号内的位是使用 PPI 解析的,它是为纯 Perl 设计的,但结果是然后破解 PPI 树以获得有用的东西.Devel::Declare 本身就是一个黑客 - 在它看到特定的关键字(例如 'role', 'class', 'method') 使用 Devel::Declare 的模块必须手动重写源代码,不与真正的 Perl 解析器交互.

To give you an idea, the signature itself is grabbed using a big block of C code stolen from the Perl tokenizer (toke.c). This can break in some situations since it isn't actually parsing anything. The bit inside the brackets is parsed using PPI, which is designed for pure Perl, but the resulting PPI tree is then hacked up to get something useful. Devel::Declare itself is a hack - after it sees specific keywords (e.g. 'role', 'class', 'method') the Devel::Declare-using module must rewrite the source code by hand, with no interaction with the real Perl parser.

极端情况可能会导致 Perl 出现段错误.或者糟糕地重写源代码,所以你会得到语法错误,但如果没有 -MO::Deparse,你不知道是什么导致了它们.如果您不小心弄乱了 MooseX::Declare 语法,则无法保证模块会检测到这一点并给你一个合理的错误.ALPHA 消息可能已经消失,但这仍然在内部做黑暗和可怕的事情,您应该为此做好准备.

Corner cases may cause Perl to segfault. Or rewrite the source code badly, so you get syntax errors but have no idea what's causing them without -MO::Deparse. If you mess up the MooseX::Declare syntax by accident, there is no guarantee that the module will detect this and give you a sensible error. The ALPHA message may have gone, but this is still doing dark and scary things internally, and you should be prepared for that.

更新

MooseX::Declare 更新不多,您可能希望查看替代方案,例如 Moops.就我个人而言,我决定坚持使用纯 Moose,直到 Perl 本身开始支持 class/method/has 语法,即 可能在卡片上.

MooseX::Declare has not been updated much, and you may wish to look at alternatives such as Moops. Personally, I have decided to stick with pure Moose until Perl itself begins to support class/method/has syntax natively, which is possibly on the cards.

这篇关于MooseX::Declare 和 MooseX::Method::Signatures 产品准备好了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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