some refactoring of handles
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint / Registry.pm
index c1414d0..f316c81 100644 (file)
@@ -8,11 +8,17 @@ use metaclass;
 use Scalar::Util 'blessed';
 use Carp         'confess';
 
-our $VERSION   = '0.01';
+our $VERSION   = '0.55';
 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__
@@ -48,10 +63,16 @@ __END__
 
 =head1 NAME
 
-Moose::Meta::TypeConstraint::Registry
+Moose::Meta::TypeConstraint::Registry - registry for type constraints
 
 =head1 DESCRIPTION
 
+This module is currently only use internally by L<Moose::Util::TypeConstraints>. 
+It can be used to create your own private type constraint registry as well, but 
+the details of that are currently left as an exercise to the reader. (One hint: 
+You can use the 'parent_registry' feature to connect your private version with the 
+base Moose registry and base Moose types will automagically be found too).
+
 =head1 METHODS
 
 =over 4
@@ -60,13 +81,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
 
@@ -82,7 +111,7 @@ Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006, 2007 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>