.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" 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 turned on, 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 .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" 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::Backend::IniFile 3pm" .TH Config::Model::Backend::IniFile 3pm "2014-09-24" "perl v5.20.0" "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::Backend::IniFile \- Read and write config as a INI file .SH "VERSION" .IX Header "VERSION" version 2.061 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Config::Model; \& use Log::Log4perl qw(:easy); \& Log::Log4perl\->easy_init($WARN); \& \& my $model = Config::Model\->new; \& $model\->create_config_class ( \& name => "IniClass", \& element => [ \& [qw/foo bar/] => { \& type => \*(Aqlist\*(Aq, \& cargo => {qw/type leaf value_type string/} \& } \& ] \& ); \& \& # model for free INI class name and constrained class parameters \& $model\->create_config_class( \& name => "MyClass", \& \& element => [ \& \*(Aqini_class\*(Aq => { \& type => \*(Aqhash\*(Aq, \& index_type => \*(Aqstring\*(Aq, \& cargo => { \& type => \*(Aqnode\*(Aq, \& config_class_name => \*(AqIniClass\*(Aq \& }, \& }, \& ], \& \& read_config => [ \& { \& backend => \*(AqIniFile\*(Aq, \& config_dir => \*(Aq/tmp\*(Aq, \& file => \*(Aqfoo.conf\*(Aq, \& store_class_in_hash => \*(Aqini_class\*(Aq, \& auto_create => 1, \& } \& ], \& ); \& \& my $inst = $model\->instance(root_class_name => \*(AqMyClass\*(Aq ); \& my $root = $inst\->config_root ; \& \& $root\->load(\*(Aqini_class:ONE foo=FOO1 bar=BAR1 \- \& ini_class:TWO foo=FOO2\*(Aq ); \& \& $inst\->write_back ; .Ve .PP Now \f(CW\*(C`/tmp/foo.conf\*(C'\fR will contain: .PP .Vb 3 \& ## file written by Config::Model \& [ONE] \& foo=FOO1 \& \& bar=BAR1 \& \& [TWO] \& foo=FOO2 .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is used directly by Config::Model to read or write the content of a configuration tree written with \s-1INI\s0 syntax in \&\f(CW\*(C`Config::Model\*(C'\fR configuration tree. .PP This \s-1INI\s0 file can have arbitrary comment delimiter. See the example in the \s-1SYNOPSIS\s0 that sets a semi-column as comment delimiter. By default the comment delimiter is '#' like in Shell or Perl. .PP Note that undefined values are skipped for list element. I.e. if a list element contains \f(CW\*(C`(\*(Aqa\*(Aq,undef,\*(Aqb\*(Aq)\*(C'\fR, the data structure will contain \f(CW\*(Aqa\*(Aq,\*(Aqb\*(Aq\fR. .SH "Comments" .IX Header "Comments" This backend tries to read and write comments from configuration file. The comments are stored as annotation within the configuration tree. Bear in mind that comments extraction is based on best estimation as to which parameter the comment may apply. Wrong estimations are possible. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .ie n .SS "new ( node => $node_obj, name => 'inifile' ) ;" .el .SS "new ( node => \f(CW$node_obj\fP, name => 'inifile' ) ;" .IX Subsection "new ( node => $node_obj, name => 'inifile' ) ;" Inherited from Config::Model::Backend::Any. The constructor will be called by Config::Model::BackendMgr. .SH "Parameters" .IX Header "Parameters" Optional parameters declared in the model: .IP "comment_delimiter" 4 .IX Item "comment_delimiter" Change the character that starts comments in the \s-1INI\s0 file. Default is '\f(CW\*(C`#\*(C'\fR'. .IP "store_class_in_hash" 4 .IX Item "store_class_in_hash" See \*(L"Arbitrary class name\*(R" .IP "section_map" 4 .IX Item "section_map" Is a kind of exception of the above rule. See also \*(L"Arbitrary class name\*(R" .IP "force_lc_section" 4 .IX Item "force_lc_section" Boolean. When set, sections names are converted to lowercase. .IP "force_lc_key" 4 .IX Item "force_lc_key" Idem for key name .IP "force_lc_value" 4 .IX Item "force_lc_value" Idem for all values. .IP "split_list_value" 4 .IX Item "split_list_value" Some \s-1INI\s0 values are in fact a list of items separated by a space or a comma. This parameter specifies the regex to use to split the value into a list. This applies only to \f(CW\*(C`list\*(C'\fR elements. .IP "join_list_value" 4 .IX Item "join_list_value" Conversely, the list element split with \f(CW\*(C`split_list_value\*(C'\fR needs to be written back with a string to join them. Specify this string (usually ' ' or ', ') with \f(CW\*(C`join_list_value\*(C'\fR. .IP "write_boolean_as" 4 .IX Item "write_boolean_as" Array ref. Reserved for boolean value. Specify how to write a boolean value. Default is \f(CW\*(C`[0,1]\*(C'\fR which may not be the most readable. \f(CW\*(C`write_boolean_as\*(C'\fR can be specified as \f(CW\*(C`[\*(Aqfalse\*(Aq,\*(Aqtrue\*(Aq]\*(C'\fR or \f(CW\*(C`[\*(Aqno\*(Aq,\*(Aqyes\*(Aq]\*(C'\fR. .SH "Mapping between INI structure and model" .IX Header "Mapping between INI structure and model" \&\s-1INI\s0 file typically have the same structure with 2 different conventions. The class names can be imposed by the application or may be chosen by user. .SS "Imposed class name" .IX Subsection "Imposed class name" In this case, the class names must match what is expected by the application. The elements of each class can be different. For instance: .PP .Vb 5 \& foo = foo_v \& [ A ] \& bar = bar_v \& [ B ] \& baz = baz_v .Ve .PP In this case, class \f(CW\*(C`A\*(C'\fR and class \f(CW\*(C`B\*(C'\fR will not use the same configuration class. .PP The model will have this structure: .PP .Vb 6 \& Root class \& |\- leaf element foo \& |\- node element A of class_A \& | \e\- leaf element bar \& \e\- node element B of class_B \& \e\- leaf element baz .Ve .SS "Arbitrary class name" .IX Subsection "Arbitrary class name" In this case, the class names can be chosen by the end user. Each class will have the same elements. For instance: .PP .Vb 5 \& foo = foo_v \& [ A ] \& bar = bar_v1 \& [ B ] \& bar = bar_v2 .Ve .PP In this case, class \f(CW\*(C`A\*(C'\fR and class \f(CW\*(C`B\*(C'\fR will not use the same configuration class. The model will have this structure: .PP .Vb 7 \& Root class \& |\- leaf foo \& \e\- hash element my_class_holder \& |\- key A (value is node of class_A) \& | \e\- element\-bar \& \e\- key B (value is node of class_A) \& \e\- element\-bar .Ve .PP In this case, the \f(CW\*(C`my_class_holder\*(C'\fR name is specified in \f(CW\*(C`read_config\*(C'\fR with \f(CW\*(C`store_class_in_hash\*(C'\fR parameter: .PP .Vb 8 \& read_config => [ \& { \& backend => \*(AqIniFile\*(Aq, \& config_dir => \*(Aq/tmp\*(Aq, \& file => \*(Aqfoo.ini\*(Aq, \& store_class_in_hash => \*(Aqmy_class_holder\*(Aq, \& } \& ], .Ve .PP Of course they are exceptions. For instance, in \f(CW\*(C`Multistrap\*(C'\fR, the \f(CW\*(C`[General]\*(C'\fR \&\s-1INI\s0 class must be mapped to a specific node object. This can be specified with the \f(CW\*(C`section_map\*(C'\fR parameter: .PP .Vb 11 \& read_config => [ \& { \& backend => \*(AqIniFile\*(Aq, \& config_dir => \*(Aq/tmp\*(Aq, \& file => \*(Aqfoo.ini\*(Aq, \& store_class_in_hash => \*(Aqmy_class_holder\*(Aq, \& section_map => { \& General => \*(Aqgeneral_node\*(Aq, \& } \& } \& ], .Ve .PP \&\f(CW\*(C`section_map\*(C'\fR can also map an \s-1INI\s0 class to the root node: .PP .Vb 9 \& read_config => [ \& { \& backend => \*(Aqini_file\*(Aq, \& store_class_in_hash => \*(Aqsections\*(Aq, \& section_map => { \& General => \*(Aq!\*(Aq \& }, \& } \& ], .Ve .SH "Methods" .IX Header "Methods" .SS "read ( io_handle => ... )" .IX Subsection "read ( io_handle => ... )" Of all parameters passed to this read call-back, only \f(CW\*(C`io_handle\*(C'\fR is used. This parameter must be IO::File object already opened for read. .PP It can also be undef. In this case, \f(CW\*(C`read()\*(C'\fR will return 0. .PP When a file is read, \f(CW\*(C`read()\*(C'\fR will return 1. .SS "write ( io_handle => ... )" .IX Subsection "write ( io_handle => ... )" Of all parameters passed to this write call-back, only \f(CW\*(C`io_handle\*(C'\fR is used. This parameter must be IO::File object already opened for write. .PP \&\f(CW\*(C`write()\*(C'\fR will return 1. .SH "AUTHOR" .IX Header "AUTHOR" Dominique Dumont, (ddumont at cpan dot org); Krzysztof Tyszecki, (krzysztof.tyszecki at gmail dot com) .SH "SEE ALSO" .IX Header "SEE ALSO" Config::Model, Config::Model::BackendMgr, Config::Model::Backend::Any, .SH "AUTHOR" .IX Header "AUTHOR" Dominique Dumont .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2014 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