Moose::...::Union(3)

πŸ’– Moose::Meta::TypeConstraint::Union β€” bestie edition πŸ’–

okay so this is the page for Moose::Meta::TypeConstraint::Union, which lives in the User Contributed Perl Documentation section of your man pages. It's giving very "the sum is greater than the parts" energy. Let's get into it. ✨


🌸 VERSION 🌸

version 2.4000 β€” that's the one, no cap.


πŸ¦‹ DESCRIPTION πŸ¦‹

So this metaclass? It represents a union of type constraints. A union takes a whole bunch of type constraints, and it's true if any one of its member constraints is true.

It's giving "any of my girls said yes so the answer is yes." πŸ’…


πŸ‘‘ INHERITANCE πŸ‘‘

Moose::Meta::TypeConstraint::Union is a subclass of Moose::Meta::TypeConstraint. So it inherits all that main character energy from its parent. 🫢


✨ METHODS ✨

πŸŽ€ Moose::Meta::TypeConstraint::Union->new(%options)

This creates a brand new class type constraint based on the %options you hand it.

It takes the same options as its parent. But there's one extra requirement: it also needs an additional option called type_constraints. That one is an array reference holding the Moose::Meta::TypeConstraint objects that are the members of the union type.

The name option defaults to the names of all of those member types, sorted and then joined by a pipe (|). Obsessed with a default that just figures itself out. 😌

The constructor also sets the implementation of the constraint so that it simply calls check on the newly created object.

And finally β€” because the constructor is a multitasking icon β€” it also makes sure that the object's coercion attribute is a Moose::Meta::TypeCoercion::Union object. ✨


πŸ“ $constraint->type_constraints

This returns the array reference of type_constraints that you gave to the constructor. That's it, that's the whole method. Simple, effective, slay. πŸ’–


🌈 $constraint->parent

This returns the nearest common ancestor of all the components of the union. It's literally finding the shared family tree of the whole friend group. 🌳


🧚 $constraint->check($value) and $constraint->validate($value)

These two methods simply call the relevant method on each of the member type constraints in the union. If any type accepts the value, then the value is valid. Periodt.

But with validate, there's a little extra: the error message it returns includes all of the error messages returned by the member type constraints. Not just one β€” all of them. It's thorough like that. 😭


πŸ’œ $constraint->equals($type_name_or_object)

A type is considered equal if it is also a union type, and the two unions have the same member types. Both conditions, bestie. No shortcuts. πŸ‘‘


⭐ $constraint->find_type_for($value)

This returns the first member type constraint for which check($value) is true. Which is super handy, because it lets you figure out which of the Union's member type constraints a given value actually matches. iykyk. πŸ”₯


πŸŽ€ $constraint->is_a_type_of($type_name_or_object)

This returns true if all of the member type constraints return true for the is_a_type_of method. All of them. Every single one. πŸ’―


πŸ¦‹ $constraint->is_subtype_of

This returns true if all of the member type constraints return true for the is_subtype_of method. Same deal β€” it's an all-or-nothing situation. 🫢


🌸 $constraint->create_child_type(%options)

This returns a new Moose::Meta::TypeConstraint object, with the type as its parent. New baby constraint, freshly spawned. πŸ₯Ή


πŸ’€ BUGS πŸ’€

See "BUGS" in Moose for all the details on reporting bugs. Go tell them, bestie, they want to know.


πŸ’… AUTHORS πŸ’…

The absolute legends who made this happen:

  • 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>

Ten authors. TEN. That's a whole group chat and every single one of them ate. πŸ‘‘


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.


That's the whole page bestie, go forth and union your type constraints responsibly πŸ’–

Moose::...::Union(3) β€” from perl v5.42.0, dated 2025-07-25. That's the tea, mwah. πŸ’…βœ¨

πŸ“¦ where this page comes from