first go at a fix for reported bug
John Napiorkowski [Fri, 30 Sep 2011 20:58:16 +0000 (16:58 -0400)]
lib/MooseX/Types/Structured.pm
t/bug-mixed-stringy.t [new file with mode: 0644]

index 3d9fb76..94dde0d 100644 (file)
@@ -758,6 +758,14 @@ Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint(
                 $overflow_handler = pop @type_constraints;
             }
 
+            my $length = $#type_constraints;
+            foreach my $idx (0..$length) {
+                unless(blessed $type_constraints[$idx]) {
+                    ($type_constraints[$idx] = find_type_constraint($type_constraints[$idx]))
+                      || die "$type_constraints[$idx] is not a registered type";
+                }
+            }
+
             my (@checks, @optional, $o_check, $is_compiled);
             return sub {
                 my ($values, $err) = @_;
@@ -838,7 +846,13 @@ Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint(
               && $type_constraints[-1]->isa('MooseX::Types::Structured::OverflowHandler')) {
                 $overflow_handler = pop @type_constraints;
             }
-            my (%type_constraints) = @type_constraints;
+            my %type_constraints = @type_constraints;
+            foreach my $key (keys %type_constraints) {
+                unless(blessed $type_constraints{$key}) {
+                    ($type_constraints{$key} = find_type_constraint($type_constraints{$key}))
+                      || die "$type_constraints{$key} is not a registered type";
+                }
+            }
 
             my (%check, %optional, $o_check, $is_compiled);
             return sub {
diff --git a/t/bug-mixed-stringy.t b/t/bug-mixed-stringy.t
new file mode 100644 (file)
index 0000000..9a4682a
--- /dev/null
@@ -0,0 +1,53 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+{
+  package Test::MooseX::Types::Structured::StringyBug;
+
+  use Moose;
+  use MooseX::Types::Moose qw(Str);
+  use MooseX::Types::Structured qw(Tuple Dict);
+  use Moose::Util::TypeConstraints;
+
+  subtype "TestStringTypes::SubType",
+    as Str,
+    where { 1 };
+
+  has 'attr1' => (
+    is  => 'ro',
+    required => 1,
+    isa => Dict[
+      foo1 => Str,
+      foo2 => "Int",
+      foo3 => "TestStringTypes::SubType",
+    ],
+  );
+
+  has 'attr2' => (
+    is  => 'ro',
+    required => 1,
+    isa => Tuple[
+      Str,
+      "Int",
+      "TestStringTypes::SubType",
+    ],
+  );
+}
+
+my %init_args = (
+  attr1 => {
+    foo1 => 'a',
+    foo2 => 2,
+    foo3 => 'c',
+  },
+  attr2 => ['a', 2, 'c'],
+);
+
+ok(
+  Test::MooseX::Types::Structured::StringyBug->new(%init_args),
+  'Made a class with mixed constraint types',
+);
+
+done_testing;