use Scalar::Util qw(blessed refaddr);
use Sub::Name qw(subname);
+use Try::Tiny;
use base qw(Class::MOP::Object);
-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->( $self, @_ );
+}
+
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";
}
}
unless ( ref $type_constraint ) {
require Moose;
- Carp::confess ("Hand optimized type constraint for " . $self->name . " is not a code reference");
Moose->throw_error("Hand optimized type constraint is not a code reference");
}