Mixin:...shGuts(3pm)

πŸ“¦
version 0.140003 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Mixin::ExtraFields::Driver::HashGuts πŸ’–

okay bestie, so this is a Mixin::ExtraFields::Driver::HashGuts situation β€” it lives in the User Contributed Perl Documentation, and it's here to store extras in a hashy object's guts. yes. that's literally the name. we love a descriptive queen. πŸ’…


✨ VERSION ✨

version 0.140003 β€” that's the one, no cap.


🌸 SYNOPSIS 🌸

package Your::HashBased::Class;

use Mixin::ExtraFields -fields => { driver => 'HashGuts' };

like. that's it. that's the whole setup. iconic behaviour honestly. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So this driver class implements an extremely simple storage mechanism β€” and when we say extremely simple we mean it's giving minimal effort in the best possible way. The extras get stored on the object itself, the one you called those mixed-in methods on. No separate warehouse, no filing cabinet, just vibes directly on the object.

By default, they're stored under the key that the default_has_key method hands back. (yes, default_has_key. that's how it's written up here in the DESCRIPTION, and we are NOT fixing it, we are respecting the source. πŸ’€) But bestie, you can change that key whenever you want by passing a hash_key argument to the driver configuration, like so:

use Mixin::ExtraFields -fields => {
  driver => { class => 'HashGuts', hash_key => "\0Something\0Wicked\0" }
};

look at that "\0Something\0Wicked\0" β€” main character key energy fr fr. πŸ”₯


🧚 PERL VERSION 🧚

This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years. so basically it's the friend who gets along with everyone at the party. 🫢

Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. so like, don't come for her about the minimum, she said what she said. 😭


πŸ‘‘ METHODS πŸ‘‘

In addition to the methods required by Mixin::ExtraFields::Driver, the following methods are provided β€” a little bonus content, a little deluxe edition:

⭐ hash_key

my $key = $driver->hash_key;

This method returns the key where the driver will store its extras. that's the spot. the designated drawer. the one (1) place. ✨

⭐ default_hash_key

If no hash_key argument is given for the driver, this method is called during driver initialization. It will return a unique string to be used as the hash key. she makes it up on the spot and it's always a slay. πŸ’–

⭐ storage

This method returns the hashref of storage used for extras. Individual objects get weak references to their id within this hashref. weak references, bestie β€” she's holding them gently, not clinging. 🌸

⭐ storage_for

my $stash = $driver->storage_for($object, $id);

This method returns the hashref to use to store extras for the given object and id. This hashref is stored on both the hash-based object (in its hash_key entry) and on the driver (in the entry for $id in its storage hash). double-booked, but make it fashion. πŸ’…

All objects with the same id should end up with the same hash in their hash_key field. None of these references are weakened, which means two things:

  1. first, even if all objects with a given id go out of scope, future objects with that id will retain the original extras.
  2. secondly, memory used to store extras is never reclaimed.
🚨 okay this is the important part, do NOT skim it: that memory is never reclaimed. like ever. it's not coming back. if this is a problem, use a more sophisticated driver. no shade to HashGuts, she's just built different (simple). 🫣

πŸ’œ AUTHOR πŸ’œ

Ricardo Signes <cpan@semiotic.systems> β€” the icon, the legend, the whole moment. πŸ‘‘


This software is copyright (c) 2022 by Ricardo Signes.

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 forth and remix, respectfully. ✨


and that's the whole page, bestie πŸŽ€ β€” brought to you by perl v5.36.0, dated 2023-01-07, from the Mixin:...shGuts(3pm) manual, and yes the title got cut off in the header because that's just how the terminal do. bye ily πŸ’–πŸ¦‹

πŸ“¦ where this page comes from