Config-Model-Backend-Yaml-2.134/0000755000175000017500000000000014002607357014661 5ustar domidomiConfig-Model-Backend-Yaml-2.134/README.md0000644000175000017500000000271514002607357016145 0ustar domidomi[![](https://travis-ci.org/dod38fr/config-model-backend-yaml.svg?branch=master)](https://travis-ci.org/dod38fr/config-model-backend-yaml) # config-model-backend-yaml YAML read/write plugin for [Config::Model](https://github.com/dod38fr/config-model/wiki) ## Description A plugin to let [cme](https://metacpan.org/pod/distribution/App-Cme/bin/cme) and [Config::Model](https://github.com/dod38fr/config-model/wiki) read and write Yaml files. ## Usage Once this module is installed, you can modify a model to specify a `YAML` backend, either with [cme meta edit](https://github.com/dod38fr/config-model/wiki/How-to-add-a-new-parameter-to-an-existing-model) or using Perl code. See the example in [Config::Model::BackendMgr synopsis](https://metacpan.org/pod/Config::Model::BackendMgr#SYNOPSIS) ## Installation ### Debian, Ubuntu Run: apt install cme libconfig-model-backend-yaml-perl ### Others You can also install this project from CPAN: cpanm install App::Cme cpanm install Config::Model::Backend::Yaml ### From GitHub You may also follow these [instructions](README-build-from-git.md) to install and build from git. ## Problems ? Please report any issue on https://github.com/dod38fr/config-model-backend-yaml/issues ## More information * [Using cme](https://github.com/dod38fr/config-model/wiki/Using-cme) * An example that shows how to [update a model](https://github.com/dod38fr/config-model/wiki/How-to-add-a-new-parameter-to-an-existing-model) Config-Model-Backend-Yaml-2.134/META.json0000644000175000017500000000413114002607357016301 0ustar domidomi{ "abstract" : "Read and write config as a YAML data structure", "author" : [ "Dominique Dumont" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010", "license" : [ "lgpl_2_1" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Config-Model-Backend-Yaml", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.34" } }, "configure" : { "requires" : { "Module::Build" : "0.34" } }, "runtime" : { "requires" : { "Carp" : "0", "Config::Model" : "2.131", "Config::Model::Backend::Any" : "0", "Config::Model::Exception" : "0", "File::Path" : "0", "Log::Log4perl" : "0", "YAML::XS" : "0.69", "base" : "0", "boolean" : "0", "parent" : "0", "perl" : "v5.12.0", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Config::Model::Tester" : "4.001", "Config::Model::Tester::Setup" : "0", "ExtUtils::testlib" : "0", "Path::Tiny" : "0", "Test::Memory::Cycle" : "0", "Test::More" : "0", "lib" : "0", "utf8" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "ddumont at cpan.org", "web" : "https://github.com/dod38fr/config-model-backend-yaml/issues" }, "homepage" : "https://github.com/dod38fr/config-model/wiki", "repository" : { "type" : "git", "url" : "git://github.com/dod38fr/config-model-backend-yaml.git", "web" : "http://github.com/dod38fr/config-model-backend-yaml" } }, "version" : "2.134", "x_generated_by_perl" : "v5.32.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.25", "x_spdx_expression" : "LGPL-2.1" } Config-Model-Backend-Yaml-2.134/weaver.ini0000644000175000017500000000022014002607357016645 0ustar domidomi[@Default] [-Transformer] transformer = List [Support] perldoc = 0 bugs = metadata websites = search,ratings,kwalitee,testers,testmatrix,deps Config-Model-Backend-Yaml-2.134/Changes0000644000175000017500000000105614002607357016156 0ustar domidomi2.134 2021-01-22 * fail test if object can be loaded with YAML * use new style of model_test spec (tests require Config::Model::Tester 4.001) 2.133 2018-12-29 * fix read/write of UTF-8 data 2.132 2018-12-16 * Depends on Config::Model 2.131 2.131 2018-12-10 This module was spinned off Config::Model 2.130. Here are the changes since version 2.130: * Read and write boolean values to and from YAML (Depends on YAML::XS) * YAML::XS is configured to ignore Perl/* tags. I.e. Perl object cannot be created with this backend. Config-Model-Backend-Yaml-2.134/CONTRIBUTING.md0000644000175000017500000000524314002607357017116 0ustar domidomi# How to contribute # ## Ask questions ## Yes, asking a question is a form of contribution that helps the author to improve documentation. Feel free to ask questions by sending a mail to the [author](mailto:ddumont@cpan.org) ## Log a bug ## Please report issue on https://github.com/dod38fr/config-model-backend-yaml/issues ## Source code structure ## The main parts of this modules are: * `lib/Config/Model/Backend/Yaml.pm`: the "main" file of the Perl package. YAML data is converted to a Perl data structure by YAML::XS and loaded into Config::Model (through [Config::Model::BackendMgr](https://metacpan.org/pod/Config::Model::BackendMgr). The reverse is done when writing back data. * `t`: test files. Run the tests with `prove -l t` * `t/model_tests.d` test the YAML backend using [Config::Model::Tester](http://search.cpan.org/dist/Config-Model-Tester/lib/Config/Model/Tester.pm). Use `prove -l t/model_test.t` command to run only model tests. ## Edit source code from github ## If you have a github account, you can clone a repo and prepare a pull-request. You can: * run `git clone https://github.com/dod38fr/config-model-backend-yaml/` * edit files * run `prove -l t` to run non-regression tests There's no need to worry about `dzil`, `Dist::Zilla` or `dist.ini` files. These are useful to prepare a new release, but not to fix bugs. ## Edit source code from Debian source package ## You can also prepare a patch using Debian source package: For instance: * download and unpack `apt-get source libconfig-model-backend-yaml-perl` * jump in `cd libconfig-model-backend-yaml-perl-0.xxx` * useful to create a patch later: `git init` * commit all files: `git add -A ; git commit -m"committed all"` * edit files * run `prove -l t` to run non-regression tests * run `git diff` and send the output to the [author](mailto:ddumont@cpan.org) ## Edit source code from Debian source package or CPAN tarball ## Non Debian users can also prepare a patch using CPAN tarball: * Download tar file from http://search.cpan.org * unpack tar file with something like `tar axvf Config-Model-Backend-Yaml-1.xxx.tar.gz` * jump in `cd Config-Model-Backend-Yaml-xxx` * useful to create a patch later: `git init` * commit all files: `git add -A ; git commit -m"committed all"` * edit files * run `prove -l t` to run non-regression tests * run `git diff` and send the output to the [author](mailto:ddumont@cpan.org) ## Provide feedback ## Feedback is important. Please take a moment to rate, comment or add stars to this project: * [config-model github](https://github.com/dod38fr/config-model-backend-yaml) or [config-model cpan ratings](http://cpanratings.perl.org/rate/?distribution=Config::Model::Backend::Yaml) Config-Model-Backend-Yaml-2.134/MANIFEST.SKIP0000644000175000017500000000016514002607357016561 0ustar domidomi^debian/ ~$ \.ptkdb$ \.old$ dist.ini libconfig _build \.orig$ ^MYMETA.yml$ blib wr_root \.rej$ README.build-from-git Config-Model-Backend-Yaml-2.134/Build.PL0000644000175000017500000000266614002607357016167 0ustar domidomi# # This file is part of Config-Model-Backend-Yaml # # This software is Copyright (c) 2018 by Dominique Dumont. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use Module::Build; use warnings; use strict; require 5.010001 ; my @version_info = @ARGV ? ( dist_version => $ARGV[0] ) : (); my $build = Module::Build->new( module_name => 'Config::Model::Backend::Yaml', @version_info, license => 'lgpl', dist_abstract => 'Config::Model plugin to read and write YAML files', dist_author => 'Dominique Dumont (ddumont at cpan dot org)', 'build_requires' => { 'Config::Model::Tester' => '4.001', 'Config::Model::Tester::Setup' => '0', 'ExtUtils::testlib' => '0', 'Module::Build' => '0.34', 'Path::Tiny' => '0', 'Test::Memory::Cycle' => '0', 'Test::More' => '0', 'lib' => '0', 'utf8' => '0' }, 'configure_requires' => { 'Module::Build' => '0.34' }, 'requires' => { 'Carp' => '0', 'Config::Model' => '2.131', 'Config::Model::Backend::Any' => '0', 'Config::Model::Exception' => '0', 'File::Path' => '0', 'Log::Log4perl' => '0', 'YAML::XS' => '0.69', 'base' => '0', 'boolean' => '0', 'parent' => '0', 'perl' => 'v5.12.0', 'strict' => '0', 'warnings' => '0' }, add_to_cleanup => [ qw/wr_root/ ], ); $build->add_build_element('pl'); $build->create_build_script; Config-Model-Backend-Yaml-2.134/lib/0000755000175000017500000000000014002607357015427 5ustar domidomiConfig-Model-Backend-Yaml-2.134/lib/Config/0000755000175000017500000000000014002607357016634 5ustar domidomiConfig-Model-Backend-Yaml-2.134/lib/Config/Model/0000755000175000017500000000000014002607357017674 5ustar domidomiConfig-Model-Backend-Yaml-2.134/lib/Config/Model/Backend/0000755000175000017500000000000014002607357021223 5ustar domidomiConfig-Model-Backend-Yaml-2.134/lib/Config/Model/Backend/Yaml.pm0000644000175000017500000001735114002607357022472 0ustar domidomi# # This file is part of Config-Model-Backend-Yaml # # This software is Copyright (c) 2018 by Dominique Dumont. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # package Config::Model::Backend::Yaml; $Config::Model::Backend::Yaml::VERSION = '2.134'; use 5.10.1; use Carp; use strict; use warnings; use Config::Model 2.131; use Config::Model::Exception; use File::Path; use Log::Log4perl qw(get_logger :levels); use boolean; use YAML::XS 0.69; use base qw/Config::Model::Backend::Any/; my $logger = get_logger("Backend::Yaml"); sub single_element { my $self = shift; my @elts = $self->node->children; return if @elts != 1; my $obj = $self->node->fetch_element($elts[0]); my $type = $obj->get_type; return $type =~ /^(list|hash)$/ ? $obj : undef ; } sub read { my $self = shift; my %args = @_; local $YAML::XS::LoadBlessed = 0; # args is: # object => $obj, # Config::Model::Node object # root => './my_test', # fake root directory, userd for tests # config_dir => /etc/foo', # absolute path # file => 'foo.conf', # file name # file_path => './my_test/etc/foo/foo.conf' # check => yes|no|skip return 0 unless $args{file_path}->exists; # no file to read # load yaml file my $yaml = $args{file_path}->slurp_raw; # convert to perl data my $perl_data = Load($yaml) ; if ( not defined $perl_data ) { my $msg = "No data found in YAML file $args{file_path}"; if ($args{auto_create}) { $logger->info($msg); } else { $logger->warn($msg); } return 1; } my $target = $self->single_element // $self->node ; # load perl data in tree $target->load_data( data => $perl_data, check => $args{check} || 'yes' ); return 1; } sub write { my $self = shift; my %args = @_; # args is: # object => $obj, # Config::Model::Node object # root => './my_test', # fake root directory, userd for tests # config_dir => /etc/foo', # absolute path # file => 'foo.conf', # file name # file_path => './my_test/etc/foo/foo.conf' # check => yes|no|skip local $YAML::XS::Boolean = "boolean"; my $target = $self->single_element // $self->node ; my $perl_data = $target->dump_as_data( full_dump => $args{full_dump} // 0, to_boolean => sub { return boolean($_[0]) } ); my $yaml = Dump( $perl_data ); $args{file_path}->spew_raw($yaml); return 1; } 1; # ABSTRACT: Read and write config as a YAML data structure __END__ =pod =encoding UTF-8 =head1 NAME Config::Model::Backend::Yaml - Read and write config as a YAML data structure =head1 VERSION version 2.134 =head1 SYNOPSIS use Config::Model ; use Data::Dumper ; # define configuration tree object my $model = Config::Model->new ; $model ->create_config_class ( name => "MyClass", element => [ [qw/foo bar/] => { type => 'leaf', value_type => 'string' }, baz => { type => 'hash', index_type => 'string' , cargo => { type => 'leaf', value_type => 'string', }, }, ], rw_config => { backend => 'yaml', config_dir => '/tmp', file => 'foo.yml', auto_create => 1, } ) ; my $inst = $model->instance(root_class_name => 'MyClass' ); my $root = $inst->config_root ; my $steps = 'foo=yada bar="bla bla" baz:en=hello baz:fr=bonjour baz:hr="dobar dan"'; $root->load( steps => $steps ) ; $inst->write_back ; Now, C contains: --- bar: bla bla baz: en: hello fr: bonjour hr: dobar dan foo: yada =head1 DESCRIPTION This module is used directly by L to read or write the content of a configuration tree written with YAML syntax in C configuration tree. Note: =over 4 =item * Undefined values are skipped for list element. I.e. if a list element contains C<('a',undef,'b')>, the data structure contains C<'a','b'>. =item * YAML file is not created (and may be deleted) when no data is to be written. =back =head2 Class with only one hash element If the root node contains a single hash or list element, only the content of this hash is written in a YAML file. For example, if a class contains: element => [ baz => { type => 'hash', index_type => 'string' , cargo => { type => 'leaf', value_type => 'string', }, }, If the configuration is loaded with: $root->load("baz:one=un baz:two=deux") Then the written YAML file does B show C: --- one: un two: deux Likewise, a YAML file for a class with a single list C element would be written with: --- - un - deux =head1 YAML class As of v2.129, this backend uses L 0.69 or later. For security reason, loading a Perl blessed object is disabled. Value of type boolean are written as boolean values in YAML files. =head1 backend parameter =head2 yaml_class This parameter is ignored as of version 2.129. =head1 CONSTRUCTOR =head2 new Parameters: C<< ( node => $node_obj, name => 'yaml' ) >> Inherited from L. The constructor is called by L. =head2 read Read YAML file and load into C<$node_obj> tree. When a file is read, C returns 1. =head2 write Write YAML File using C<$node_obj> data. C returns 1. =head1 AUTHOR Dominique Dumont, (ddumont at cpan dot org) =head1 SEE ALSO L, L, L, L =head1 AUTHOR Dominique Dumont =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2018 by Dominique Dumont. This is free software, licensed under: The GNU Lesser General Public License, Version 2.1, February 1999 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Websites The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources. =over 4 =item * CPANTS The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. L =item * CPAN Testers The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions. L =item * CPAN Testers Matrix The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. L =item * CPAN Testers Dependencies The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. L =back =head2 Bugs / Feature Requests Please report any bugs or feature requests by email to C, or through the web interface at L. You will be automatically notified of any progress on the request by the system. =head2 Source Code The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :) L git clone git://github.com/dod38fr/config-model-backend-yaml.git =cut Config-Model-Backend-Yaml-2.134/t/0000755000175000017500000000000014002607357015124 5ustar domidomiConfig-Model-Backend-Yaml-2.134/t/README.md0000644000175000017500000000176514002607357016414 0ustar domidomi## Running the tests All tests can be run in parrallel with prove -j8 t/ ### Test options Most tests can be run with the options provided by [Config::Model::Tester::Setup](https://metacpan.org/pod/Config::Model::Tester::Setup): * `-trace`: show more information * `-error`: show stack stace in case of error * `-log`: Enable logs (you may need to tweak `~/.log4config-model` to get more trace. See [cme/Logging](https://metacpan.org/pod/distribution/App-Cme/bin/cme#Logging) for more details. ### model_tests.t This test is set of subtests made of test cases. It accepts arguments to limit the test to one subtest and one test case: perl t/model_test.t [ --log ] [--error] [--trace] [ subtest [ test_case ] ] See [Config::Model::Tester](https://metacpan.org/pod/Config::Model::Tester) for more details. ### Running with prove You can run all tests with prove -j8 t/ To run with local files: prove -l -j8 t/ You can pass parameter to test files with: prove -l t/ :: --log Config-Model-Backend-Yaml-2.134/t/model_tests.d/0000755000175000017500000000000014002607357017670 5ustar domidomiConfig-Model-Backend-Yaml-2.134/t/model_tests.d/backend-yaml-examples/0000755000175000017500000000000014002607357024033 5ustar domidomiConfig-Model-Backend-Yaml-2.134/t/model_tests.d/backend-yaml-examples/basic0000644000175000017500000000023314002607357025035 0ustar domidomi--- localhost: ipaddr: 127.0.0.1 alias: localhost bilbo: !!perl/hash:SneakyObject ipaddr: 192.168.0.1 yada: # Local Variables: # mode: yaml # End: Config-Model-Backend-Yaml-2.134/t/model_tests.d/backend-yaml-data-examples/0000755000175000017500000000000014002607357024742 5ustar domidomiConfig-Model-Backend-Yaml-2.134/t/model_tests.d/backend-yaml-data-examples/utf8_data0000644000175000017500000000006614002607357026546 0ustar domidomi# -*- yaml -*- --- utf8_string: Марцел Mézigue Config-Model-Backend-Yaml-2.134/t/model_tests.d/backend-yaml-data-examples/basic0000644000175000017500000000010314002607357025740 0ustar domidomi# -*- yaml -*- --- true_bool: true false_bool: false null_value: ~ Config-Model-Backend-Yaml-2.134/t/model_tests.d/backend-yaml-data-test-conf.pl0000644000175000017500000000322314002607357025363 0ustar domidomi# # This file is part of Config-Model-Backend-Yaml # # This software is Copyright (c) 2018 by Dominique Dumont. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use strict; use warnings; use utf8; my @config_classes = ({ name => 'Master', rw_config => { backend => 'yaml', config_dir => '/etc/', file => 'test.yaml', }, element => [ true_bool => { qw/type leaf value_type boolean upstream_default 0/}, false_bool => { qw/type leaf value_type boolean upstream_default 0/}, new_bool => { qw/type leaf value_type boolean upstream_default 0/}, null_value => { qw/type leaf value_type uniline/}, utf8_string => { qw/type leaf value_type uniline/}, ] }); my @tests = ( { name => 'basic', check => [ # values are translated from whatever YAML lib returns to true and false true_bool => 1, false_bool => 0, null_value => undef ], load => 'new_bool=1', file_contents => { # test that file contains real booleans "/etc/test.yaml" => "---\nfalse_bool: false\nnew_bool: true\ntrue_bool: true\n", } }, { name => 'utf8_data', check => [ utf8_string => "Марцел Mézigue" ], file_contents_like => { "/etc/test.yaml" => [ qr/Марцел Mézigue/ ] , } } ); return { model_to_test => "Master", conf_dir => '/etc', conf_file_name => 'test.yaml', config_classes => \@config_classes, tests => \@tests }; Config-Model-Backend-Yaml-2.134/t/model_tests.d/backend-yaml-test-conf.pl0000644000175000017500000000243714002607357024462 0ustar domidomi# # This file is part of Config-Model-Backend-Yaml # # This software is Copyright (c) 2018 by Dominique Dumont. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # use strict; use warnings; my @config_classes = ({ name => 'Host', element => [ [qw/ipaddr alias/] => { type => 'leaf', value_type => 'uniline', }, dummy => {qw/type leaf value_type uniline/}, ] }); push @config_classes, { name => 'Hosts', rw_config => { backend => 'yaml', config_dir => '/etc/', file => 'hosts.yaml', }, element => [ record => { type => 'hash', index_type => 'string', write_empty_value => 1, cargo => { type => 'node', config_class_name => 'Host', }, }, ] }; my @tests = ( { name => 'basic', check => [ 'record:localhost ipaddr' => '127.0.0.1', 'record:bilbo ipaddr' => '192.168.0.1' ] }, ); return { model_to_test => "Hosts", conf_dir => '/etc', conf_file_name => 'hosts.yaml', config_classes => \@config_classes, tests => \@tests }; Config-Model-Backend-Yaml-2.134/t/backend_yaml.t0000644000175000017500000001113014002607357017716 0ustar domidomi# -*- cperl -*- use ExtUtils::testlib; use Test::More; use Test::Memory::Cycle; use Config::Model; use Path::Tiny; use Config::Model::Tester::Setup qw/init_test setup_test_dir/; use warnings; use strict; use lib "t/lib"; my ($model, $trace) = init_test(); # pseudo root where config files are written by config-model my $wr_root = setup_test_dir(); my $yaml_dir = $wr_root->child('yaml'); $yaml_dir->mkpath(); my $load = "record:0 ipaddr=127.0.0.1 canonical=localhost alias=localhost - record:1 ipaddr=192.168.0.1 canonical=bilbo - - "; my $yaml_file = $yaml_dir ->child('hosts.yml'); subtest 'Create YAML file from scratch' => sub { my $i_hosts = $model->instance( instance_name => 'hosts_inst', root_class_name => 'Hosts', root_dir => $wr_root->stringify, model_file => 'test_yaml_model.pl', ); ok( $i_hosts, "Created instance" ); my $i_root = $i_hosts->config_root; $i_root->load($load); $i_hosts->write_back; ok( 1, "yaml write back done" ); # TODO: test yaml content for skipped element ok( $yaml_file->exists, "check that config file $yaml_file was written" ); my $written = $yaml_file->slurp; unlike($written, qr/record/, "check that list element name is not written"); }; subtest 'test automatic file backup' => sub { my $i_hosts = $model->instance( instance_name => 'hosts_inst_backup', root_class_name => 'Hosts', root_dir => $wr_root->stringify, model_file => 'test_yaml_model.pl', backup => '' ); ok( $i_hosts, "Created instance" ); my $i_root = $i_hosts->config_root; $i_root->load("record:2 ipaddr=192.168.0.3 canonical=stuff"); $i_hosts->write_back; ok( 1, "yaml write back done" ); my $backup = path($yaml_file.'.old'); ok ($backup->exists, "backup file was written"); # restore backup to undo the load done 4 lines ago # so the next subtest tests that the backup content is right $backup->move($yaml_file); }; subtest 'another instance to read the yaml that was just written' => sub { my $i2_hosts = $model->instance( instance_name => 'hosts_inst2', root_class_name => 'Hosts', root_dir => $wr_root->stringify, ); ok( $i2_hosts, "Created instance" ); my $i2_root = $i2_hosts->config_root; my $p2_dump = $i2_root->dump_tree; is( $p2_dump, $load, "compare original data with 2nd instance data" ); # since full_dump is null, check that dummy param is not written in yaml files my $yaml = $yaml_file->slurp || die "can't open $yaml_file:$!"; unlike( $yaml, qr/dummy/, "check yaml dump content" ); $yaml_file->remove; }; subtest 'test yaml content for single hash class' => sub { my $i_single_hash = $model->instance( instance_name => 'single_hash', root_class_name => 'SingleHashElement', root_dir => $wr_root->stringify, ); ok( $i_single_hash, "Created single hash instance" ); $load = "record:foo ipaddr=127.0.0.1 canonical=localhost alias=localhost - record:bar ipaddr=192.168.0.1 canonical=bilbo - - "; $i_single_hash->config_root->load($load); $i_single_hash->write_back; ok( 1, "yaml single_hash write back done" ); ok( $yaml_file->exists, "check that config file $yaml_file was written" ); my $yaml = $yaml_file->slurp || die "can't open $yaml_file:$!"; unlike( $yaml, qr/record/, "check single_hash yaml content" ); # test that yaml file is removed when no data is left $i_single_hash->config_root->fetch_element("record")->clear; $i_single_hash->write_back; ok( ! $yaml_file->exists, "check that config file $yaml_file was removed by clearing content" ); }; subtest 'test yaml content for complex class' => sub { my $i_2_elements = $model->instance( instance_name => '2 elements', root_class_name => 'TwoElements', root_dir => $wr_root->stringify, ); ok( $i_2_elements, "Created '2 elements' instance" ); $i_2_elements->config_root->load($load); $i_2_elements->write_back; ok( 1, "yaml 2 elements write back done" ); ok( $yaml_file->exists, "check that config file $yaml_file was written" ); my $yaml = $yaml_file->slurp || die "can't open $yaml_file:$!"; like( $yaml, qr/record/, "check 2 elements yaml content" ); $i_2_elements->config_root->fetch_element("record")->clear; $i_2_elements->write_back; ok( ! $yaml_file->exists, "check that config file $yaml_file was removed by clearing content" ); }; memory_cycle_ok( $model, "check model mem cycles" ); done_testing; Config-Model-Backend-Yaml-2.134/t/lib/0000755000175000017500000000000014002607357015672 5ustar domidomiConfig-Model-Backend-Yaml-2.134/t/lib/test_yaml_model.pl0000644000175000017500000000323314002607357021411 0ustar domidomi# # This file is part of Config-Model-Backend-Yaml # # This software is Copyright (c) 2018 by Dominique Dumont. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # # test model used by t/*.t my @backend_config = ( rw_config => { backend => 'yaml', config_dir => '/yaml/', file => 'hosts.yml', auto_create => 1, full_dump => 0, auto_delete => 1, } ); [ { name => 'Host', element => [ [qw/ipaddr canonical alias/] => { type => 'leaf', value_type => 'uniline', }, dummy => {qw/type leaf value_type uniline default toto/}, ] }, { name => 'Hosts', @backend_config, element => [ record => { type => 'list', cargo => { type => 'node', config_class_name => 'Host', }, }, ] }, { name => 'SingleHashElement', @backend_config, element => [ record => { type => 'hash', index_type => 'string', cargo => { type => 'node', config_class_name => 'Host', }, }, ] }, { name => 'TwoElements', include => 'SingleHashElement', @backend_config, element => [ foo => { type => 'leaf', value_type => 'uniline', } ] } ]; Config-Model-Backend-Yaml-2.134/t/lib/SneakyObject.pm0000644000175000017500000000075014002607357020613 0ustar domidomi# # This file is part of Config-Model-Backend-Yaml # # This software is Copyright (c) 2018 by Dominique Dumont. # # This is free software, licensed under: # # The GNU Lesser General Public License, Version 2.1, February 1999 # package SneakyObject; use strict; use warnings; use Test::More; use 5.10.1; # class used with some fill.copyright.blanks.yml to check that object # cannot be created from YAML files sub DESTROY { fail "SneakyObject was loaded from YAML data\n"; } 1; Config-Model-Backend-Yaml-2.134/t/model_tests.t0000644000175000017500000000023514002607357017633 0ustar domidomi# -*- cperl -*- use warnings; use strict; use Config::Model::Tester 4.001; use lib 't/lib'; use SneakyObject; $::_use_log4perl_to_warn = 1; run_tests(); Config-Model-Backend-Yaml-2.134/build-from-git.md0000644000175000017500000000331614002607357020027 0ustar domidomi# How to build Config::Model::Backend::Yaml from git repository `Config::Model` is build with [Dist::Zilla](http://dzil.org/). This pages details how to install the tools and dependencies required to build this module. ## Install tools and dependencies ### Debian, Ubuntu and derivatives Run $ sudo apt install libdist-zilla-perl libdist-zilla-app-command-authordebs-perl $ dzil authordebs --install $ sudo apt build-dep libconfig-model-perl The [libdist-zilla-app-command-authordebs-perl package](https://tracker.debian.org/pkg/libdist-zilla-app-command-authordebs-perl) is quite recent (uploaded on Dec 2016 in Debian/unstable) and may not be available yet on your favorite distribution. ### Other systems Run $ cpamn Dist::Zilla $ dzil authordeps -missing | cpanm --notest $ cpanm --quiet --notest --skip-satisfied MouseX::NativeTraits $ dzil listdeps --missing | cpanm --notest NB: The author would welcome pull requests that explains how to install these tools and dependencies using native package of other distributions. ## Build Config::Model::Backend::Yaml Run dzil build or dzil test `dzil` may complain about missing `EmailNotify` or `Twitter` plugin. You may ignore this or edit [dist.ini](dist.ini) to comment out the last 2 sections. These are useful only to the author when releasing a new version. `dzil` may also return an error like `Cannot determine local time zone`. In this case, you should specify explicitely your timezone in a `TZ` environement variable. E.g run `dzil` this way: TZ="Europe/Paris" dzil test The list of possible timezones is provided by [DateTime::TimeZone::Catalog](https://metacpan.org/pod/DateTime::TimeZone::Catalog) documentation. Config-Model-Backend-Yaml-2.134/MANIFEST0000644000175000017500000000106314002607357016012 0ustar domidomi# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.017. Build.PL CONTRIBUTING.md Changes LICENSE MANIFEST MANIFEST.SKIP META.json META.yml README.md build-from-git.md lib/Config/Model/Backend/Yaml.pm t/README.md t/backend_yaml.t t/lib/SneakyObject.pm t/lib/test_yaml_model.pl t/model_tests.d/backend-yaml-data-examples/basic t/model_tests.d/backend-yaml-data-examples/utf8_data t/model_tests.d/backend-yaml-data-test-conf.pl t/model_tests.d/backend-yaml-examples/basic t/model_tests.d/backend-yaml-test-conf.pl t/model_tests.t weaver.ini Config-Model-Backend-Yaml-2.134/LICENSE0000644000175000017500000006012514002607357015672 0ustar domidomiThis software is Copyright (c) 2018 by Dominique Dumont. This is free software, licensed under: The GNU Lesser General Public License, Version 2.1, February 1999 The GNU Lesser General Public License (LGPL) Version 2.1, February 1999 (The master copy of this license lives on the GNU website.) Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Config-Model-Backend-Yaml-2.134/META.yml0000644000175000017500000000224614002607357016136 0ustar domidomi--- abstract: 'Read and write config as a YAML data structure' author: - 'Dominique Dumont' build_requires: Config::Model::Tester: '4.001' Config::Model::Tester::Setup: '0' ExtUtils::testlib: '0' Module::Build: '0.34' Path::Tiny: '0' Test::Memory::Cycle: '0' Test::More: '0' lib: '0' utf8: '0' configure_requires: Module::Build: '0.34' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010' license: lgpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Config-Model-Backend-Yaml requires: Carp: '0' Config::Model: '2.131' Config::Model::Backend::Any: '0' Config::Model::Exception: '0' File::Path: '0' Log::Log4perl: '0' YAML::XS: '0.69' base: '0' boolean: '0' parent: '0' perl: v5.12.0 strict: '0' warnings: '0' resources: bugtracker: https://github.com/dod38fr/config-model-backend-yaml/issues homepage: https://github.com/dod38fr/config-model/wiki repository: git://github.com/dod38fr/config-model-backend-yaml.git version: '2.134' x_generated_by_perl: v5.32.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: LGPL-2.1