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::hashto@ISA - provide
get,setandexistsmethods - 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:
- a reference to the hash itself
- the XS object
- 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
- ubuntu stonking: libapt-pkg-perl 0.1.43build1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms