Your complaint is actually that the Elk does exactly what he should do. If you explicitly pass undef as a value, but that value can only be Int , then you should get an error.
So you need to make a choice. You can either change the type (via union) to allow undef as a valid value:
has 'hu', is => 'ro', isa => 'Str | Undef'; has 'ba', is => 'ro', isa => 'Int | Undef';
Or you may just not send undefined values:
my %aa_params = (); $aa_params{hu} = $foo if defined $foo; $aa = AA->new( %aa_params );
Or finally, for some unknown reason, you absolutely can not resist sending invalid undefined values โโfor things that should not be explicitly set to undefined, just write a quick filter:
sub filt_undef { my %hash = @_; return map { $_ => $hash{$_} } grep { defined $hash{$_} } keys %hash; } $aa = AA->new( filt_undef( hu => undef ) );
But it seems rather uncomfortable and terrible.
unpythonic
source share