From: Matt S Trout Date: Wed, 4 Apr 2012 09:11:11 +0000 (+0000) Subject: inflation of isa constraints X-Git-Tag: v0.009_015~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=37de175a9bc9ce0398a0bcdd21eaa00704fef4c4;p=gitmo%2FMoo.git inflation of isa constraints --- diff --git a/Changes b/Changes index c7143a0..80cdb94 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ - Some level of attributes and methods for both classes and roles - Required methods in roles - Method modifiers in roles (they're already applied in classes) + - Type constraints 0.009014 - 2012-03-29 - Split Role::Tiny out into its own dist diff --git a/lib/Moo/HandleMoose.pm b/lib/Moo/HandleMoose.pm index 97b6c49..372bc12 100644 --- a/lib/Moo/HandleMoose.pm +++ b/lib/Moo/HandleMoose.pm @@ -3,6 +3,8 @@ package Moo::HandleMoose; use strictures 1; use Moo::_Utils; +our %TYPE_MAP; + sub import { inject_all() } sub inject_all { @@ -42,6 +44,18 @@ sub inject_real_metaclass_for { foreach my $name (keys %$attr_specs) { my %spec = %{$attr_specs->{$name}}; $spec{is} = 'ro' if $spec{is} eq 'lazy'; + if (my $isa = $spec{isa}) { + $spec{isa} = do { + if (my $mapped = $TYPE_MAP{$isa}) { + _load_module($mapped->[1]) if $mapped->[1]; + Moose::Util::TypeConstraints::find_type_constraint($mapped->[0]) + } else { + Moose::Meta::TypeConstraint->new( + constraint => sub { eval { &$isa; 1 } } + ); + } + }; + } push @attrs, $meta->add_attribute($name => %spec); } }