X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FRegistry.pm;h=f316c8186085e1eb8816fc890f10fceca43e170b;hb=330dbb079ab3e4ff26fb694c232b9c86b2d19161;hp=c1414d03d914f90fcbada282c7826fd8f7db1279;hpb=22aed3c0fbe058c938ecb2834eb8a45c46d4e8ed;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Registry.pm b/lib/Moose/Meta/TypeConstraint/Registry.pm index c1414d0..f316c81 100644 --- a/lib/Moose/Meta/TypeConstraint/Registry.pm +++ b/lib/Moose/Meta/TypeConstraint/Registry.pm @@ -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. +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 +=item B + +=item B + +=item B + =item B -=item B +=item B + +=item B -=item B +=item B -=item B +=item B =back @@ -82,7 +111,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006, 2007 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L