.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Config::Model::Instance 3pm" .TH Config::Model::Instance 3pm "2017-05-14" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Config::Model::Instance \- Instance of configuration tree .SH "VERSION" .IX Header "VERSION" version 2.097 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Config::Model; \& use File::Path ; \& \& # setup a dummy popcon conf file \& my $wr_dir = \*(Aq/tmp/etc/\*(Aq; \& my $conf_file = "$wr_dir/popularity\-contest.conf" ; \& \& unless (\-d $wr_dir) { \& mkpath($wr_dir, { mode => 0755 }) \& || die "can\*(Aqt mkpath $wr_dir: $!"; \& } \& open(my $conf,"> $conf_file" ) || die "can\*(Aqt open $conf_file: $!"; \& $conf\->print( qq!MY_HOSTID="aaaaaaaaaaaaaaaaaaaa"\en!, \& qq!PARTICIPATE="yes"\en!, \& qq!USEHTTP="yes" # always http\en!, \& qq!DAY="6"\en!); \& $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 => \*(AqPopCon\*(Aq, \& root_dir => \*(Aq/tmp\*(Aq, \& ); \& my $root = $inst \-> config_root ; \& \& print $root\->describe; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides an object that holds a configuration tree. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" An instance object is created by calling instance method on an existing model. This model can be specified by its application name: .PP .Vb 6 \& my $inst = $model\->instance ( \& # run \*(Aqcme list\*(Aq to get list of applications \& application => \*(Aqfoo\*(Aq, \& # optional \& instance_name => \*(Aqtest1\*(Aq \& ); \& \& my $inst = $model\->instance ( \& root_class_name => \*(AqSomeRootClass\*(Aq, \& instance_name => \*(Aqtest1\*(Aq \& ); .Ve .PP The directory (or directories) holding configuration files is specified within the configuration model. For test purpose you can change the \*(L"root\*(R" directory with \f(CW\*(C`root_dir\*(C'\fR parameter: .IP "root_dir" 4 .IX Item "root_dir" Pseudo root directory where to read \fIand\fR write configuration files. Configuration directory specified in model or with \&\f(CW\*(C`config_dir\*(C'\fR option is appended to this root directory .IP "config_dir" 4 .IX Item "config_dir" Directory to read or write configuration file. This parameter must be supplied if not provided by the configuration model. .IP "backend" 4 .IX Item "backend" Specify which backend to use. See \*(L"write_back ( ... )\*(R" for details .IP "check" 4 .IX Item "check" Specify whether to check value while reading config files. Either: .RS 4 .IP "yes" 4 .IX Item "yes" Check value and throws an error for bad values. .IP "skip" 4 .IX Item "skip" Check value and skip bad value. .IP "no" 4 .IX Item "no" Do not check. .RE .RS 4 .RE .IP "on_change_cb" 4 .IX Item "on_change_cb" Call back this function whenever \f(CW\*(C`notify_change\*(C'\fR is called. Called with arguments: \f(CW\*(C`name => , index => \*(C'\fR .IP "on_message_cb" 4 .IX Item "on_message_cb" Call back this function when show_message is called. By default, messages are displayed on \s-1STDOUT.\s0 .IP "error_paths" 4 .IX Item "error_paths" Returns a list of tree items that currently have an error. .IP "error_messages" 4 .IX Item "error_messages" Returns a list of error messages from the tree content. .PP Note that the root directory specified within the configuration model is overridden by \f(CW\*(C`root_dir\*(C'\fR parameter. .PP If you need to load configuration data that are not correct, you can use \f(CW\*(C`force_load => 1\*(C'\fR. Then, wrong data are discarded (equivalent to \&\f(CW\*(C`check =\*(C'\fR 'no'> ). .SH "METHODS" .IX Header "METHODS" .SS "Manage configuration data" .IX Subsection "Manage configuration data" .SS "modify ( ... )" .IX Subsection "modify ( ... )" Calls \*(L"load(...)\*(R" and then \*(L"save\*(R". .PP Takes the same parameter as \f(CW\*(C`load\*(C'\fR plus \f(CW\*(C`force_write\*(C'\fR to force saving configuration file even if no value was modified (default is 0) .SS "load ( ... )" .IX Subsection "load ( ... )" Load configuration tree with configuration data. See \&\*(L"load ( ... )\*(R" in Config::Model::Loader for parameters. Returns <$self>. .SS "save ( ... )" .IX Subsection "save ( ... )" Save the content of the configuration tree to configuration files. (alias to \f(CW\*(C`write_back\*(C'\fR) .SS "\fIconfig_root()\fP" .IX Subsection "config_root()" Returns the root object of the configuration tree. .SS "apply_fixes" .IX Subsection "apply_fixes" Scan the tree and apply fixes that are attached to warning specifications. See \f(CW\*(C`warn_if_match\*(C'\fR or \f(CW\*(C`warn_unless_match\*(C'\fR in "" in Config::Model::Value. .SS "deep_check" .IX Subsection "deep_check" Scan the tree and deep check on all elements that support this. Currently only hash or list element have this feature. .SS "needs_save" .IX Subsection "needs_save" Returns 1 (or more) if the instance contains data that needs to be saved. I.e some change were done in the tree that needs to be saved. .SS "list_changes" .IX Subsection "list_changes" In list context, returns a array ref of strings describing the changes. In scalar context, returns a big string. Useful to print. .SS "say_changes" .IX Subsection "say_changes" Print all changes on \s-1STDOUT\s0 and return the list of changes. .SS "clear_changes" .IX Subsection "clear_changes" Clear list of changes. Note that changes pending in the configuration tree is not affected. This clears only the list shown to user. Use only for tests. .SS "has_warning" .IX Subsection "has_warning" Returns the number of warning found in the elements of this configuration instance. .ie n .SS "update( quiet => (0|1), %args )" .el .SS "update( quiet => (0|1), \f(CW%args\fP )" .IX Subsection "update( quiet => (0|1), %args )" Try to run update command on all nodes of the configuration tree. Node without \f(CW\*(C`update\*(C'\fR method are ignored. \f(CW\*(C`update\*(C'\fR prints a message otherwise (unless \f(CW\*(C`quiet\*(C'\fR is true). .SS "searcher ( )" .IX Subsection "searcher ( )" Returns an object dedicated to search an element in the configuration model (respecting privilege level). .PP This method returns a Config::Model::Searcher object. See Config::Model::Searcher for details on how to handle a search. .SS "iterator" .IX Subsection "iterator" This method returns a Config::Model::Iterator object. See Config::Model::Iterator for details. .PP Arguments are explained in Config::Model::Iterator constructor arguments. .SS "application" .IX Subsection "application" Returns the application name of the instance. (E.g \f(CW\*(C`popcon\*(C'\fR, \f(CW\*(C`dpkg\*(C'\fR ...) .SS "wizard_helper ( ... )" .IX Subsection "wizard_helper ( ... )" Deprecated. Call \*(L"iterator\*(R" instead. .SH "Internal methods" .IX Header "Internal methods" .SS "\fIname()\fP" .IX Subsection "name()" Returns the instance name. .SS "\fIread_check()\fP" .IX Subsection "read_check()" Returns which kind of check is performed while reading configuration files. (see \f(CW\*(C`check\*(C'\fR parameter in \*(L"\s-1CONSTRUCTOR\*(R"\s0 section) .SS "show_message( string )" .IX Subsection "show_message( string )" Display the message on \s-1STDOUT\s0 unless a custom function was passed to \&\f(CW\*(C`on_message_cb\*(C'\fR parameter. .SS "reset_config" .IX Subsection "reset_config" Destroy current configuration tree (with data) and returns a new tree with data (and annotations) loaded from disk. .SS "\fIconfig_model()\fP" .IX Subsection "config_model()" Returns the model (Config::Model object) of the configuration tree. .SS "\fIannotation_saver()\fP" .IX Subsection "annotation_saver()" Returns the object loading and saving annotations. See Config::Model::Annotation for details. .SS "preset_start ()" .IX Subsection "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) .SS "preset_stop ()" .IX Subsection "preset_stop ()" Stop preset mode .SS "preset ()" .IX Subsection "preset ()" Get preset mode .SS "\fIpreset_clear()\fP" .IX Subsection "preset_clear()" Clear all preset values stored. .SS "layered_start ()" .IX Subsection "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) .SS "layered_stop ()" .IX Subsection "layered_stop ()" Stop layered mode .SS "layered ()" .IX Subsection "layered ()" Get layered mode .SS "\fIlayered_clear()\fP" .IX Subsection "layered_clear()" Clear all layered values stored. .SS "get_data_mode" .IX Subsection "get_data_mode" Returns 'normal' or 'preset' or 'layered'. Does not take into account initial_load. .SS "initial_load_stop ()" .IX Subsection "initial_load_stop ()" Stop initial_load mode. Instance is built with initial_load as 1. Read backend clears this value once the first read is done. .SS "initial_load ()" .IX Subsection "initial_load ()" Get initial_load mode .SS "data( kind, [data] )" .IX Subsection "data( kind, [data] )" The data method provide a way to store some arbitrary data in the instance object. .SH "Auto read and write feature" .IX Header "Auto read and write feature" Usually, a program based on config model must first create the configuration model, then load all configuration data. .PP 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. .SS "\fIbackend()\fP" .IX Subsection "backend()" Get the preferred backend method for this instance (as passed to the constructor). .SS "\fIroot_dir()\fP" .IX Subsection "root_dir()" Returns root directory where configuration data is read from or written to. .SS "register_write_back ( node_location )" .IX Subsection "register_write_back ( node_location )" Register a node path that is called back with \&\f(CW\*(C`write_back\*(C'\fR method. .SS "notify_change" .IX Subsection "notify_change" Notify that some data has changed in the tree. See \&\*(L"notify_change(...)\*(R" in Config::Model::AnyThing for more details. .SS "write_back ( ... )" .IX Subsection "write_back ( ... )" In summary, save the content of the configuration tree to configuration files. .PP In more details, \f(CW\*(C`write_back\*(C'\fR trie to run all subroutines registered with \f(CW\*(C`register_write_back\*(C'\fR to write the configuration information until one succeeds (returns true). (See Config::Model::BackendMgr for details). .PP You can specify here a pseudo root directory or another config directory to write configuration data back with \f(CW\*(C`root\*(C'\fR and \&\f(CW\*(C`config_dir\*(C'\fR parameters. This overrides the model specifications. .PP You can force to use a backend by specifying \f(CW\*(C`backend => xxx\*(C'\fR. For instance, \f(CW\*(C`backend => \*(Aqaugeas\*(Aq\*(C'\fR or \f(CW\*(C`backend => \*(Aqcustom\*(Aq\*(C'\fR. .PP You can force to use all backend to write the files by specifying \&\f(CW\*(C`backend => \*(Aqall\*(Aq\*(C'\fR. .PP \&\f(CW\*(C`write_back\*(C'\fR croaks if no write call-back are known. .SH "AUTHOR" .IX Header "AUTHOR" Dominique Dumont, (ddumont at cpan dot org) .SH "SEE ALSO" .IX Header "SEE ALSO" Config::Model, Config::Model::Node, Config::Model::Loader, Config::Model::Searcher, Config::Model::Value, .SH "AUTHOR" .IX Header "AUTHOR" Dominique Dumont .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2005\-2016 by Dominique Dumont. .PP This is free software, licensed under: .PP .Vb 1 \& The GNU Lesser General Public License, Version 2.1, February 1999 .Ve