X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint.pm;h=298656fa10a64bf764da10a0d05647a4cc00bc0b;hb=c24269b37a781e0358c3682e8717cfd539269550;hp=4b78f5420e8a1fa97176e4056f2f32c4f0ebc60a;hpb=d03bd989b97597428b460d7f9a021e2931893fa0;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 4b78f54..298656f 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -9,10 +9,11 @@ use overload '""' => sub { shift->name }, # stringify to tc name fallback => 1; use Scalar::Util qw(blessed refaddr); +use Sub::Name qw(subname); use base qw(Class::MOP::Object); -our $VERSION = '0.75_01'; +our $VERSION = '0.88'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -103,6 +104,16 @@ sub validate { } } +sub assert_valid { + my ($self, $value) = @_; + + my $error = $self->validate($value); + return 1 if ! defined $error; + + require Moose; + Moose->throw_error($error); +} + sub get_message { my ($self, $value) = @_; if (my $msg = $self->message) { @@ -234,7 +245,7 @@ sub _compile_subtype { if ( $check == $null_constraint ) { return $optimized_parent; } else { - return Class::MOP::subname($self->name, sub { + return subname($self->name, sub { return undef unless $optimized_parent->($_[0]); my (@args) = @_; local $_ = $args[0]; @@ -245,7 +256,7 @@ sub _compile_subtype { # general case, check all the constraints, from the first parent to ourselves my @checks = @parents; push @checks, $check if $check != $null_constraint; - return Class::MOP::subname($self->name => sub { + return subname($self->name => sub { my (@args) = @_; local $_ = $args[0]; foreach my $check (@checks) { @@ -261,7 +272,7 @@ sub _compile_type { return $check if $check == $null_constraint; # Item, Any - return Class::MOP::subname($self->name => sub { + return subname($self->name => sub { my (@args) = @_; local $_ = $args[0]; $check->(@args);