You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
packageA;
use Mouse;
use Mouse::Util::TypeConstraints;
subtype 'MultiInt'=>as'ArrayRef[Int]';
coerce 'MultiInt'=> from 'Int'=> via { [ $_ ] };
has 'a'=> ('is'=>'ro', 'isa'=>'MultiInt');
and A->new( 'a' => 1 ) was throwing me this error:
Attribute (a) does not pass the type constraint because: Validation failed for 'MultiInt' with value 1 at
...
Fix:
This documentation page should mention, that coerce should be explicitly requested in attribute definition: has 'a' => ('is' => 'ro', 'isa' => 'MultiInt', 'coerce' => 1);. Good example is Moose documentation that says is explicitly: Moose will never try to coerce a value unless you explicitly ask for it. This is done by setting the coerce attribute option to a true value. While in Mouse this important piece of information is not mentioned in Mouse::Util::TypeConstraints nor Moose::Manual::Attributes doc.
The text was updated successfully, but these errors were encountered:
By reading https://metacpan.org/pod/Mouse::Util::TypeConstraints documentation i felt into the trap and spent good amount of time trying to figure out why following code is not working:
and
A->new( 'a' => 1 )
was throwing me this error:Fix:
This documentation page should mention, that coerce should be explicitly requested in attribute definition:
has 'a' => ('is' => 'ro', 'isa' => 'MultiInt', 'coerce' => 1);
. Good example is Moose documentation that says is explicitly: Moose will never try to coerce a value unless you explicitly ask for it. This is done by setting the coerce attribute option to a true value. While in Mouse this important piece of information is not mentioned in Mouse::Util::TypeConstraints nor Moose::Manual::Attributes doc.The text was updated successfully, but these errors were encountered: