MooseX...oercion(3pm)
π MooseX::Meta::TypeConstraint::ForceCoercion π
okay bestie, so this is a page from the User Contributed Perl Documentation, and it's filed under MooseX...oercion(3pm) β the manual name got squished by the man page formatter, but we know the truth: it's MooseX::Meta::TypeConstraint::ForceCoercion. She's the one who forces coercion when you're validating type constraints. No cap. β¨
β¨ NAME β¨
MooseX::Meta::TypeConstraint::ForceCoercion β Force coercion when validating type constraints π
πΈ VERSION πΈ
version 0.01
π¦ SYNOPSIS π¦
use MooseX::Types:::Moose qw/Str Any/;
use Moose::Util::TypeConstraints;
use MooseX::Meta::TypeConstraint::ForceCoercion;
# get any type constraint
my $tc = Str;
# declare one or more coercions for it
coerce $tc,
from Any,
via { ... };
# wrap the $tc to force coercion
my $coercing_tc = MooseX::Meta::TypeConstraint::ForceCoercion->new(
type_constraint => $tc,
);
# check a value against new type constraint. this will run the type
# coercions for the wrapped type, even if the value already passes
# validation before coercion. it will fail if the value couldn't be
# coerced
$coercing_tc->check('Affe');
like literally look at that last line, 'Affe' is getting coerced whether it likes it or not π the whole point is that coercion is mandatory, not optional.
π DESCRIPTION π
This class lets you wrap any Moose::Meta::TypeConstraint in a way that will force coercion of the value when you're checking or validating a value against it. it's giving "you WILL be coerced, periodt" energy π
π ATTRIBUTES π
type_constraint
The type constraint to wrap. All methods except for validate and check are delegated to the value of this attribute. so she's basically a lil bodyguard that hands off everything else to the wrapped type β but keeps validate and check for herself π
π METHODS π
check ($value)
Same as Moose::Meta::TypeConstraint::check, except it will always try to coerce $value before checking it against the actual type constraint. If coercing fails the check will fail, too. so like, no sneaking past the vibe check just because you already technically passed π«Ά
validate ($value, $coerced_ref?)
Same as Moose::Meta::TypeConstraint::validate, except it will always try to coerce $value before validating it against the actual type constraint. If coercing fails the validation will fail, too.
If coercion was successful and a $coerced_ref references was passed, the coerced value will be stored in that. π so you can snag the glow-up'd version and keep it, iykyk.
π AUTHOR π
Florian Ragwitz <rafl@debian.org>
shoutout to Florian, the original main character π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2009 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as perl itself. πΈ
okay that's the whole page bestie, you ate it up π and just so we're keeping receipts: this was written up against perl v5.36.0, dated 2022-12-09, and the manual page is MooseX...oercion(3pm) β go forth and force some coercions, no cap π
β¨π¦
π¦ where this page comes from
- debian bookworm: libmoosex-meta-typeconstraint-forcecoercion-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-meta-typeconstraint-forcecoercion-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-meta-typeconstraint-forcecoercion-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-meta-typeconstraint-forcecoercion-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-meta-typeconstraint-forcecoercion-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms