use Scalar::Util 'blessed';
use Moose::Util::TypeConstraints ();
-our $VERSION = '0.73';
+our $VERSION = '0.93';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
my $self = shift;
my $class = $self->class;
$self->hand_optimized_type_constraint(
- sub {
- blessed( $_[0] ) && $_[0]->isa($class)
+ sub {
+ blessed( $_[0] ) && $_[0]->isa($class)
}
);
}
# 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,
);
}
my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class);
-
+
return unless defined $type;
if ( $type->isa(__PACKAGE__) ) {
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__
Note that it does I<not> return a
C<Moose::Meta::TypeConstraint::Class> object!
+=item B<< $constraint->get_message($value) >>
+
+This is the same as L<Moose::Meta::TypeConstraint/get_message> except
+that it explicitly says C<isa> 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<Moose/BUGS> for details on reporting bugs.
=head1 AUTHOR
=head1 COPYRIGHT AND LICENSE
-Copyright 2006-2009 by Infinity Interactive, Inc.
+Copyright 2006-2010 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>