问题描述
Perl人们在模拟将作为类型约束属性注入到其他Moose对象中的Moose对象时使用了哪些策略?
What strategies have Perl people used when mocking Moose objects that they will inject into other Moose objects as type-constrained attributes?
测试::: MockObject :: Extends 似乎没有播放驼鹿很好.我需要将对象作为一个特定的包来祝福,尽管如此,香草Test :: MockObject将无法正常工作.我敢肯定其他人也有类似的困难.您是如何解决的?
Test::MockObject::Extends doesn't seem to play well with Moose. I need the object to blessed as a specific package though so a vanilla Test::MockObject won't work. I'm sure other folks have had similar difficulty. How did you resolve it?
已在CPAN上解决方案的加分点.
Extra Points for Solutions that are already on CPAN.
推荐答案
好吧,我不是这类事情的专家,但我首先要看的是Shaw Moore(Sartak)的测试-MockOO .
Well I'm not the expert on such things but the first thing I'd look at is Shaw Moore's (Sartak) Test-MockOO.
如果这对您不起作用,那么我将看一下使用元对象协议的功能并由starrt手动构建Mock对象.查看Class :: MOP :: Class和Moose :: Meta :: Class,了解如何重写特定方法和/或在运行时以编程方式创建整个类.
If this doesn't work for you, I'd then look at using the power of the Metaobject Protocol and starrt manually building Mock objects. Look at Class::MOP::Class and Moose::Meta::Class for how to override specific methods and/or create entire classes at runtime programatically.
如果这仍然不适合您,我将绕过IRC并询问.驼鹿重击手在那里闲逛,我敢肯定其中一个已经遇到了这种情况.
If this still doesn't work for you, I'd swing past IRC and ask. The moose hevy hitters hang out there and I'm sure one of them has run into this situation.
这篇关于如何模拟Moose对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!