views:

396

answers:

1

What strategies have Perl people used when mocking Moose objects that they will inject into other Moose objects as type-constrained attributes?

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?

Extra Points for Solutions that are already on CPAN.

+4  A: 

Well I'm not the expert on such things but the first thing I'd look at is Shaw Moore's (Sartak) Test-MockOO.

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.

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.

perigrin
If that Module was already on CPAN I'd give you the checkmark. It looks like it would do the job.
Jeremy Wall