KiokuD...allback(3pm)

πŸ“¦
version 0.57 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

πŸ’– KiokuDB::TypeMap::Entry::Callback πŸ’–

okay bestie, welcome to the User Contributed Perl Documentation glow-up of KiokuDB::TypeMap::Entry::Callback(3pm) β€” the type map entry that does inflation and deflation of objects through callbacks. yes, callbacks. we love a pluggable moment. ✨


🌸 VERSION 🌸

version 0.57 β€” she's giving vintage but she works, no cap.


πŸ¦‹ SYNOPSIS πŸ¦‹

KiokuDB::TypeMap->new(
    entries => {
        'My::Class' => KiokuDB::TypeMap::Entry::Callback->new(
            expand => "new", # My::Class->new(%$self)
            collapse => sub {
                my $self = shift;
                return %$self; # provide args to 'new' in this example
            },
            id => sub { "foo" }, # 'id' callback is optional
        ),
    },
);

look at that. clean. iconic. she's basically saying "here's how you turn an object into a list and back again, you're welcome." 🫢


✨ DESCRIPTION ✨

So this KiokuDB::TypeMap entry provides callback based inflation and deflation. That's the whole vibe. You hand her some callbacks, she hands you objects back. πŸ’…

⚠️ But bestie, listen β€” the major limitation here is that this method cannot be used for self referential structures. Why? Because the object being inflated is only constructed after all of its arguments are. So like… the object can't reference itself while it doesn't exist yet. it's giving "can't sit with us, you're not built yet." πŸ’€

For the overwhelming majority of the use cases though? This is good enough. fr fr. 🌈


πŸŽ€ ATTRIBUTES πŸŽ€

  • collapse β€” a method name or code reference that gets invoked on the object during collapsing. She's evaluated in list context, and that list of values she returns gets collapsed by the KiokuDB::Collapser and then stored. πŸ“
  • expand β€” a method name or code reference invoked on the class of the object during loading. The arguments are exactly as returned by the collapse callback. symmetry, we love to see it. πŸ‘‘
  • id β€” an optional method name or code reference invoked to get an ID for the object. If you don't provide one, the default (UUID based) generation is used. she'll handle it, don't stress. πŸ’œ
  • intrinsic β€” a boolean denoting whether or not the object should be collapsed with no ID, and serialized as part of its parent object. Super useful for value like objects, for whom the reference address makes no difference β€” such as URI objects. main character energy for value objects. 🧚

πŸ’– AUTHOR πŸ’–

Yuval Kogman <nothingmuch@woobling.org> β€” the legend herself. 🫢


This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so go off, legally. ⭐


and that's the whole page, bestie β€” perl v5.34.0, dated 2022-05-23, KiokuDB::TypeMap::Entry::Callback, signing off. mwah. πŸ’‹

πŸ“¦ where this page comes from