AptPkg::Config(3pm)
β¨ NAME β¨
AptPkg::Config β the APT configuration interface, bestie π
π¦ SYNOPSIS π¦
use AptPkg::Config;
πΈ DESCRIPTION πΈ
So the AptPkg::Config module hands you an interface to APT's configuration mechanism. That's the whole vibe.
It literally gives you a configuration file and command line parser for a tree-oriented configuration environment. Tree-oriented. Fancy. Slay. π³β¨
π AptPkg::Config
The AptPkg::Config package implements the APT Configuration class. Iconic behaviour, no notes.
A global instance of the libapt-pkg _config instance is provided as $AptPkg::Config::_config, and it may be imported. Yep, it's right there, yours for the taking π«Ά
The following methods are implemented:
get(KEY, [DEFAULT])β grab the value of KEY out of the configuration object, and it returnsundefif that key isn't found (or DEFAULT if you passed one, bestie).
If the key ends in ::, you get an array of values back in an array context, or a string with the values separated by spaces in a scalar context. Pick your fighter.
A trailing /f, /d, /b or /i makes it interpret the thing as file, directory, boolean or integer (the underlying XS call is FindAny).
get_file(KEY, [DEFAULT]),get_dir(KEY, [DEFAULT])β variants ofgetthat prepend the directory value from the parent key. Theget_dirmethod additionally appends a/. The way it just adds the slash... attention to detail fr fr.
For example, given the configuration file:
foo "/some/dir/" { bar "value"; }
then:
$conf->get("foo::bar") # "value"
$conf->get_file("foo::bar") # "/some/dir/value"
$conf->get_dir("foo::bar") # "/some/dir/value/"
get_bool(KEY, [DEFAULT])β anothergetvariant, this one returns true (1) if the value contains any of:
1 yes true with on enable
otherwise false (''). That's it, that's the whole boolean moment β
set(KEY, VALUE)β set configuration entry KEY to VALUE. Returns VALUE. Heads up though: empty parent entries may be created for KEYs that contain::. It's building the tree for you, lowkey thoughtful.exists(KEY)β test if KEY exists in the configuration. Simple. Powerful. πdumpβ principally for debugging: output the contents of the configuration object to stderr. Not your main character, but she's there when you need her.read_file(FILE, [AS_SECTIONAL, [DEPTH]])β load the contents of FILE into the object. The format of the file is described inapt.conf(5).
If the AS_SECTIONAL argument is true, then the file is parsed as a BIND-style config. That is:
foo "bar" { baz "quux"; }
is interpreted as if it were:
foo::bar { baz "quux"; }
The DEPTH argument may be used to restrict the number of nested include directives processed. Keep that recursion in check bestie π§
read_dir(DIR, [AS_SECTIONAL, [DEPTH]])β load configuration from all files in DIR. Whole directory, one call, obsessed. πinitβ initialise the configuration object with some default values for the libapt-pkg library, and reads the default configuration file/etc/apt/apt.conf(or as given by the environment variableAPT_CONFIG) if it exists.systemβ return theAptPkg::Systemobject appropriate for this system.parse_cmdline(DEFS, [ARG, ...])β parse the arguments given by ARGs based on the contents of DEFS and returns the list of remaining arguments.
Warning bestie: the function does not return if there are errors processing the args. Use eval to trap such errors. Not a drill. π
DEFS is a reference to an array containing a set argument definition arrays. The elements of each definition define: the short argument character, the long argument string, the configuration key and the optional argument type (defaults to Boolean).
Valid argument types are defined by the strings:
HasArg takes an argument value (-f foo)
IntLevel defines an integer value (-q -q, -qq, -q2, -q=2)
Boolean true/false (-d, -d=true, -d=yes, --no-d, -d=false, etc)
InvBoolean same as Boolean but false with no specified sense (-d)
ConfigFile load the specified configuration file
ArbItem arbitrary configuration string of the form key=value
The configuration key in the last two cases is ignored, and for the rest gives the key into which the value is placed.
Single case equivalents also work (has_arg == HasArg). Both vibes are valid, we don't gatekeep β¨
Example:
@files = $conf->parse_cmndline([
[ 'h', 'help', 'help' ],
[ 'v', 'version', 'version' ],
[ 'c', 'config-file', '', ConfigFile ],
[ 'o', 'option', '', ArbItem ],
], @ARGV);
The module uses AptPkg::hash to provide a hash-like access to the object, so that $conf->{key} is equivalent to using the get/set methods. Look at her, being all convenient.
Additionally inherits the constructor (new) and keys methods from that module.
Methods of the internal XS object (AptPkg::_config) such as Find may also be used. See AptPkg.
π AptPkg::Config::Iter
Iterator object for AptPkg::Config which is returned by the keys method. She's the little helper that walks the tree for you πΆβοΈπ³
new(XS_OBJ, [ROOT])β constructor, which is invoked by thekeysmethod. ROOT, if given, determines the subset of the tree to walk (may be given as an argument tokeys).nextβ returns the current key and advances to the next. One step at a time, main character energy π
π₯ SEE ALSO π₯
AptPkg::System(3pm), AptPkg(3pm), AptPkg::hash(3pm).
π AUTHOR π
Brendan O'Dea <bod@debian.org> β thank you for your service, king π«Ά
And that's the tea, bestie π this page came to you from the User Contributed Perl Documentation corner of the universe, riding along with perl v5.42.3, dated 2026-08-19. Go configure something iconic. π
π¦ 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