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

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

πŸ’– List::Objects::WithUtils::Hash::Typed β€” the manual page πŸ’–

okay bestie, you found it: this is the List::...::Typed(3pm) page from the User Contributed Perl Documentation set. Pull up a chair, we're doing type-checked hashes and we're doing them correctly. ✨


🌸 NAME 🌸

List::Objects::WithUtils::Hash::Typed β€” type-checking hash objects πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

use List::Objects::WithUtils 'hash_of';

use Types::Standard -all;

my $arr = hash_of Int() => ( foo => 1, bar => 2 );

(yes, it's literally called $arr in the original, no we are not fixing it, it's iconic 🫢)


✨ DESCRIPTION ✨

These are type-checking hash objects. So like β€” every value gets checked against the type you specified, and that happens when the object is constructed or when new elements are added. Every single time. No sneaky bad values slipping through the vibe check. πŸ¦‹

The first argument you hand the constructor should be a Type::Tiny type:

use Types::Standard -all;
my $hash = hash_of Int() => ( foo => 1 );

And here's the little plot twist: if the initial type-check fails, a coercion is attempted. So it's not an instant no, it's a "let me see if I can make this work" moment. πŸ’«

This class consumes the following roles, and those roles are where most of the relevant documentation actually lives, so go read them:

  • List::Objects::WithUtils::Role::Hash
  • List::Objects::WithUtils::Role::Hash::Typed

Also see Types::Standard, List::Objects::Types. iykyk πŸ‘‘


πŸ”₯ hash_of πŸ”₯

Creates a new typed hash object. That's the whole thing. She's simple, she's effective, she ate. πŸ’…


πŸ‘‘ AUTHOR πŸ‘‘

Jon Portnoy <avenj@cobaltirc.org> with significant contributions from Toby Inkster (CPAN: TOBYINK) 🌟


fr fr that's the whole page, no cap. go forth and type-check your hashes bestie πŸ’–

and that's a wrap on perl v5.38.2, dated 2024-03-07 β€” mwah, stan this manpage πŸŽ€πŸ’œ

πŸ“¦ where this page comes from