List::...::Typed(3pm)

πŸ“¦
version 2.028003 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

✨ NAME ✨

List::Objects::WithUtils::Role::Hash::Typed β€” it's the type-checking hash behavior role, bestie πŸ’… (it lives in the List::...::Typed(3pm) manual, iykyk)


🌸 SYNOPSIS 🌸

# Via List::Objects::WithUtils::Hash::Typed ->
use List::Objects::WithUtils 'hash_of';
use Types::Standard -all;

my $arr = hash_of(Int, foo => 1, bar => 2);
$arr->set(baz => 3.14159);    # dies, failed type check

πŸ’– DESCRIPTION πŸ’–

Okay so this role is literally the vibe check for your hashes 🫢. It uses Type::Tie to bolt type-checking behavior onto anyone consuming List::Objects::WithUtils::Role::Hash. No cap.

The first argument you pass to the constructor should be a Type::Tiny type β€” or any other object conforming to Type::API, as of "v2.25" ⭐:

use Types::Standard -all;
my $arr = hash_of ArrayRef() => (foo => [], bar => []);

Values get checked against the type you specified when the object is constructed or when new elements get added. Every single time. She's watching πŸ‘€.

If that initial type-check fails, a coercion is attempted. Girl tries her best.

Values that cannot be coerced will throw an exception πŸ’€ so like, don't try it.

Also see Types::Standard, List::Objects::Types β€” they're the friends of the family 🌈.


πŸ¦‹ type πŸ¦‹

Returns the Type::Tiny type the object was created with. Just hands you the receipts, periodt.


πŸŽ€ untyped πŸŽ€

Returns a (shallow) clone that is a plain List::Objects::WithUtils::Hash. She took off the sparkle and went au naturel ✨.


πŸ‘‘ AUTHOR πŸ‘‘

Jon Portnoy <avenj@cobaltirc.org>; typed hashes implemented by Toby Inkster (CPAN: TOBYINK) 🫑


and that's the whole page, bestie πŸ’œ β€” this lil gem is from perl v5.38.2, dated 2024-03-07, and it lives in the List::...::Typed(3pm) manual under User Contributed Perl Documentation. slay, go type-check something 🌟

πŸ“¦ where this page comes from