j1n3l0 has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone,
Can anyone explain why this coersion does not appear to work:
use 5.026; use Test::Most; { package Thing; use Moose; use Types::Standard qw( Bool Str ); has delete => ( coerce => 1, is => 'ro', isa => Str->plus_coercions( Bool, q{ $_ ? 'yes' : 'no' } ), ); } { cmp_methods( new_ok( Thing => [ delete => 1 ] ), [ delete => 'yes' ], 'attributes are coerced as expected', ); } done_testing;
I get the following output:
# Failed test 'attributes are coerced as expected' # at t/coercion.t line 16. # Compared $data->delete # got : '1' # expect : 'yes' # Looks like you failed 1 test of 2.
I was following the instructions documented here. Any and all assistance is appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cannot coerce from Bool to Str
by choroba (Cardinal) on Sep 06, 2018 at 14:48 UTC | |
|
Re: Cannot coerce from Bool to Str
by tobyink (Canon) on Sep 08, 2018 at 20:39 UTC |