如何将 Moose 与 Test::Class 一起使用?
我目前正在重构由同事构建的测试套件,并希望在此过程中使用 Test::Class[::Most]
。当我开始时,我发现我真的可以使用几个 Moose
角色来稍微解耦代码。然而,这似乎不太可能——我收到这样的错误消息:
Prototype mismatch: sub My::Test::Class::Base::blessed: none vs ($) at
/usr/lib/perl5/vendor_perl/5.8.8/Sub/Exporter.pm line 896
所以问题是:我可以将 Moose
与 Test::Class
一起使用吗如果是这样,怎么办?
PS:代码是这样的:
package My::Test::Class::Base;
use Moose;
use Test::Class::Most;
with 'My::Cool::Role';
has attr => ( ... );
I'm currently refactoring a test suite built up by a colleague and would like to use Test::Class[::Most]
while doing so. As I started I figured out I could really use a couple of Moose
roles to decouple code a little bit. However, it seems it's not quite possible -- I'm getting error messages like this one:
Prototype mismatch: sub My::Test::Class::Base::blessed: none vs ($) at
/usr/lib/perl5/vendor_perl/5.8.8/Sub/Exporter.pm line 896
So the question is: can I use Moose
together with Test::Class
and if so, how?
PS: The code goes like this:
package My::Test::Class::Base;
use Moose;
use Test::Class::Most;
with 'My::Cool::Role';
has attr => ( ... );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Test::Deep(通过 Test::Class::Most 通过 Test::Most 加载)正在导出自己的
blessed
以及许多其他可能不应该的东西。它没有记录。 Moose 还导出了更常见的Scalar::Util::blessed
。由于Scalar::Util::blessed
相当常见,Test::Deep 不应该导出自己不同的blessed
。不幸的是,没有什么好办法来阻止它。我建议在 My::Test::Class::Base 中执行以下 hack:
并将问题报告给 测试::深 和 测试::大多数。
Test::Deep (loaded via Test::Most via Test::Class::Most) is exporting its own
blessed
along with a lot of other stuff it probably shouldn't be. Its not documented. Moose is also exporting the more commonScalar::Util::blessed
. SinceScalar::Util::blessed
is fairly common, Test::Deep should not be exporting its own differentblessed
.Unfortunately, there's no good way to stop it. I'd suggest in My::Test::Class::Base doing the following hack:
and reporting the problem to Test::Deep and Test::Most.
您可以通过(例如)压制特定的导出:
You can squelch particular exports via (for example):
我刚刚发布了 Test::Most 的更新版本。如果您安装 0.30,这个问题就会消失。
I've just released an updated version of Test::Most. If you install 0.30, this issue goes away.
找到此页面的人们可能也有兴趣了解各种 Test::Class-Moose 混搭模块:
对于其中任何一个都需要进行一定程度的重构-- 语法有所不同。然而,通过一定量的查找和替换,您可能能够进行相当快速的转换。
Folks finding this page might also be interested to know about the various Test::Class-Moose mashup modules:
With any of these some amount of refactoring would required-- the syntax varies. HOwever, with some amount of find-and-replace you may be able to make a fairly quick transition.