sub find_or_parse_type_constraint ($) {
my $type_constraint_name = shift;
-
- return $REGISTRY->get_type_constraint($type_constraint_name)
- if $REGISTRY->has_type_constraint($type_constraint_name);
-
my $constraint;
-
- if (_detect_type_constraint_union($type_constraint_name)) {
+
+ if ($constraint = find_type_constraint($type_constraint_name)) {
+ return $constraint;
+ } elsif (_detect_type_constraint_union($type_constraint_name)) {
$constraint = create_type_constraint_union($type_constraint_name);
- }
- elsif (_detect_parameterized_type_constraint($type_constraint_name)) {
+ } elsif (_detect_parameterized_type_constraint($type_constraint_name)) {
$constraint = create_parameterized_type_constraint($type_constraint_name);
} else {
return;
}
-
+
$REGISTRY->add_type_constraint($constraint);
return $constraint;
}
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 8;
use Test::Exception;
BEGIN {
} '... create bare subtype fine';
my $numb3rs = find_type_constraint('Numb3rs');
-isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
\ No newline at end of file
+isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
+
+# subtype with unions
+
+{
+ package Test::Moose::Meta::TypeConstraint::Union;
+
+ use overload '""' => sub { 'Broken|Test' }, fallback => 1;
+ use Moose;
+
+ extends 'Moose::Meta::TypeConstraint';
+}
+
+ok my $dummy_instance = Test::Moose::Meta::TypeConstraint::Union->new
+ => "Created Instance";
+
+isa_ok $dummy_instance, 'Test::Moose::Meta::TypeConstraint::Union'
+ => 'isa correct type';
+
+is "$dummy_instance", "Broken|Test"
+ => "Got expected stringification result";
+
+ok my $subtype1 = subtype('New1', as $dummy_instance)
+ => "made a subtype";
+
+ok my $subtype2 = subtype('New2', as $subtype1)
+ => "made another subtype";