getting-there
Stevan Little [Mon, 20 Mar 2006 21:33:41 +0000 (21:33 +0000)]
lib/Moose.pm
lib/Moose/Util/TypeConstraints.pm
t/053_util_find_type_constraint.t

index fdc0903..d8444b5 100644 (file)
@@ -83,7 +83,7 @@ sub import {
                        }
                        else {
                            # otherwise assume it is a constraint
-                           my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options{isa});
+                           my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options{isa})->constraint_code;
                            # if the constraing it not found ....
                            unless (defined $constraint) {
                                # assume it is a foreign class, and make 
index b2c5db7..eb5524d 100644 (file)
@@ -26,7 +26,7 @@ sub import {
     my %TYPES;
     sub find_type_constraint { 
         my $type_name = shift;
-        $TYPES{$type_name}->constraint_code; 
+        $TYPES{$type_name}; 
     }
 
     sub register_type_constraint { 
@@ -82,7 +82,7 @@ sub subtype ($$;$) {
        my ($name, $parent, $check) = @_;
        if (defined $check) {
            my $full_name = caller() . "::${name}";
-               $parent = find_type_constraint($parent) 
+               $parent = find_type_constraint($parent)->constraint_code 
                    unless $parent && ref($parent) eq 'CODE';
                register_type_constraint($name => subname $full_name => sub {                   
                        local $_ = $_[0];
@@ -92,7 +92,7 @@ sub subtype ($$;$) {
        }
        else {
                ($parent, $check) = ($name, $parent);
-               $parent = find_type_constraint($parent) 
+               $parent = find_type_constraint($parent)->constraint_code 
                    unless $parent && ref($parent) eq 'CODE';           
                return subname '__anon_subtype__' => sub {                      
                        local $_ = $_[0];
@@ -109,7 +109,7 @@ sub coerce ($@) {
     my @coercions;
     while (@coercion_map) {
         my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
-        my $constraint = find_type_constraint($constraint_name);
+        my $constraint = find_type_constraint($constraint_name)->constraint_code;
         (defined $constraint)
             || confess "Could not find the type constraint ($constraint_name)";
         push @coercions => [  $constraint, $action ];
index b3dc1e0..00e584a 100644 (file)
@@ -3,11 +3,27 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 12;
 use Test::Exception;
 
 BEGIN {
        use_ok('Moose::Util::TypeConstraints', (':no_export'));
 }
 
-#diag Moose::Util::TypeConstraints::dump_type_constraints();
\ No newline at end of file
+*find_type_constraint = \&Moose::Util::TypeConstraints::find_type_constraint;
+
+foreach my $type_name (qw(
+    Any
+        Value
+            Int
+            Str
+        Ref
+            ScalarRef
+            ArrayRef
+            HashRef
+            CodeRef
+            RegexpRef
+            Object    
+    )) {
+    is(find_type_constraint($type_name)->name, $type_name, '... got the right name for ' . $type_name);
+}
\ No newline at end of file