Config...nstance(3pm)
πΈ NAME πΈ
Config::Model::Instance β an Instance of configuration tree. Yes bestie, that's literally the whole name. It's giving "I hold a whole config tree and I'm chill about it". π
This is part of the User Contributed Perl Documentation, i.e. the Config...nstance(3pm) page, so if you were looking for the manual you found her. β¨
π VERSION π
version 2.166
β¨ SYNOPSIS β¨
okay so here's the entire vibe in code form, copy it exactly, no cap:
use Config::Model;
use File::Path ;
# setup a dummy popcon conf file
my $wr_dir = '/tmp/etc/';
my $conf_file = "$wr_dir/popularity-contest.conf" ;
unless (-d $wr_dir) {
mkpath($wr_dir, { mode => 0755 })
|| die "can't mkpath $wr_dir: $!";
}
open(my $conf,"> $conf_file" ) || die "can't open $conf_file: $!";
$conf->print( qq!MY_HOSTID="aaaaaaaaaaaaaaaaaaaa"\n!,
qq!PARTICIPATE="yes"\n!,
qq!USEHTTP="yes" # always http\n!,
qq!DAY="6"\n!);
$conf->close ;
my $model = Config::Model->new;
# PopCon model is provided. Create a new Config::Model::Instance object
my $inst = $model->instance (root_class_name => 'PopCon',
root_dir => '/tmp',
);
my $root = $inst -> config_root ;
print $root->describe;
π¦ DESCRIPTION π¦
This module provides an object that holds a configuration tree. That's the whole job. She's a container, she's holding the whole tree, main character energy honestly. π³
π CONSTRUCTOR π
So to make an instance object, you call the instance method on an existing model. And you can point at that model by its application name, like:
my $inst = $model->instance (
# run 'cme list' to get list of applications
application => 'foo',
# optional
instance_name => 'test1'
);
my $inst = $model->instance (
root_class_name => 'SomeRootClass',
instance_name => 'test1'
);
The directory (or directories, plural, she's flexible π) that holds the configuration files is specified inside the configuration model itself. But for testing purposes you can switch up that "root" directory with the root_dir parameter. iykyk. π§
Constructor parameters are, bestie, listen:
root_dirβ the pseudo root directory where config files get read from and written to. Takes a Path::Tiny object or a plain string. Whatever configuration directory the model specifies (or the one you pass withconfig_dir) gets appended onto this root directory. πroot_pathβ a Path::Tiny object built from theroot_dirvalue, or from the current directory ifroot_diris empty.config_dirβ the directory to read or write the configuration file. You must supply this if the configuration model doesn't already provide one. (string, periodt.)backend_argβ specify a backend argument that some backend might retrieve later. The Instance is just the relay here, she does not use this data herself. πcheckβ says whether to check values while reading config files. Either:yesβ check the value and throw an error for bad values. π€skipβ check the value and skip the bad value. π«£noβ do not check. At all. Zero checking. π
canonicalβ when true, write config data back using model order. By default, items get written back in the order found in the configuration file. Heads up though: this feature is experimental and not supported by all backends. β οΈon_change_cbβ call back this function whenevernotify_changeis called. It's called with arguments:name => <root node element name>, index => <index_value>on_message_cbβ call back this function when show_message is called. By default, messages are displayed onSTDOUT. π’error_pathsβ returns a list of tree items that currently have an error.error_messagesβ returns a list of error messages from the tree content.
Note that the root directory specified within the configuration model gets overridden by the root_dir parameter. No arguing with her. π
And if you need to load configuration data that is, mm, not correct, you can use force_load => 1. In that case the wrong data are discarded (equivalent to check => 'no'). π
π METHODS π
π Manage configuration data π
modifyβ callsloadand thensave. Takes the same parameters asload, plus:force_writeβ force saving the configuration file even if no value was modified (default is0).quietβ do no display the changes brought by the modification steps.
loadβ load the configuration tree with configuration data. Seeloadin Config::Model::Loader for the parameters. Returns<$self>. π«Άsaveβ save the content of the configuration tree to configuration files. (Seewrite_backfor more details.) Use theforce => 1option to force saving configuration data.config_rootβ returns the root object of the configuration tree. The mother of all roots. πapply_fixesβ scan the tree and apply fixes that are attached to warning specifications. Seewarn_if_matchorwarn_unless_matchin""in Config::Model::Value. (yeah bestie, that's exactly how the original points at it, we don't question the citation.)deep_checkβ scan the tree and deep check on all elements that support this. Currently only hash or list element have this feature.needs_saveβ returns1(or more) if the instance contains data that needs to be saved. I.e. some change was done in the tree that needs to be saved. πhas_changesβ returns true if the instance contains unsasved changes. (yes, "unsasved", she said what she said π)list_changesβ in list context, returns an array ref of strings describing the changes. In scalar context, returns a big string. Useful to print. πsay_changesβ print all changes onSTDOUTand return$self.clear_changesβ clear the list of changes. Note that changes pending in the configuration tree are not affected. This clears only the list shown to the user. Use only for tests.has_warningβ returns the number of warning found in the elements of this configuration instance.updateβ parameters:( quiet => (0|1), %args )
Try to run the update method on all nodes and leaves of the configuration tree.
Nodes without an update method get ignored. update prints a message otherwise (unless quiet is true). Note that a plain Config::Model::Node has no update method. Only classes inheriting from Config::Model::Node can have update methods.
update is called on all leaves. update in Config::Model::Values is called as well, to update value from external files, like INI or YAML file, according to the user's configuration model.
The goal of the update method is to update configuration data from external data. For instance, update is called on Config::Model::Dpkg::Copyright nodes to update copyright data from sources files. π₯
grabβ use the steps parameter to retrieve and returns an object from the configuration tree. Forwarded tograbin Config::Model::Role::Grab.grab_valueβ use the steps parameter to retrieve and returns the value of a leaf object from the configuration tree. Forwarded tograb_valuein Config::Model::Role::Grab.searcherβ returns an object dedicated to search an element in the configuration model. This method returns a Config::Model::Searcher object. See Config::Model::Searcher for details on how to handle a search. πiteratorβ this method returns a Config::Model::Iterator object. See Config::Model::Iterator for details. The arguments are explained in the Config::Model::Iterator constructor arguments.applicationβ returns the application name of the instance. (E.gpopcon,dpkgβ¦) πwizard_helperβ Deprecated. Calliteratorinstead. (we do not use her anymore bestie π«)
π§ Internal methods π§
nameβ returns the instance name.read_checkβ returns which kind of check is performed while reading configuration files. (see thecheckparameter in theCONSTRUCTORsection)show_messageβ parameters:( string )
Display the message on STDOUT unless a custom function was passed to the on_message_cb parameter.
reset_configβ destroy the current configuration tree (with data) and returns a new tree with data (and annotations) loaded from disk. β¨config_modelβ returns the model (Config::Model object) of the configuration tree.annotation_saverβ returns the object loading and saving annotations. See Config::Model::Annotation for details.preset_startβ all values stored in preset mode are shown to the user as default values. This feature is useful to enter configuration data entered by an automatic process (like hardware scan). π€preset_stopβ stop preset mode.presetβ get preset mode.preset_clearβ clear all preset values stored.layered_startβ all values stored in layered mode are shown to the user as default values. This feature is useful to enter configuration data entered by an automatic process (like hardware scan). π§layered_stopβ stop layered mode.layeredβ get layered mode.layered_clearβ clear all layered values stored.get_data_modeβ returns'normal'or'preset'or'layered'. Does not take into account initial_load.initial_load_startβ start initial_load mode. This mode tracks the first modifications of the tree done with data read from the configuration file.
Instance is built with initial_load as 1. Read backend clears this value once the first read is done.
Other modifications, when initial_load is zero, are assumed to be user modifications. π
initial_load_stopβ stop initial_load mode. Instance is built with initial_load as1. Read backend clears this value once the first read is done.initial_loadβ get initial_load mode.dataβ this method provides a way to store some arbitrary data in the instance object. E.g:
$instance->data(foo => 'bar');
Later:
my $foo = $instance->data('foo'); # $foo contains 'bar'
π Read and write backend features π
Usually, a program based on config model must first create the configuration model, then load all configuration data.
This feature enables you to declare with the model a way to load configuration data (and to write it back). See Config::Model::BackendMgr for details.
backend_argβ get the cme command line argument that may be used by the backend to get the configuration file. This method is typically used in the read and write method of a backend to know where the configuration file to edit is. πroot_dirβ returns a Path::Tiny object for the root directory where configuration data is read from or written to.root_pathβ same asroot_dir.register_write_backβ parameters:( node_location )
Register a node path that is called back with the write_back method.
notify_changeβ notify that some data has changed in the tree. Seenotify_changein Config::Model::AnyThing for more details. πwrite_backβ in summary, save the content of the configuration tree to configuration files.
In more details, write_back tries to run all subroutines registered with register_write_back to write the configuration information. (See Config::Model::BackendMgr for details.)
You can specify here another config directory to write configuration data back with the config_dir parameter. This overrides the model specifications.
write_back croaks if no write call-backs are known. π
Use the force => 1 option to force saving configuration data. This is useful to write back a file even when no change is done at the semantic level, i.e. to reformat a file or remove unnecessary data. π
π AUTHOR π
Dominique Dumont, (ddumont at cpan dot org)
Give her flowers, she wrote all of this. π«ΆπΉ
β¨ SEE ALSO β¨
okay bestie, when you're done here and you wanna go meet the rest of the family π β these are the modules that ride with Config::Model::Instance:
Config::Modelβ the mothership πConfig::Model::Nodeβ the node situationConfig::Model::Loaderβ the one that loads stuff inConfig::Model::Searcherβ the one that goes hunting πConfig::Model::Valueβ the value girlies
π AUTHOR
Dominique Dumont
(yes, them again β and we're still obsessed, the range is unreal π )
π COPYRIGHT AND LICENSE
kay so legal moment, but make it cute π β this software is Copyright (c) 2005-2022 by Dominique Dumont.
And this is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999
free software, licensed correctly, we love to see it β¨
ngl, that's the whole page bestie π«Ά you read all of it, main character energy fr fr. now go instantiate something and slay π
this page came from perl v5.42.3, dated 2026-07-23, and it's the Config...nstance(3pm) page β periodt ππΈπ¦
π¦ where this page comes from
- ubuntu stonking: libconfig-model-perl 2.166-1 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms