X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint.pm;h=1e3736d6e39e1b6552d59b272e5dcb5ff761f248;hb=6d0815b59db07f71cdbfd978ed6f574e57e2b3ea;hp=64b266d7567541efa0d1e3cca8b280324758c366;hpb=dbe21639d532a07229d0beeffafafba66a7e26f5;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 64b266d..1e3736d 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -13,7 +13,7 @@ use Sub::Name qw(subname); use base qw(Class::MOP::Object); -our $VERSION = '0.79'; +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. 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 and C, 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.