From: Stevan Little Date: Wed, 23 Aug 2006 20:17:05 +0000 (+0000) Subject: is_a_type_of for mst; X-Git-Tag: 0_12~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b26e162e732896d5965cda7e6f633e9718855944;p=gitmo%2FMoose.git is_a_type_of for mst; --- diff --git a/Changes b/Changes index dc8501c..286fae2 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,10 @@ Revision history for Perl extension Moose * Moose::Object - added &dump method, cause it makes all out lives easier really. + + * Moose::Meta::TypeConstraint + - added the &is_a_type_of method to check both the current + and the subtype of a method (similar to &isa with classes) 0.11 Wed. July 12, 2006 * Moose diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index e2109c6..1ae35e2 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -9,7 +9,7 @@ use Sub::Name 'subname'; use Carp 'confess'; use Scalar::Util 'blessed'; -our $VERSION = '0.03'; +our $VERSION = '0.04'; __PACKAGE__->meta->add_attribute('name' => (reader => 'name' )); __PACKAGE__->meta->add_attribute('parent' => (reader => 'parent' )); @@ -78,6 +78,11 @@ sub validate { } } +sub is_a_type_of { + my ($self, $type_name) = @_; + ($self->name eq $type_name || $self->is_subtype_of($type_name)); +} + sub is_subtype_of { my ($self, $type_name) = @_; my $current = $self; @@ -187,7 +192,12 @@ If you wish to use features at this depth, please come to the =item B -=item B +=item B + +This checks the current type name, and if it does not match, +checks if it is a subtype of it. + +=item B =item B