Monday, July 20, 2009

adventures in ignorance: Multiple roles with MooseX::Declare

I am really liking Moose, in particular MooseX::Declare; however, the docs and error messages can be very confusing. For instance, I was trying to create a class that used two roles and kept getting the following error:
expected option name at [path to MooseX/Declare/Syntax/] line 45
What this meant was that I needed to say:
class FooBar with (Fooable, Barable) {}
instead of:
class FooBar with Fooable, Barable {}
Now, I should never have gotten that error if I had followed the docs, so lets see what MooseX::Declare has to say about with:
    class Foo with Role { ... }

Applies a role to the class being declared.

No parentheses there (and no example of multiple roles). How about the Moose docs then?
with (@roles)

This will apply a given set of @roles to the local class.
Well, this has the parentheses, but let's look at how with is used in the examples:
package MovieCar;

use Moose;

extends 'Car';

with 'Breakable', 'ExplodesOnBreakage';
Hey! Where are the parentheses? In Moose they are optional, and in MooseX::Declare they are optional if you have only one role, but required if you have more than one.


  1. Glad to see I'm not the only one confused... I've had to remove MooseX::Declare from several classes because I couldn't figure out multiple roles, and it gets worse when using MooseX::Role::Parameterized

  2. I agree this is a problem, well 2 in fact.

    1) that the error is reported from MooseX/Declare/Syntax/ not in your code; and
    2) That the error itself is unhelpful.

    Both of these problems are solvable.

    Bu if you tell us about them: in the future *please* send an email to < bug-MooseX-Declare [at]> . Or better yet, a failing test case with a pull request against

  3. Thanks, I was meaning to hunt down that information. I have another problem related to the BUILD (and possibly BUILDARGS), but I haven't figured out yet what would be the solution that would make me happy.


Some limited HTML markup is allowed by blogger: strong, b, i, and a. You may also use em, but I have repurposed it through the magic of CSS to be behave very much like <tt><code></code></tt>.