package Types; use v5.34; use warnings; use Type::Utils qw( as coerce declare from via ); use Types::Common qw( Enum Str ); use Type::Library -base, -declare => qw( CreditType InvoiceType ); declare InvoiceType, as Enum [qw/ ACCPAY ACCREC /]; coerce InvoiceType, from Str, via { #warn "Trying to coerce $_\n"; my %types = ( Invoice => 'ACCREC', SupplierInvoice => 'ACCPAY', ); #my $ret = $types{$_}; #warn "Returning $ret\n"; return $types{$_}; } ; declare CreditType, as Enum [qw/ ACCPAYCREDIT ACCRECCREDIT /]; coerce CreditType, from Str, via { warn "Trying to coerce $_\n"; my %types = ( Credit => 'ACCRECCREDIT', SupplierCredit => 'ACCPAYCREDIT', ); my $ret = $types{$_}; warn "Returning $ret\n"; return $types{$_}; } ; 1;