1Config::Model::Backend:U:sPelraiCnoFnitlrei(b3u)ted PerlCoDnofciugm:e:nMtoadteilo:n:Backend::PlainFile(3)
2
3
4

NAME

6       Config::Model::Backend::PlainFile - Read and write config as plain file
7

VERSION

9       version 2.141
10

SYNOPSIS

12        use Config::Model;
13
14        my $model = Config::Model->new;
15
16        my $inst = $model->create_config_class(
17           name => "WithPlainFile",
18           element => [
19               [qw/source new/] => { qw/type leaf value_type uniline/ },
20           ],
21           rw_config  => {
22             backend => 'plain_file',
23             config_dir => '/tmp',
24           },
25        );
26
27        my $inst = $model->instance(root_class_name => 'WithPlainFile' );
28        my $root = $inst->config_root ;
29
30        $root->load('source=foo new=yes' );
31
32        $inst->write_back ;
33
34       Now "/tmp" directory contains 2 files: "source" and "new" with "foo"
35       and "yes" inside.
36

DESCRIPTION

38       This module is used directly by Config::Model to read or write the
39       content of a configuration tree written in several files.  Each element
40       of the node is written in a plain file.
41

Element type and file mapping

43       Element values are written in one or several files depending on their
44       type.
45
46       leaf
47           The leaf value is written in one file. This file can have several
48           lines if the leaf type is "string"
49
50       list
51           The list content is written in one file. Each line of the file is a
52           value of the list.
53
54       hash
55           Not supported
56

File mapping

58       By default, the configuration file is named after the element name
59       (like in synopsis above).
60
61       The "file" parameter can also be used to specify a file name that take
62       into account the path in the tree using "&index()" and "&element()"
63       functions from Config::Model::Role::ComputeFunction.
64
65       For instance, with the following model:
66
67           class_name => "Foo",
68           element => [
69               string_a => { type => 'leaf', value_type => 'string'}
70               string_b => { type => 'leaf', value_type => 'string'}
71           ],
72           rw_config => {
73               backend => 'PlainFile',
74               config_dir => 'foo',
75               file => '&element(-).&element',
76               file_mode => 0644,  # optional
77           }
78
79       If the configuration is loaded with "example string_a=something
80       string_b=else", this backend writes ""something"" in file
81       "example.string_a" and "else" in file "example.string_b".
82
83       "file_mode" parameter can be used to set the mode of the written file.
84       "file_mode" value can be in any form supported by "chmod" in
85       Path::Tiny.
86

Methods

88   read_leaf
89       Parameters: "(obj, elt, check, file, args)"
90
91       Called by read method to read the file of a leaf element. "args"
92       contains the arguments passed to read method.
93
94   read_hash (obj,elt,check,file,args);
95       Like read_leaf for hash elements.
96
97   read_list
98       Parameters: "(obj, elt, check, file, args)"
99
100       Like read_leaf for list elements.
101
102   write
103       "write" writes a file for each element of the calling class. Works only
104       for leaf and list elements. Other element type are skipped. Always
105       return 1 (unless it died before).
106

AUTHOR

108       Dominique Dumont, (ddumont at cpan dot org)
109

SEE ALSO

111       Config::Model, Config::Model::BackendMgr, Config::Model::Backend::Any,
112

AUTHOR

114       Dominique Dumont
115
117       This software is Copyright (c) 2005-2021 by Dominique Dumont.
118
119       This is free software, licensed under:
120
121         The GNU Lesser General Public License, Version 2.1, February 1999
122
123
124
125perl v5.32.1                      2021-01-2C7onfig::Model::Backend::PlainFile(3)
Impressum