1Config::Model::Backend:U:sJesronC(o3n)tributed Perl DocuCmoennftiagt:i:oMnodel::Backend::Json(3)
2
3
4

NAME

6       Config::Model::Backend::Json - Read and write config as a JSON data
7       structure
8

VERSION

10       version 2.129
11

SYNOPSIS

13        use Config::Model ;
14        use Data::Dumper ;
15
16        # define configuration tree object
17        my $model = Config::Model->new ;
18        $model ->create_config_class (
19           name => "MyClass",
20           element => [
21               [qw/foo bar/] => {
22                   type => 'leaf',
23                   value_type => 'string'
24               },
25               baz => {
26                   type => 'hash',
27                   index_type => 'string' ,
28                   cargo => {
29                       type => 'leaf',
30                       value_type => 'string',
31                   },
32               },
33           ],
34         rw_config  => {
35           backend => 'Json' ,
36           config_dir => '/tmp',
37           file  => 'foo.json',
38           auto_create => 1,
39         }
40        ) ;
41
42        my $inst = $model->instance(root_class_name => 'MyClass' );
43
44        my $root = $inst->config_root ;
45
46        my $steps = 'foo=yada bar="bla bla" baz:en=hello
47                    baz:fr=bonjour baz:hr="dobar dan"';
48        $root->load( steps => $steps ) ;
49        $inst->write_back ;
50
51       Now, "/tmp/foo.yml" contains:
52
53        {
54          "bar" : "bla bla",
55          "foo" : "yada",
56          "baz" : {
57             "hr" : "dobar dan",
58             "en" : "hello",
59             "fr" : "bonjour"
60          }
61        }
62

DESCRIPTION

64       This module is used directly by Config::Model to read or write the
65       content of a configuration tree written with Json syntax in
66       "Config::Model" configuration tree.
67
68       Note that undefined values are skipped for list element. I.e. if a list
69       element contains "('a',undef,'b')", the data structure only contains
70       'a','b'.
71

CONSTRUCTOR

73   new
74       Parameters: "( node => $node_obj, name => 'Json' )"
75
76       Inherited from Config::Model::Backend::Any. The constructor is called
77       by Config::Model::BackendMgr.
78
79   read
80       Of all parameters passed to this read call-back, only "file_path" is
81       used. This parameter must be a Path::Tiny.
82
83       When a file is read, "read" returns 1.
84
85   write
86       Of all parameters passed to this write call-back, only "file_path" is
87       used. This parameter must be Path::Tiny object.
88
89       "write" returns 1.
90

AUTHOR

92       Dominique Dumont, (ddumont at cpan dot org)
93

SEE ALSO

95       Config::Model, Config::Model::BackendMgr, Config::Model::Backend::Any,
96

AUTHOR

98       Dominique Dumont
99
101       This software is Copyright (c) 2005-2018 by Dominique Dumont.
102
103       This is free software, licensed under:
104
105         The GNU Lesser General Public License, Version 2.1, February 1999
106
107
108
109perl v5.28.1                      2018-12-07   Config::Model::Backend::Json(3)
Impressum