Moose::...Coercion(3)

πŸ’– Moose::...Coercion(3) πŸ’–

User Contributed Perl Documentation Β· Moose::Meta::TypeCoercion β€” the Moose Type Coercion metaclass, bestie πŸ’…


✨ VERSION ✨

version 2.4000 πŸŽ€


🌸 NAME 🌸

Moose::Meta::TypeCoercion β€” it's literally the Moose Type Coercion metaclass, no cap πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so. A type coercion object is basically a mapping of one or more type constraints plus the coercion subroutines that go with them. That's the whole vibe πŸ’«

And ngl? You're probably never gonna need to instantiate one of these yourself. It's part of the deep, deep internals of Moose β€” like, deep deep. Main character energy, but behind the scenes πŸ™ˆ


πŸ’… METHODS πŸ’…

πŸ’œ Moose::Meta::TypeCoercion->new(%options)

Makes you a brand new type coercion object, built from the options you hand it.

  • type_constraint β€” this is the Moose::Meta::TypeConstraint object for the type that's being coerced to. Like, the destination. The glow-up target ✨

πŸ’œ $coercion->type_coercion_map

Returns the map of type constraints β†’ coercions as an array reference. The values in that array alternate between type names and subroutine references that implement the coercion. Cute, right? πŸ“

It's an array reference specifically because coercions get tried in the order they were added. First come, first served, periodt ⭐

πŸ’œ $coercion->type_constraint

Returns the Moose::Meta::TypeConstraint that you passed to the constructor. Just hands it right back to you 🫢

πŸ’œ $coercion->has_coercion_for_type($type_name)

Returns true if the coercion can coerce the named type. Simple as 🌈

πŸ’œ $coercion->add_type_coercions( $type_name => $sub, ... )

Takes a list of type names and subroutine references. Heads up though β€” if the coercion already has a mapping for a given type, it throws an exception. It said no duplicates, and it meant it πŸ’€

Coercions are actually

πŸ’œ $coercion->coerce($value)

Takes a value and applies the first valid coercion it finds.

Which means β€” listen β€” if the value could belong to more than one type in the coercion object, the first coercion added is the one that wins. Order matters, bestie 😭

πŸ’œ Moose::Meta::TypeCoercion->meta

This will return a Class::MOP::Class instance for this class. Metaclass inception, iconic πŸ‘‘


πŸ™ˆ BUGS πŸ™ˆ

See "BUGS" in Moose for the details on reporting bugs. Go tell 'em, not me πŸ’–


πŸ‘‘ 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>

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.


okay that's the whole page, you ate that πŸ’…βœ¨ Brought to you by perl v5.42.0, dated 2025-07-25, and stamped with the manual name Moose::...Coercion(3) from the User Contributed Perl Documentation. mwah πŸŽ€πŸ’–
πŸ“¦ where this page comes from