From: Dave Rolsky Date: Sat, 29 Sep 2012 01:50:48 +0000 (-0500) Subject: Work in progress to make Moose accept Type::Constraint objects for the isa param X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoose.git;a=commitdiff_plain;h=30718b50031e1d5202f509cb83abaa2f904a3e4b Work in progress to make Moose accept Type::Constraint objects for the isa param I have tests in the Type distro, but none in Moose. I still need to make this work with does as well. --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 46a8412..c126884 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -231,12 +231,14 @@ sub clone_and_inherit_options { if (blessed($options{isa}) && $options{isa}->isa('Moose::Meta::TypeConstraint')) { $type_constraint = $options{isa}; } + elsif (blessed($options{isa}) && Moose::Util::does_role($options{isa}, 'Type::Constraint::Role::Interface')) { + $type_constraint = $options{isa}; + } else { $type_constraint = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($options{isa}, { package_defined_in => $options{definition_context}->{package} }); (defined $type_constraint) || $self->throw_error("Could not find the type constraint '" . $options{isa} . "'", data => $options{isa}); } - $options{type_constraint} = $type_constraint; } @@ -374,6 +376,14 @@ sub _process_isa_option { && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) { $options->{type_constraint} = $options->{isa}; } + elsif ( + blessed( $options->{isa} ) + && Moose::Util::does_role( + $options->{isa}, 'Type::Constraint::Role::Interface' + ) + ) { + $options->{type_constraint} = $options->{isa}; + } else { $options->{type_constraint} = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint(