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/NamespaceHandling.pm] 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
:No parentheses there (and no example of multiple roles). How about the
- with
class Foo with Role { ... }Applies a role to the class being declared.
Moose
docs then?with (@roles)Well, this has the parentheses, but let's look at how
This will apply a given set of @roles to the local class.
with
is used in the examples:Hey! Where are the parentheses? Inpackage MovieCar;
use Moose;
extends 'Car';
with 'Breakable', 'ExplodesOnBreakage';
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.
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
ReplyDeleteI agree this is a problem, well 2 in fact.
ReplyDelete1) that the error is reported from MooseX/Declare/Syntax/NamespaceHandling.pm 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] rt.cpan.org> . Or better yet, a failing test case with a pull request against http://github.com/rafl/moosex-declare/tree/master
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.
ReplyDelete