我正在重构一个由同事建立的测试套件,并希望在这样做时使用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 => ( ... );
解决方法
Test :: Deep(通过Test :: Most通过Test :: Class :: Most加载)导出它自己的祝福以及它可能不应该的许多其他东西.它没有记录. Moose还出口更常见的Scalar :: Util :: blessed.由于Scalar :: Util :: blessed相当常见,因此Test :: Deep不应该导出自己不同的祝福.
不幸的是,没有好办法阻止它.我建议在My :: Test :: Class :: Base中执行以下hack:
package My::Test::Class::Base; # Test::Class::Most exports Test::Most exports Test::Deep which exports # an undocumented blessed() which clashes with Moose's blessed(). BEGIN { require Test::Deep; @Test::Deep::EXPORT = grep { $_ ne 'blessed' } @Test::Deep::EXPORT; } use Moose; use Test::Class::Most;
并将问题报告给Test::Deep和Test::Most.