use base qw(Class::MOP::Object);
-our $VERSION = '0.83';
+our $VERSION = '0.96';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
}
}
+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) {
=head1 DESCRIPTION
This class represents a single type constraint. Moose's built-in type
-constraints, as well as constraints you define, are all store in a
+constraints, as well as constraints you define, are all stored in a
L<Moose::Meta::TypeConstraint::Registry> object as objects of this
class.
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.
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
-exception. If you find a bug please either email me, or add the bug
-to cpan-RT.
+See L<Moose/BUGS> for details on reporting bugs.
=head1 AUTHOR
=head1 COPYRIGHT AND LICENSE
-Copyright 2006-2009 by Infinity Interactive, Inc.
+Copyright 2006-2010 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>