Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass |
new(%options)
equals($type_name_or_object)
is_subtype_of($type_name_or_object)
is_a_type_of($type_name_or_object)
coerce($value)
assert_coerce($value)
check($value)
validate($value)
assert_valid($value)
get_message($value)
create_child_type(%options)
Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
version 2.1605
This class represents a single type constraint. Moose's built-in type constraints, as well as constraints you define, are all stored in a the Moose::Meta::TypeConstraint::Registry manpage object as objects of this class.
Moose::Meta::TypeConstraint
is a subclass of the Class::MOP::Object manpage.
new(%options)
This creates a new type constraint based on the provided %options
:
Moose::Meta::TypeConstraint
object which is the parent type for
the type being created. This is optional.
"$_"
or "$_[0]"
.
This is optional.
equals($type_name_or_object)
Returns true if the supplied name or type object is the same as the current type.
is_subtype_of($type_name_or_object)
Returns true if the supplied name or type object is a parent of the current type.
is_a_type_of($type_name_or_object)
Returns true if the given type is the same as the current type, or is
a parent of the current type. This is a shortcut for checking
equals
and is_subtype_of
.
coerce($value)
This will attempt to coerce the value to the type. If the type does not have any defined coercions this will throw an error.
If no coercion can produce a value matching $constraint
, the original
value is returned.
assert_coerce($value)
This method behaves just like coerce
, but if the result is not valid
according to $constraint
, an error is thrown.
check($value)
Returns true if the given value passes the constraint for the type.
validate($value)
This is similar to check
. However, if the type is valid then the
method returns an explicit undef
. If the type is not valid, we call
$self->get_message($value)
internally to generate an error
message.
assert_valid($value)
Like check
and validate
, this method checks whether $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
$self->get_message($value)
.
Returns the type's name, as provided to the constructor.
Returns the type's parent, as provided to the constructor, if any.
Returns true if the type has a parent type.
Returns all of the types parents as an list of type constraint objects.
Returns the type's constraint, as provided to the constructor.
get_message($value)
This generates a method for the given value. If the type does not have an explicit message, we generate a default message.
Returns true if the type has a message.
Returns the type's message as a subroutine reference.
Returns the type's the Moose::Meta::TypeCoercion manpage object, if one exists.
Returns true if the type has a coercion.
Returns true if this type constraint can be inlined. A type constraint which subtypes an inlinable constraint and does not add an additional constraint ``inherits'' its parent type's inlining.
create_child_type(%options)
This returns a new type constraint of the same class using the
provided %options
. The parent
option will be the current type.
This method exists so that subclasses of this class can override this behavior and change how child types are created.
See Moose/BUGS for details on reporting bugs.
This software is copyright (c) 2006 by Infinity Interactive, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass |