$code .= "if (exists \$args->{'$from'}) {\n";
if ($attr->should_coerce && $attr->type_constraint) {
- $code .= "my \$value = Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{type_constraint}, \$attrs[$index]->{type_constraint}, \$args->{'$from'});\n";
+ $code .= "my \$value = Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{type_constraint}, \$args->{'$from'});\n";
}
else {
$code .= "my \$value = \$args->{'$from'};\n";
$code .= "my \$value = ";
if ($attr->should_coerce && $attr->type_constraint) {
- $code .= "Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{type_constraint}, \$attrs[$index]->{type_constraint}, ";
+ $code .= "Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{type_constraint}, ";
}
if ($attr->has_builder) {
# this is an original method for Mouse
sub typecast_constraints {
my($class, $pkg, $types, $value) = @_;
+ Carp::croak("wrong arguments count") unless @_==4;
local $_;
for my $type ( split /\|/, $types ) {
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests => 2;
+use Mouse::Util::TypeConstraints;
+
+subtype 'Foo', where => sub { $_->isa('A') };
+
+{
+ package A;
+ use Mouse;
+ has data => ( is => 'rw', isa => 'Str' );
+}
+
+{
+ package B;
+ use Mouse;
+ has a => ( is => 'rw', isa => 'Foo', coerce => 1 );
+}
+
+isa_ok(B->new(a => A->new()), 'B');
+B->meta->make_immutable;
+isa_ok(B->new(a => A->new()), 'B');
+