X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FClass.pm;h=bbd4c2eca0908957d56f3bd0f9a73aa83572c1b1;hb=e8ec69b65dab6111b542ca1e9ee7bd3cfb0cbdd5;hp=bc0bacb55859db5bba862a9ba4b1534996dc1fb7;hpb=a3319906531cef2b41a87138e75461ced7a3394b;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Class.pm b/lib/Moose/Meta/TypeConstraint/Class.pm index bc0bacb..bbd4c2e 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.73_01'; +our $VERSION = '0.84'; $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,8 +49,8 @@ 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__" ) } 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__ @@ -167,11 +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 +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.