adding ->parent_registry to the TC registry object
Stevan Little [Fri, 14 Sep 2007 05:39:42 +0000 (05:39 +0000)]
lib/Moose/Meta/TypeConstraint/Registry.pm
lib/Moose/Util/TypeConstraints.pm

index c1414d0..ae6429a 100644 (file)
@@ -13,6 +13,12 @@ our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Class::MOP::Object';
 
+__PACKAGE__->meta->add_attribute('parent_registry' => (
+    reader    => 'get_parent_registry',
+    writer    => 'set_parent_registry',    
+    predicate => 'has_parent_registry',    
+));
+
 __PACKAGE__->meta->add_attribute('type_constraints' => (
     reader  => 'type_constraints',
     default => sub { {} }
@@ -39,6 +45,15 @@ sub add_type_constraint {
     $self->type_constraints->{$type->name} = $type;
 }
 
+sub find_type_constraint {
+    my ($self, $type_name) = @_;
+    return $self->get_type_constraint($type_name)
+        if $self->has_type_constraint($type_name);
+    return $self->get_parent_registry->find_type_constraint($type_name)
+        if $self->has_parent_registry;
+    return;
+}
+
 1;
 
 __END__
@@ -60,13 +75,21 @@ Moose::Meta::TypeConstraint::Registry
 
 =item B<new>
 
+=item B<get_parent_registry>
+
+=item B<set_parent_registry ($registry)>
+    
+=item B<has_parent_registry>
+
 =item B<type_constraints>
 
-=item B<has_type_constraint>
+=item B<has_type_constraint ($type_name)>
+
+=item B<get_type_constraint ($type_name)>
 
-=item B<get_type_constraint>
+=item B<add_type_constraint ($type)>
 
-=item B<add_type_constraint>
+=item B<find_type_constraint ($type_name)>
 
 =back
 
index 5d01e2c..cc36e8e 100644 (file)
@@ -17,20 +17,20 @@ our $AUTHORITY = 'cpan:STEVAN';
 # predeclaration ensures the prototypes are in scope when consumers are
 # compiled
 
-sub find_type_constraint ($);
-sub _create_type_constraint ($$$;$$);
-sub _install_type_coercions ($$);
+sub find_type_constraint         ($);
+sub _create_type_constraint      ($$$;$$);
+sub _install_type_coercions      ($$);
 sub create_type_constraint_union (@);
-sub type ($$;$$);
-sub subtype ($$;$$$);
-sub coerce ($@);
-sub as      ($);
-sub from    ($);
-sub where   (&);
-sub via     (&);
-sub message     (&);
-sub optimize_as (&);
-sub enum ($;@);
+sub type                         ($$;$$);
+sub subtype                      ($$;$$$);
+sub coerce                       ($@);
+sub as                           ($);
+sub from                         ($);
+sub where                        (&);
+sub via                          (&);
+sub message                      (&);
+sub optimize_as                  (&);
+sub enum                         ($;@);
 
 use Moose::Meta::TypeConstraint;
 use Moose::Meta::TypeCoercion;