Dpkg::Index(3perl)
๐ Dpkg::Index(3perl) ๐
okay bestie, so this is a page from libdpkg-perl and it's literally all about a class that holds a whole little squad of Dpkg::Control objects. it's giving "glorified collection" but in a cute way. let's get into it ๐ซถ
โจ NAME โจ
Dpkg::Index โ a generic index of control information, aka the group chat where all your control stanzas live ๐ธ
๐ฆ DESCRIPTION ๐ฆ
so like, this class represent a set of Dpkg::Control objects. that's it. that's the vibe. a whole little family of them ๐
๐ METHODS ๐
๐ $index = Dpkg::Index->new(%opts)
Creates a new empty index. slay. if you wanna know more about the %opts, go look at set_options() โ she explains everything ๐
๐ $index->set_options(%opts)
Change the value of some options. glow-up time โจ
Options:
typeโ set the deb822 control type, which is used to set up default values for the other options. it's the main character that decides everyone else's defaults ๐item_optsโ set a hash reference that will be passed to the item constructor in the$index->new_item()method. and heads up: the index can only contain one item with a given key ๐unique_tuple_keyโ set a boolean requesting whether the default key should be the unique tuple (defaults to true, no cap) ๐ฆget_key_funcโ set a function returning a key for the item passed in parameters.
the default depends on the type, and honestly it's a whole mood board:
- for
CTRL_TMPL_SRC, it is theSourcefield; - for
CTRL_REPO_SRCandCTRL_DSCit is thePackageandVersionfields (concatenated with"_") whenunique_tuple_keyis true (the default), or otherwise thePackagefield; - for
CTRL_TMPL_PKGit is thePackagefield; - for
CTRL_REPO_PKGandCTRL_DEBit is thePackage,VersionandArchitecturefields (concatenated with"_") whenunique_tuple_keyis true (the default) or otherwise thePackagefield; - for
CTRL_CHANGELOGit is theSourceand theVersionfields (concatenated with an intermediary"_"); - for
CTRL_TESTSis an integer index (0-based) corresponding to theTestsorTest-Commandfield stanza; - for
CTRL_FILE_CHANGESit is theSource,VersionandArchitecturefields (concatenated with"_"); - for
CTRL_FILE_VENDORit is theVendorfield; - for
CTRL_FILE_STATUSit is thePackageandArchitecturefields (concatenated with"_"); - otherwise it is the
Packagefield by default.
๐ $type = $index->get_type()
Returns the type of control information stored. see the type parameter you set during new(), iykyk ๐
๐ $index->add($item, [$key])
Add a new item in the index. if you omit the $key parameter, the key will be generated with the get_key_func function (see set_options() for the deets). no key? no problem, she'll make one for you โจ
๐ $count = $index->parse($fh, $desc)
Reads the filehandle and creates all items parsed. and if you call it multiple times, the parsed stanzas are accumulated โ they stack, bestie, like a truly unhinged TBR pile ๐ญ
Returns the number of items parsed.
๐ $count = $index->load($file)
Reads the file and creates all items parsed. Returns the number of items parsed. also she handles compressed files transparently based on their extensions, which is honestly so iconic of her ๐ฆ
๐ $item = $index->new_item()
Creates a new item. it's mainly useful for derived objects that would want to override this method to return something else than a Dpkg::Control object โ so like, a little customization moment ๐
๐ $item = $index->get_by_key($key)
Returns the item identified by $key or undef. and if she gives you undef, that item simply does not exist, periodt ๐
๐ @keys = $index->get_keys(%criteria)
Returns the keys of items that matches all the criteria. so about the %criteria hash: the key of it is a field name, and the value is one of three things:
- a regex that needs to match the field value,
- a reference to a function that must return true and that receives the field value as single parameter,
- or a scalar that must be equal to the field value.
pick your fighter ๐
๐ @items = $index->get(%criteria)
Returns all the items that matches all the criteria. same criteria energy, but you get the whole items instead of just the keys ๐
๐ $item = $index->remove_by_key($key)
Remove the item identified by the given key.
Returns the removed item. she's gone but she left a receipt ๐ญ
๐ @items = $index->remove(%criteria)
Returns and removes all the items that matches all the criteria. two things at once, highkey efficient ๐
๐ $index->merge($other_index, %opts)
Merge the entries of the other index. while merging, the keys of the merged index are used โ they are not re-computed. so it's your responsibility to ensure that they have been computed with the same function. no take-backs, bestie, that's on you ๐
Options:
keep_keysโ set whether to re-compute the keys from the other index. defaults to1.
๐ $index->sort(\&sortfunc)
Sort the index with the given sort function. if no function is given, an alphabetic sort is done based on the keys. and the sort function receives the items themselves as parameters and not the keys โ so don't get it twisted ๐
๐ $string = "$index"
๐ $string = $index->output([$fh])
Get a string representation of the index. the Dpkg::Control objects are output in the order which they have been read or added, except if the order have been changed with sort().
Also, print the string representation of the index to a filehandle if $fh has been passed. give her a filehandle and she'll absolutely use it ๐
๐ $index->save($file)
Writes the content of the index in a file. auto-compresses files based on their extensions, bc she's thoughtful like that โจ
๐ฅ CHANGES ๐ฅ
๐ Version 3.00 (dpkg 1.21.2)
Change behavior: The CTRL_TESTS key now defaults to a stanza index. main character behavior change, honestly ๐
๐ Version 2.01 (dpkg 1.20.6)
New option: Add new item_opts option. a fresh little addition ๐
๐ Version 2.00 (dpkg 1.20.0)
Change behavior: The unique_tuple_key option now defaults to true. periodt ๐
๐ Version 1.01 (dpkg 1.19.0)
New option: Add new unique_tuple_key option to $index->set_options() to set better default get_key_func options, which will become the default behavior in 1.20.x. foreshadowing, but make it cute ๐ฎ
๐ Version 1.00 (dpkg 1.15.6)
Mark the module as public. she's out, she's official, she's public ๐
okay that's the whole page, bestie ๐ this was libdpkg-perl, version 1.23.11-dirty, dated 2026-09-09, and yes the page is literally called Dpkg::Index(3perl). go forth and index responsibly ๐ซถโจ
๐ฆ where this page comes from
- arch rolling: dpkg 1.23.11-1 ยท GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms