From: Graham Knop Date: Fri, 22 Feb 2013 23:20:09 +0000 (-0500) Subject: apply coercion to subtype of inflated moose type when using %TYPE_MAP X-Git-Tag: v1.001000~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3985eb35079aa4093a80393648b42efc31cf4a13;p=gitmo%2FMoo.git apply coercion to subtype of inflated moose type when using %TYPE_MAP --- diff --git a/lib/Moo/HandleMoose.pm b/lib/Moo/HandleMoose.pm index cb2c2a2..c7c29f0 100644 --- a/lib/Moo/HandleMoose.pm +++ b/lib/Moo/HandleMoose.pm @@ -99,22 +99,24 @@ sub inject_real_metaclass_for { delete $spec{index}; $spec{is} = 'ro' if $spec{is} eq 'lazy' or $spec{is} eq 'rwp'; delete $spec{asserter}; + my $coerce = $spec{coerce}; if (my $isa = $spec{isa}) { my $tc = $spec{isa} = do { if (my $mapped = $TYPE_MAP{$isa}) { - $mapped->(); + my $type = $mapped->(); + $coerce ? $type->create_child_type(name => $type->name) : $type; } else { Moose::Meta::TypeConstraint->new( constraint => sub { eval { &$isa; 1 } } ); } }; - if (my $coerce = $spec{coerce}) { + if ($coerce) { $tc->coercion(Moose::Meta::TypeCoercion->new) ->_compiled_type_coercion($coerce); $spec{coerce} = 1; } - } elsif (my $coerce = $spec{coerce}) { + } elsif ($coerce) { my $attr = perlstring($name); my $tc = Moose::Meta::TypeConstraint->new( constraint => sub { die "This is not going to work" },