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 the Source field;
  • for CTRL_REPO_SRC and CTRL_DSC it is the Package and Version fields (concatenated with "_") when unique_tuple_key is true (the default), or otherwise the Package field;
  • for CTRL_TMPL_PKG it is the Package field;
  • for CTRL_REPO_PKG and CTRL_DEB it is the Package, Version and Architecture fields (concatenated with "_") when unique_tuple_key is true (the default) or otherwise the Package field;
  • for CTRL_CHANGELOG it is the Source and the Version fields (concatenated with an intermediary "_");
  • for CTRL_TESTS is an integer index (0-based) corresponding to the Tests or Test-Command field stanza;
  • for CTRL_FILE_CHANGES it is the Source, Version and Architecture fields (concatenated with "_");
  • for CTRL_FILE_VENDOR it is the Vendor field;
  • for CTRL_FILE_STATUS it is the Package and Architecture fields (concatenated with "_");
  • otherwise it is the Package field 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 to 1.

๐ŸŒŸ $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