Subject: | Type::Params; slurpy Dict breaks HasMethods |
The attached code illustrates the problem. It results in
not ok 1 - slurpy Dict w/ HasMethods
# Failed test 'slurpy Dict w/ HasMethods'
# at bug.pl line 18.
# got: 'Can't use string ("send") as a HASH ref while "strict refs" in use at parameter validation for 'main::__ANON__' line 4.
# '
# expected: undef
1..1
# Looks like you failed 1 test of 1.
The generated code has this in it:
Scalar::Util::blessed( $_->{"encoder"} )
and not grep( !$_->{"encoder"}->can( $_ ), qw/send/ );
The $_ in the grep code can't be both the grep variable and the
outer $_. This is generated by this code in Type::Tiny::Duck::_build_inlined:
qq{ Scalar::Util::blessed($var) and not grep(!$var->can(\$_), qw/@methods/) };
which assumes $var isn't $_. Here's a possible fix (works for me)
qq{ Scalar::Util::blessed($var) and not do { my \$var = $var; grep(!\$var->can(\$_), qw/@methods/) } };
Thanks,
Diab
Subject: | bug.pl |
use Type::Params -all;
use Types::Standard -all;
use Test::More;
use Test::Fatal;
{
package Foo;
sub new { bless {}, shift }
sub send { }
};
is(
exception {
validate( [ encoder => Foo->new ],
slurpy Dict [ encoder => HasMethods ['send'] ] );
},
undef,
"slurpy Dict w/ HasMethods"
);
done_testing;