use Scalar::Util qw(blessed refaddr);
use Sub::Name qw(subname);
+use Try::Tiny;
use base qw(Class::MOP::Object);
-our $VERSION = '1.18';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
__PACKAGE__->meta->add_attribute('name' => (reader => 'name'));
__PACKAGE__->meta->add_attribute('parent' => (
reader => 'parent',
predicate => 'has_hand_optimized_type_constraint',
));
+__PACKAGE__->meta->add_attribute('inlined' => (
+ accessor => 'inlined',
+ predicate => 'has_inlined_type_constraint',
+));
+
sub parents {
my $self;
$self->parent;
}
}
+sub _inline_check {
+ my $self = shift;
+
+ die 'Cannot inline a type constraint check for ' . $self->name
+ unless $self->has_inlined_type_constraint;
+
+ return $self->inlined()->(@_);
+}
+
sub assert_valid {
my ($self, $value) = @_;
return $msg->($value);
}
else {
- $value = (defined $value ? overload::StrVal($value) : 'undef');
+ # have to load it late like this, since it uses Moose itself
+ my $can_partialdump = try {
+ # versions prior to 0.14 had a potential infinite loop bug
+ Class::MOP::load_class('Devel::PartialDump', { -version => 0.14 });
+ 1;
+ };
+ if ($can_partialdump) {
+ $value = Devel::PartialDump->new->dump($value);
+ }
+ else {
+ $value = (defined $value ? overload::StrVal($value) : 'undef');
+ }
return "Validation failed for '" . $self->name . "' with value $value";
}
}
1;
+# ABSTRACT: The Moose Type Constraint metaclass
+
__END__
=pod
-=head1 NAME
-
-Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
-
=head1 DESCRIPTION
This class represents a single type constraint. Moose's built-in type
=item B<< $constraint->coerce($value) >>
-This will attempt to coerce the value to the type. If the type does
+This will attempt to coerce the value to the type. If the type does not
have any defined coercions this will throw an error.
If no coercion can produce a value matching C<$constraint>, the original
See L<Moose/BUGS> for details on reporting bugs.
-=head1 AUTHOR
-
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2006-2010 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
=cut