Moose implicitly creates type constraints for roles and classes, which
means that isa => 'SomeRole' accepts an object that does the role. For
increased compatibility, create these constraints when injecting the
fake meta class.
Class::MOP::store_metaclass_by_name(
$name, bless({ name => $name }, 'Moo::HandleMoose::FakeMetaClass')
);
+ require Moose::Util::TypeConstraints;
+ if ($Moo::Role::INFO{$name}) {
+ Moose::Util::TypeConstraints::find_or_create_does_type_constraint($name);
+ } else {
+ Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($name);
+ }
}
{
--- /dev/null
+use strictures 1;
+use Test::More;
+
+use Moose::Util::TypeConstraints qw(find_type_constraint);
+
+{
+ package TestRole;
+ use Moo::Role;
+}
+
+{
+ package TestClass;
+ use Moo;
+
+ with 'TestRole';
+}
+
+my $o = TestClass->new;
+
+foreach my $name (qw(TestClass TestRole)) {
+ ok !find_type_constraint($name), "No $name constraint created without Moose loaded";
+}
+note "Loading Moose";
+require Moose;
+
+foreach my $name (qw(TestClass TestRole)) {
+ my $tc = find_type_constraint($name);
+ isa_ok $tc, 'Moose::Meta::TypeConstraint', "$name constraint"
+ and ok $tc->check($o), "TestClass object passes $name constraint";
+}
+
+done_testing;