Priorities when using Any::Moose, and what Mouse people should do

A recent test script of mine broke with the following message: You can only consume roles, MooseX::Role::Loggable is not a Moose role at /usr/lib/perl5/Moose/Util.pm line 137. What happened?

This test script uses Juno and an internal module that we have at work here. Both of them use Any::Moose. They also use my MooseX::Role::Loggable which uses Any::Moose as well, in order to allow you to use it in Moose and Mouse.

The problem started when I changed my internal module to use Moose instead of Any::Moose (I needed native traits, native traits are awesome). This broke everything. Why, I thought, isn't this supposed to be interchangeable? Oh, it is, it is. The problem was the order of loading in the test script. Because it loaded Juno first, Any::Moose loaded Mouse. When I loaded the internal module (which now uses Moose) first, it loaded Moose and Any::Moose loaded that too, which allows MooseX::Role::Loggable to use Moose instead of Mouse and be consumed correctly.

So, the lesson is this: everyone using Mouse should use Any::Moose. (btw, it seems like that was the purpose in the first place, so I'm not the only one saying it :)

Also, if you're gonna have something that uses hardcoded Moose, load that before loading any Any::Moose code.

4 Comments

Actually, you can use native traits with Mouse too, using MouseX-NativeTraits. It makes using Mouse a lot more bearable.

Except if something else expects an Any::Moose class to have delegated to Mouse, then loading Moose first will break that. And if you manage to get both in your program, you lose: no way around is right.

The whole Moose/Mouse/Any::Moose situation is an action-at-a-distance mess.

Leave a comment

About Sawyer X

user-pic Gots to do the bloggingz