I recently upgraded Moose to v1.15 and found that a set of modules I use no longer worked. The error I get is:
You cannot coerce an attribute (source) unless its type (GOBO::Node) has a coercion at
/opt/local/lib/perl5/site_perl/5.12.0/darwin-multi-2level/Moose/Meta/Role/Application/ToClass.pm line 142
I can see several possible sources of error and would be grateful for advice on how to fix the problem.
The first bit of code for GOBO::Node looks like this:
package GOBO::Node;
[...]
extends 'GOBO::Base';
with 'GOBO::Labeled';
with 'GOBO::Attributed';
coerce 'GOBO::Node'
=> from 'Str'
=> via { new GOBO::Node(id=>$_) };
has 'source' => (is => 'rw', isa => 'GOBO::Node');
The roles used by this package also have attributes that are GOBO::Nodes, and the attribute 'source' mentioned in the error message is one of them.
part of the reason for having the coercion in GOBO::Node seems to be as a shortcut when creating a new node. Would it be better to use BUILDARGS rather than coerce?
where should I put the coercion if I want several packages to be able to use it? If I add the coercion to (e.g.) GOBO::Attributed, I get a warning that it already exists. Without the coercion, though, I get the warning above about not being able to coerce.
there is a separate package of subtypes; would it be better to create a subtype of GOBO::Node--e.g. GOBO::Node::ProtoNode--and a coercion, and use that for the attributes should be GOBO::Nodes?
Thank you for any help or advice on this problem!