| 1 | # | ||||||||||
| 2 | # This file is part of Config-Model | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is Copyright (c) 2005-2022 by Dominique Dumont. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software, licensed under: | ||||||||||
| 7 | # | ||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||
| 9 | # | ||||||||||
| 10 | package Config::Model::Backend::CdsFile 2.169; | ||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use 5.020; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use Config::Model::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use File::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | use feature qw/postderef signatures/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | use base qw/Config::Model::Backend::Any/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 1 | my $logger = get_logger("Backend::CdsFile"); | |||||||||
| 26 | |||||||||||
| 27 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||
| 28 | 2 | ▶ | sub read ($self, %args) { | ||||||||
|
Subroutine
read: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 29 | # args is: | ||||||||||
| 30 | # object => $obj, # Config::Model::Node object | ||||||||||
| 31 | # root => './my_test', # fake root directory, userd for tests | ||||||||||
| 32 | # config_dir => /etc/foo', # absolute path | ||||||||||
| 33 | # file => 'foo.conf', # file name | ||||||||||
| 34 | # file_path => './my_test/etc/foo/foo.conf' | ||||||||||
| 35 | # check => yes|no|skip | ||||||||||
| 36 | |||||||||||
| 37 | 2 | my $file_path = $args{file_path}; | |||||||||
| 38 | 2 | ▶ | return 0 unless $file_path->exists; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 2 | $logger->info("Read cds data from $file_path"); | |||||||||
| 40 | |||||||||||
| 41 | 2 | $self->node->load( step => $file_path->slurp_utf8 ); | |||||||||
| 42 | 2 | return 1; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | sub write ($self, %args) { | ||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | # args is: | ||||||||||
| 47 | # object => $obj, # Config::Model::Node object | ||||||||||
| 48 | # root => './my_test', # fake root directory, userd for tests | ||||||||||
| 49 | # config_dir => /etc/foo', # absolute path | ||||||||||
| 50 | # file => 'foo.conf', # file name | ||||||||||
| 51 | # file_path => './my_test/etc/foo/foo.conf' | ||||||||||
| 52 | # check => yes|no|skip | ||||||||||
| 53 | |||||||||||
| 54 | 1 | my $file_path = $args{file_path}; | |||||||||
| 55 | 1 | $logger->info("Write cds data to $file_path"); | |||||||||
| 56 | |||||||||||
| 57 | 1 | my $dump = $self->node->dump_tree( skip_auto_write => 'cds_file', check => $args{check} ); | |||||||||
| 58 | 1 | $file_path->spew_utf8($dump); | |||||||||
| 59 | 1 | return 1; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | 1; | |||||||||
| 63 | |||||||||||
| 64 | # ABSTRACT: Read and write config as a Cds data structure | ||||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||