X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FClass.pm;h=b350fe585f2d0694fd57f74c9fa63d7827818ce5;hb=57385c0daf41b64d818535240abbd2c510d11984;hp=5148a5c8f6f335aa872c4e09e7636cc25dfdb449;hpb=38bf0e17a192755de0bee58818581b058d3b8957;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Class.pm b/lib/Moose/Meta/TypeConstraint/Class.pm index 5148a5c..b350fe5 100644 --- a/lib/Moose/Meta/TypeConstraint/Class.pm +++ b/lib/Moose/Meta/TypeConstraint/Class.pm @@ -7,7 +7,7 @@ use metaclass; use Scalar::Util 'blessed'; use Moose::Util::TypeConstraints (); -our $VERSION = '0.72'; +our $VERSION = '1.01'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -33,8 +33,8 @@ sub _create_hand_optimized_type_constraint { my $self = shift; my $class = $self->class; $self->hand_optimized_type_constraint( - sub { - blessed( $_[0] ) && $_[0]->isa($class) + sub { + blessed( $_[0] ) && $_[0]->isa($class) } ); } @@ -49,10 +49,10 @@ sub parents { # if anybody thinks this problematic please discuss on IRC. # a possible fix is to add by attr indexing to the type registry to find types of a certain property # regardless of their name - Moose::Util::TypeConstraints::find_type_constraint($_) - || + Moose::Util::TypeConstraints::find_type_constraint($_) + || __PACKAGE__->new( class => $_, name => "__ANON__" ) - } $self->class->meta->superclasses, + } Class::MOP::class_of($self->class)->superclasses, ); } @@ -84,7 +84,7 @@ sub is_subtype_of { } my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class); - + return unless defined $type; if ( $type->isa(__PACKAGE__) ) { @@ -106,6 +106,18 @@ sub create_child_type { return Moose::Meta::TypeConstraint->new(@args, parent => $self); } +sub get_message { + my $self = shift; + my ($value) = @_; + + if ($self->has_message) { + return $self->SUPER::get_message(@_); + } + + $value = (defined $value ? overload::StrVal($value) : 'undef'); + return "Validation failed for '" . $self->name . "' failed with value $value (not isa " . $self->class . ")"; +} + 1; __END__ @@ -151,7 +163,7 @@ Returns the class name associated with the constraint. Returns all the type's parent types, corresponding to its parent classes. -=item B<< $constraint->is_a_subtype_of($type_name_or_object) >> +=item B<< $constraint->is_subtype_of($type_name_or_object) >> If the given type is also a class type, then this checks that the type's class is a subclass of the other type's class. @@ -167,13 +179,17 @@ as its parent. Note that it does I return a C object! +=item B<< $constraint->get_message($value) >> + +This is the same as L except +that it explicitly says C was checked. This is to help users deal +with accidentally autovivified type constraints. + =back =head1 BUGS -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. +See L for details on reporting bugs. =head1 AUTHOR @@ -181,7 +197,7 @@ Yuval Kogman Enothingmuch@cpan.orgE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2009 by Infinity Interactive, Inc. +Copyright 2006-2010 by Infinity Interactive, Inc. L