X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FRegistry.pm;h=abdc23d0d69806ea551eec71434480b410599a15;hb=e1d6f0a3c8cee0350b97695a2307af7004a1eb97;hp=b4229c1fcf1d98d920288119119a8eca6dc83733;hpb=0779da922a64aa891bc2708b6fc8de4d4fdffa11;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Registry.pm b/lib/Moose/Meta/TypeConstraint/Registry.pm index b4229c1..abdc23d 100644 --- a/lib/Moose/Meta/TypeConstraint/Registry.pm +++ b/lib/Moose/Meta/TypeConstraint/Registry.pm @@ -6,9 +6,10 @@ use warnings; use metaclass; use Scalar::Util 'blessed'; -use Carp 'confess'; +use Carp 'confess'; # FIXME Moose->throw_error -our $VERSION = '0.56'; +our $VERSION = '0.61'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Object'; @@ -32,16 +33,19 @@ sub new { sub has_type_constraint { my ($self, $type_name) = @_; - exists $self->type_constraints->{$type_name} ? 1 : 0 + ($type_name and exists $self->type_constraints->{$type_name}) ? 1 : 0 } sub get_type_constraint { my ($self, $type_name) = @_; + return unless defined $type_name; $self->type_constraints->{$type_name} } sub add_type_constraint { my ($self, $type) = @_; + confess("No type supplied / type is not a valid type constraint") + unless ($type && blessed $type && $type->isa('Moose::Meta::TypeConstraint')); $self->type_constraints->{$type->name} = $type; } @@ -93,8 +97,15 @@ base Moose registry and base Moose types will automagically be found too). =item B +Returns a type constraint object from the registry by name. Will return +false if the supplied type name cannot be found. + =item B +Adds a type constraint object to the registry. Will throw an exception if +no type is supplied, or the supplied object does not inherit from +L + =item B =back