Checking in changes prior to tagging of version 0.93. Changelog diff is:
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint.pm
index bd5f2a9..1e3736d 100644 (file)
@@ -13,7 +13,7 @@ use Sub::Name qw(subname);
 
 use base qw(Class::MOP::Object);
 
-our $VERSION   = '0.83';
+our $VERSION   = '0.93';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -104,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) {
@@ -385,6 +395,13 @@ method returns an explicit C<undef>. If the type is not valid, we call
 C<< $self->get_message($value) >> internally to generate an error
 message.
 
+=item B<< $constraint->assert_valid($value) >>
+
+Like C<check> and C<validate>, this method checks whether C<$value> is
+valid under the constraint.  If it is, it will return true.  If it is not,
+an exception will be thrown with the results of
+C<< $self->get_message($value) >>.
+
 =item B<< $constraint->name >>
 
 Returns the type's name, as provided to the constructor.