7 use Moose::Util::TypeConstraints;
11 use Moose::Util::TypeConstraints;
14 subtype 'Foo2', as 'Str';
18 { package Foo5; use Moose; }
19 { package Foo6; use Moose::Role; }
20 { package IsaAttr; use Moose; has foo => (is => 'ro', isa => 'Foo7'); }
21 { package DoesAttr; use Moose; has foo => (is => 'ro', does => 'Foo8'); }
27 [1, sub { type $_[0] }, 'type'],
28 [1, sub { subtype $_[0], as 'Str' }, 'subtype'],
29 [1, sub { class_type $_[0] }, 'class_type'],
30 [1, sub { role_type $_[0] }, 'role_type'],
31 # should these two die?
32 [0, sub { eval "package $_[0]; use Moose; 1" || die $@ }, 'use Moose'],
33 [0, sub { eval "package $_[0]; use Moose::Role; 1" || die $@ }, 'use Moose::Role'],
36 eval <<CLASS || die $@;
39 has foo => (is => 'ro', isa => '$_[0]');
45 eval <<CLASS || die $@;
48 has foo => (is => 'ro', does => '$_[0]');
51 }, 'does => "Thing"'],
56 my $type = find_type_constraint($type_name);
57 for my $check (@checks) {
58 my ($should_fail, $code, $desc) = @$check;
61 if overriding_with_equivalent_type($type, $desc);
62 unload_class($type_name);
66 exception { $code->($type_name) },
67 qr/^The type constraint '$type_name' has already been created in [\w:]+ and cannot be created again in [\w:]+/,
68 "trying to override $type_name via '$desc' should die"
73 exception { $code->($type_name) },
75 "trying to override $type_name via '$desc' should do nothing"
78 is($type, find_type_constraint($type_name), "type didn't change");
84 my $meta = Class::MOP::class_of($class);
86 $meta->add_package_symbol('@ISA', []);
87 $meta->remove_package_symbol('&'.$_)
88 for $meta->list_all_package_symbols('CODE');
90 Class::MOP::remove_metaclass_by_name($class);
93 sub overriding_with_equivalent_type {
94 my ($type, $desc) = @_;
95 if ($type->isa('Moose::Meta::TypeConstraint::Class')) {
96 return 1 if $desc eq 'use Moose'
97 || $desc eq 'class_type'
98 || $desc eq 'isa => "Thing"';
100 if ($type->isa('Moose::Meta::TypeConstraint::Role')) {
101 return 1 if $desc eq 'use Moose::Role'
102 || $desc eq 'role_type'
103 || $desc eq 'does => "Thing"';
110 check_conflicts($_) for map { "Foo$_" } 1..8;