in reply to Cannot coerce from Bool to Str
As per choroba's answer, coercions are only triggered if the value fails the type constraint, and "1" is a valid string.
You could use Enum["yes","no"] as your type constraint instead of Str.
use 5.026; use Test::Most; { package Thing; use Moose; use Types::Standard qw( Bool Enum ); has delete => ( coerce => 1, is => 'ro', isa => Enum->of(qw/yes no/)->plus_coercions( Bool, q{ $_ ? +'yes' : 'no' } ), ); } { cmp_methods( new_ok( Thing => [ delete => 1 ] ), [ delete => 'yes' ], 'attributes are coerced as expected', ); } done_testing;
|
|---|