Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
| Use Case | Command | Description |
|---|---|---|
| 📦 Create a new type constraint | Moose::Meta::TypeConstraint->new(%options) | Create a type constraint with name, parent, constraint sub, message, coercion, inlining |
| 🔍 Check if value is valid | $constraint->check($value) | Returns true if value passes constraint |
| 🔄 Coerce a value | $constraint->coerce($value) | Attempt to coerce value to type; returns original if no coercion applies |
| ✅ Validate and return message | $constraint->validate($value) | Returns explicit undef if valid, or error message generated by get_message |
| 🚨 Assert valid or throw | $constraint->assert_valid($value) | Returns true if valid, throws exception with message otherwise |
| 🧬 Check subtype relationship | $constraint->is_subtype_of($type) | Returns true if given type is a parent of current type |
| 🔗 Get parent type | $constraint->parent | Returns parent type constraint object, if any |
| 📝 Get constraint subroutine | $constraint->constraint | Returns the subroutine that implements the constraint check |
| 🏗️ Create child type | $constraint->create_child_type(%options) | Returns new type constraint of same class, with this as parent |
version 2.2200
This class represents a single type constraint. Moose's built-in type constraints, as well as constraints you define, are all stored in a Moose::Meta::TypeConstraint::Registry object as objects of this class.
"Moose::Meta::TypeConstraint" is a subclass of Class::MOP::Object.
Moose::Meta::TypeConstraint->new(%options) — Creates a new type constraint. Options:
name — The constraint name. Defaults to "__ANON__".parent — A Moose::Meta::TypeConstraint object (optional).constraint — Subroutine reference implementing the constraint check. Defaults to always true.message — Subroutine reference for error message generation (optional).coercion — A Moose::Meta::TypeCoercion object (optional).inlined — Subroutine returning a string for inlining. Called as method with variable name to test (optional).inline_environment — Hash reference of variables to close over (keys are variable names, values are references).$constraint->equals($type_name_or_object) — Returns true if the supplied name or type object is the same as the current type.$constraint->is_subtype_of($type_name_or_object) — Returns true if the supplied name or type object is a parent of the current type.$constraint->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. Shortcut for "equals" and "is_subtype_of".$constraint->coerce($value) — Attempts to coerce the value to the type. If no coercion defined, throws error. If no coercion can produce a matching value, returns the original value.$constraint->assert_coerce($value) — Behaves like "coerce", but if result is not valid, throws an error.$constraint->check($value) — Returns true if the value passes the constraint.$constraint->validate($value) — Similar to "check". If valid, returns explicit undef. If invalid, calls $self->get_message($value) to generate error message.$constraint->assert_valid($value) — Like "check" and "validate": if valid, returns true; if invalid, throws exception with message from get_message.$constraint->name — Returns the type's name as provided to constructor.$constraint->parent — Returns the type's parent, if any.$constraint->has_parent — Returns true if the type has a parent type.$constraint->parents — Returns all parent types as a list of type constraint objects.$constraint->constraint — Returns the constraint subroutine reference.$constraint->get_message($value) — Generates an error message. Falls back to default message if no explicit message defined.$constraint->has_message — Returns true if the type has a message subroutine.$constraint->message — Returns the message subroutine reference.$constraint->coercion — Returns the Moose::Meta::TypeCoercion object, if one exists.$constraint->has_coercion — Returns true if the type has a coercion.$constraint->can_be_inlined — Returns true if this type constraint can be inlined. A subtype of an inlinable constraint with no additional constraint inherits its parent's inlining.$constraint->create_child_type(%options) — Returns a new type constraint of the same class using the provided options. The "parent" option will be the current type. Exists so subclasses can override child type creation.See "BUGS" in Moose 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.
Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-28 07:18 @216.73.217.46
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format