From: Matt S Trout Date: Tue, 17 Jul 2012 13:42:43 +0000 (+0000) Subject: convert isa and coerce info from external role attributes X-Git-Tag: v1.000000~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a668eb674ab882c664d5b5f7e92e850a0bcb6afa;p=gitmo%2FMoo.git convert isa and coerce info from external role attributes --- diff --git a/Changes b/Changes index 8018c78..173eeb4 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - convert isa and coerce info from external role attributes - clear method cache after metaclass generation to fix autoclean bug 0.091014 - 2012-07-16 diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index fbdd52b..256b191 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -99,7 +99,19 @@ sub _inhale_if_moose { }; $INFO{$role}{requires} = [ $meta->get_required_method_list ]; $INFO{$role}{attributes} = [ - map +($_ => $meta->get_attribute($_)), $meta->get_attribute_list + map +($_ => do { + my $spec = { %{$meta->get_attribute($_)} }; + if ($spec->{isa}) { + require Moose::Util::TypeConstraints; + my $tc = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($spec->{isa}); + my $check = $tc->_compiled_type_constraint; + $spec->{isa} = sub { &$check or die "Type constraint failed for $_[0]" }; + if ($spec->{coerce}) { + $spec->{coerce} = $tc->coercion->_compiled_type_coercion; + } + } + $spec; + }), $meta->get_attribute_list ]; my $mods = $INFO{$role}{modifiers} = []; foreach my $type (qw(before after around)) {