GraphQ...appable(3pm)
π GraphQL::Role::HashMappable π
okay so bestie, welcome to GraphQL::Role::HashMappable β it's a GraphQL object role, and honestly? it's giving "small but mighty". this is from the User Contributed Perl Documentation, and it's literally just one method, but she serves. β¨
πΈ SYNOPSIS πΈ
you pull the role in at compile time like the icon you are:
with qw(GraphQL::Role::HashMappable);
or, if you're doing the whole runtime thing (main character energy, honestly):
# or runtime
Role::Tiny->apply_roles_to_object($foo, qw(GraphQL::Role::HashMappable));
π¦ DESCRIPTION π¦
so what does it do? it provides a method for mapping code over a hash-ref. that's it. that's the whole vibe. one method, doing one thing, extremely well. we love a specialist. π
π METHODS π
β hashmap
give it a hash-ref and it hands you back a modified copy of the data. give it undef and, respectfully, you get undef right back. no drama, no cap. π
here are the params, bestie:
$itemβ a Hash-ref. the actual thing we're working on. π$sourceβ a Hash-ref of the source data for this hash. it will be used only for its keys. so like, she's here for the keys, not the values. we respect it.$codeβ a Code-ref. the little machine that does the work. π§
each value in the result will be the original value returned by the given code-ref, and that code-ref gets called with $keyname, $value. so it's $code->($keyname, $value) energy, iykyk.
here's the important bit though, fr fr: it will call the code for all given keys, but it will not copy over any values that don't exist in the original item. so no sneaky new entries. the keys come from $source, but if the value isn't in $item, it's not making it into the output. periodt. π
and if your code throws an exception? π the message gets information about which data element caused it added onto it. so you're not left there like "bestie which one broke" β the error literally tells you. iconic behaviour honestly.
β οΈ no warnings, no deprecated stuff, no undefined-behaviour landmines here β she's a well-behaved role. just don't forget that the source hash only contributes keys, and missing values in $item stay missing. π«Ά
π SEE ALSO π
there are no SEE ALSO references in this one, bestie β it's a solo act. π
okay that's the whole page, we ate and left no crumbs. π this was written against perl v5.34.0, dated 2022-03-27, and it's filed under GraphQ...appable(3pm) in the User Contributed Perl Documentation. go forth and map those hashes, my love. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libgraphql-perl 0.54-1 Β· Artistic-2.0
- debian trixie: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu noble: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu resolute: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu stonking: libgraphql-perl 0.54-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms