Moose::...nstraint(3)
π NAME π
Moose::Meta::TypeConstraint β bestie, this is the Moose Type Constraint metaclass, and she is serving looks. We're in the Moose::...nstraint(3) perl doc page btw, if the header didn't already spoil it. π
β¨ VERSION β¨
version 2.4000 β that's the one, no cap.
πΈ DESCRIPTION πΈ
Okay so, imagine this class as one single type constraint. That's her whole job, that's her whole vibe. π
Every type constraint in Moose β the built-in ones and the ones you write yourself β gets stored as an object of this class inside a Moose::Meta::TypeConstraint::Registry object. So yeah, they're all living in the registry together, iconic behavior honestly. π¦
π INHERITANCE π
Moose::Meta::TypeConstraint is a subclass of Class::MOP::Object. Family tree slays, we love a legacy. π
π₯ METHODS π₯
π Moose::Meta::TypeConstraint->new(%options)
This makes a brand-new type constraint out of the %options you hand her. Here's the tea on every single one of those options:
nameβ the constraint's name. If you don't give her one, she'll just be like "fine, I'm__ANON__now" and that's that. πparentβ aMoose::Meta::TypeConstraintobject that acts as the parent type for the type you're creating. Totally optional, no pressure bestie.constraintβ the subroutine reference that does the actual constraint check. Defaults to a subroutine that always returns true. Yeah, she's easygoing like that. β¨messageβ a subroutine reference used to generate the error message when the constraint fails. Optional!coercionβ aMoose::Meta::TypeCoercionobject representing the coercions into this type. Also optional.inlinedβ a subroutine that returns a string suitable for inlining this type constraint. It gets called as a method on the type constraint object, and it receives one extra parameter: a variable name to be tested (usually$_or$_[0].
Optional, bestie. π«Ά
inline_environmentβ a hash reference of variables to close over. The keys are variable names and the values are references to those variables.
β $constraint->equals($type_name_or_object)
Returns true if the name or type object you passed in is the same as the current type. Twin check: passed. π―
π $constraint->is_subtype_of($type_name_or_object)
Returns true if the name or type object you passed in 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 of the current type. It's basically a shortcut for checking equals and is_subtype_of β two birds, one slay. ποΈ
π $constraint->coerce($value)
Attempts to coerce the value into the type. Heads up though: if the type doesn't have any defined coercions, this throws an error. Not a vibe, but it is what it is. π
If no coercion can produce a value matching $constraint, you just get the original value back. She tried her best.
π $constraint->assert_coerce($value)
Behaves just like coerce, but with consequences: if the result isn't valid according to $constraint, an error gets thrown. Periodt.
π¦ $constraint->check($value)
Returns true if the given value passes the constraint for the type. Simple, clean, main character energy.
π§ $constraint->validate($value)
Similar to check, but with a lil plot twist: if the type is valid, the method returns an explicit undef. If the type is not valid, we call $self->get_message($value) internally to generate an error message.
π $constraint->assert_valid($value)
Like check and validate, this checks whether $value is valid under the constraint. If it is, she returns true. If she's not valid, an exception gets thrown with the results of $self->get_message($value). No silent failures in this house. π
πΈ $constraint->name
Returns the type's name, exactly as provided to the constructor.
π $constraint->parent
Returns the type's parent, exactly as provided to the constructor β if there is one, anyway.
β¨ $constraint->has_parent
Returns true if the type has a parent type. Yes or no, no in-between.
π $constraint->parents
Returns all of the type's parents as a list of type constraint objects. Whole family reunion. π«Ά
π₯ $constraint->constraint
Returns the type's constraint, as provided to the constructor.
π $constraint->get_message($value)
Generates a message for the given value. If the type doesn't have an explicit message of her own, we generate a default one. She always has something to say.
π $constraint->has_message
Returns true if the type has a message.
β $constraint->message
Returns the type's message as a subroutine reference.
π $constraint->coercion
Returns the type's 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. Real talk: a type constraint which subtypes an inlinable constraint and does not add an additional constraint basically "inherits" its parent type's inlining. Generational talent. π
π $constraint->create_child_type(%options)
Returns a new type constraint of the same class, built from the %options you give her. The parent option will be the current type β so congrats, you're a parent now. π₯Ή
This method exists so that subclasses of this class can override the behavior and change how child types get created. Customizable, as she should be.
π BUGS π
See "BUGS" in Moose for the details on reporting bugs. Go tell them, bestie, they wanna know. π«Ά
π AUTHORS π
- Stevan Little <stevan@cpan.org>
- Dave Rolsky <autarch@urth.org>
- Jesse Luehrs <doy@cpan.org>
- Shawn M Moore <sartak@cpan.org>
- ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman) <nothingmuch@woobling.org>
- Karen Etheridge <ether@cpan.org>
- Florian Ragwitz <rafl@debian.org>
- Hans Dieter Pearcey <hdp@cpan.org>
- Chris Prather <chris@prather.org>
- Matt S Trout <mstrout@cpan.org>
Look at that roster. The Avengers could never. π β¨
π COPYRIGHT AND LICENSE π
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. Free as in freedom, slay. ποΈ
okay that's the whole page, ily, go write some type constraints πβ¨ππ¦πΈπ π«Άππβ
signing off from perl v5.42.0, dated 2025-07-25, in the Moose::...nstraint(3) section β byeeee ππ
π¦ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms