| 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::PerlFile 2.169; | ||||||||||||
| 11 | |||||||||||||
| 12 | 2 | ▶ | use 5.020; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 2 | ▶ | use Config::Model::Exception; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 2 | ▶ | use File::Path; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 2 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | 2 | ▶ | use feature qw/postderef signatures/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 2 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | 2 | ▶ | use base qw/Config::Model::Backend::Any/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | |||||||||||||
| 25 | 2 | my $logger = get_logger("Backend::PerlFile"); | |||||||||||
| 26 | |||||||||||||
| 27 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||
| 28 | 12 | ▶ | sub read ($self, %args) { | ||||||||||
|
Subroutine
read: called CC=4 SCAR=14.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 | 12 | my $file_path = $args{file_path}; | |||||||||||
| 38 | 12 | ▶ | return 0 unless -r $file_path; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 9 | ▶ | $file_path = "./$file_path" unless $file_path =~ m!^\.?/!; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 9 | $logger->info("Read Perl data from $file_path"); | |||||||||||
| 41 | |||||||||||||
| 42 | 9 | ▶ | my $pdata = do $file_path || die "Cannot open $file_path:$?"; | ||||||||||
|
Condition50%1/2
do $file_path || die("Cannot open ${file_path}:$?")
MC/DC0%0/1
do $file_path || die("Cannot open ${file_path}:$?")
do $file_path
Truth table50%1/2
A
A= do $file_path
| |||||||||||||
| 43 | 9 | $self->node->load_data($pdata); | |||||||||||
| 44 | 9 | return 1; | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 5 | ▶ | sub write ($self, %args) { | ||||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 48 | # args is: | ||||||||||||
| 49 | # object => $obj, # Config::Model::Node object | ||||||||||||
| 50 | # root => './my_test', # fake root directory, userd for tests | ||||||||||||
| 51 | # config_dir => /etc/foo', # absolute path | ||||||||||||
| 52 | # file => 'foo.conf', # file name | ||||||||||||
| 53 | # file_path => './my_test/etc/foo/foo.conf' | ||||||||||||
| 54 | # check => yes|no|skip | ||||||||||||
| 55 | |||||||||||||
| 56 | 5 | my $file_path = $args{file_path}; | |||||||||||
| 57 | 5 | $logger->info("Write perl data to $file_path"); | |||||||||||
| 58 | |||||||||||||
| 59 | my $p_data = $self->node->dump_as_data( | ||||||||||||
| 60 | skip_auto_write => 'perl_file', | ||||||||||||
| 61 | check => $args{check} | ||||||||||||
| 62 | 5 | ); | |||||||||||
| 63 | 5 | my $dumper = Data::Dumper->new( [$p_data] ); | |||||||||||
| 64 | 5 | $dumper->Terse(1); | |||||||||||
| 65 | |||||||||||||
| 66 | 5 | $args{file_path}->spew_utf8( $dumper->Dump, ";\n" ); | |||||||||||
| 67 | |||||||||||||
| 68 | 5 | return 1; | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 2 | 1; | |||||||||||
| 72 | |||||||||||||
| 73 | # ABSTRACT: Read and write config as a Perl data structure | ||||||||||||
| 74 | |||||||||||||
| 75 | __END__ | ||||||||||||