AptPkg::hash(3pm)

πŸ’– NAME πŸ’–

AptPkg::hash β€” a helper class for implementing tied hashes

bestie, welcome to the User Contributed Perl Documentation, section 3pm ✨ this is the little class that makes your fancy XS-backed thing behave like a plain old hash and honestly? iconic 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

use AptPkg::hash;

that's it. that's the whole synopsis. we love a minimal queen πŸ’…


✨ DESCRIPTION ✨

okay so AptPkg::hash gives you hash-like access for objects that have an underlying XS implementation. that's the whole job, no cap.

for that to work, those objects gotta do a few things, and they're non-negotiable πŸ™ˆ:

  • add AptPkg::hash to @ISA
  • provide get, set and exists methods
  • provide an iterator class

do that and the vibes are immaculate 🌸


πŸŽ€ AptPkg::hash πŸŽ€

🌟 new([XS_OBJECT]) 🌟

creates an object as a tied hash. like, the object is implemented as a hash reference that's been blessed into the class, and that hash reference is in turn tied to AptPkg::hash. main character energy fr fr πŸ‘‘

what that means for you: both $obj->method() and $obj->{key} are valid, and the latter calls up get/set (by way of FETCH/STORE). yes, both. she contains multitudes πŸ’…

the tie associates an array reference with the hash, and that array starts out holding three things:

  1. a reference to the hash itself
  2. the XS object
  3. an anon hash that subclasses can use to stash state info 🌈

if you don't pass an XS object, one gets created via new in the XS class. and how do we figure out that class's name? we take the class name, lower-case the last component, and stick an underscore in front of it. so AptPkg::Config becomes AptPkg::_config. cute, right? πŸŽ€

if the module has a @KEYS array in it, then the private hash gets populated with those entries as keys β€” peep the description of the AptPkg::hash::method class below for the tea β˜•

🌸 _self, _xs, _priv 🌸

accessors 🫢 you use these inside subclass methods to fetch those three array elements that are chilling with the hash reference. three accessors, three elements, perfect symmetry, ate πŸ’–

πŸ¦‹ keys(ARGS) πŸ¦‹

in scalar context: she creates and returns a brand-new iterator object β€” that's the class name with the suffix ::Iter tacked on the end ✨

the XS object, the private hash, and any arguments all get passed to the constructor.

in array context: the iterator gets used to generate a list of keys, and then those keys are returned. boom πŸ’₯

heads up though: the iterator class has to implement a next method, which returns the current key and advances to the next one. no next, no keys, periodt πŸ”₯


πŸ‘‘ AptPkg::hash::method πŸ‘‘

AptPkg::hash::method extends AptPkg::hash, and what it gives you is a simple way to map a fixed set of keys (defined by that @KEYS array, iykyk) into method calls on either the object or the internal XS object. pick your fighter πŸ’…

and if you've got classes inheriting from AptPkg::hash::method, they should provide an iterator class that inherits from AptPkg::hash::method::iter. keep the family tree tidy, bestie 🌳


πŸ’œ AUTHOR πŸ’œ

Brendan O'Dea <bod@debian.org> β€” thank you for your service, legend 🫑


and that's the whole page, bestie!! this was perl v5.42.3, dated 2026-08-19, and it's the AptPkg::hash(3pm) page ✨ go forth and tie your hashes responsibly πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from