| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# This file is part of Config-Model-Approx |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2009-2017 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::Approx ; |
|
11
|
|
|
|
|
|
|
$Config::Model::Backend::Approx::VERSION = '1.010'; |
|
12
|
2
|
|
|
2
|
|
10437
|
use Mouse ; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
14
|
|
|
13
|
2
|
|
|
2
|
|
873
|
use Log::Log4perl qw(get_logger :levels); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
16
|
|
|
14
|
2
|
|
|
2
|
|
224
|
use Carp ; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
171
|
|
|
15
|
2
|
|
|
2
|
|
11
|
use File::Copy ; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
82
|
|
|
16
|
2
|
|
|
2
|
|
10
|
use File::Path ; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
70
|
|
|
17
|
2
|
|
|
2
|
|
35
|
use 5.010 ; |
|
|
2
|
|
|
|
|
6
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
extends 'Config::Model::Backend::Any'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# optional |
|
23
|
|
|
|
|
|
|
sub suffix { |
|
24
|
5
|
|
|
5
|
1
|
47552
|
return '.conf'; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub annotation { |
|
28
|
3
|
|
|
3
|
1
|
48
|
return 1 ; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $logger = Log::Log4perl::get_logger('Backend::Approx'); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub read { |
|
35
|
3
|
|
|
3
|
1
|
1029
|
my $self = shift ; |
|
36
|
3
|
|
|
|
|
20
|
my %args = @_ ; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# args are: |
|
39
|
|
|
|
|
|
|
# root => './my_test', # fake root directory, userd for tests |
|
40
|
|
|
|
|
|
|
# config_dir => /etc/foo', # absolute path |
|
41
|
|
|
|
|
|
|
# file => 'foo.conf', # file name |
|
42
|
|
|
|
|
|
|
# file_path => './my_test/etc/foo/foo.conf' |
|
43
|
|
|
|
|
|
|
# io_handle => $io # IO::File object |
|
44
|
|
|
|
|
|
|
# check => yes|no|skip |
|
45
|
|
|
|
|
|
|
|
|
46
|
3
|
50
|
|
|
|
14
|
die "Cannot read $args{config_dir}$args{file}\n" unless defined $args{io_handle} ; |
|
47
|
|
|
|
|
|
|
|
|
48
|
3
|
50
|
|
|
|
21
|
$logger->info("loading config file $args{file}") if defined $args{file}; |
|
49
|
3
|
|
|
|
|
83
|
my @lines = $args{io_handle}->getlines ; |
|
50
|
3
|
|
|
|
|
141
|
my $global = $self->read_global_comments(\@lines, '#') ; |
|
51
|
3
|
|
|
|
|
226
|
$self->node->annotation($global) ; |
|
52
|
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
81
|
my @data = $self->associates_comments_with_data(\@lines, '#') ; |
|
54
|
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
642
|
foreach my $item (@data) { |
|
56
|
15
|
|
|
|
|
233
|
my ($line,$note) = @$item ; |
|
57
|
|
|
|
|
|
|
|
|
58
|
15
|
|
|
|
|
100
|
my ($k,$v) = split /\s+/,$line,2 ; |
|
59
|
|
|
|
|
|
|
|
|
60
|
15
|
100
|
|
|
|
95
|
my $step = ($k =~ s/^\$//) ? $k |
|
|
|
100
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
: ($v =~ m!://!) ? "distributions:".$k |
|
62
|
|
|
|
|
|
|
: $k ; # old style parameter |
|
63
|
15
|
|
|
|
|
74
|
my $leaf = $self->node->grab(step => $step) ; |
|
64
|
15
|
|
|
|
|
129547
|
$leaf->store($v) ; |
|
65
|
15
|
|
|
|
|
5514
|
$leaf->annotation($note) ; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
81
|
return 1; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub write { |
|
72
|
2
|
|
|
2
|
1
|
2854
|
my $self = shift ; |
|
73
|
2
|
|
|
|
|
10
|
my %args = @_ ; |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
23
|
$logger->info("writing config file $args{file}"); |
|
76
|
2
|
|
|
|
|
18
|
my $node = $args{object} ; |
|
77
|
2
|
|
|
|
|
3
|
my $ioh = $args{io_handle} ; |
|
78
|
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
27
|
$ioh->print("## This file was written by 'cme edit approx'\n"); |
|
80
|
2
|
|
|
|
|
22
|
$ioh->print("## You may modify the content of this file.\n\n"); |
|
81
|
|
|
|
|
|
|
|
|
82
|
2
|
50
|
|
|
|
17
|
$ioh->printf("# %s\n", $node->annotation) if $node->annotation; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Using Config::Model::ObjTreeScanner would be overkill |
|
85
|
2
|
|
|
|
|
23
|
foreach my $elt ($node->get_element_name) { |
|
86
|
26
|
100
|
|
|
|
619
|
next if $elt eq 'distributions'; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# write value |
|
89
|
24
|
|
|
|
|
69
|
my $obj = $node->grab($elt) ; |
|
90
|
24
|
|
|
|
|
6609
|
my $v = $obj->fetch ; |
|
91
|
|
|
|
|
|
|
|
|
92
|
24
|
100
|
|
|
|
4075
|
if (defined $v) { |
|
93
|
4
|
100
|
|
|
|
14
|
$ioh->printf("# %s\n", $obj->annotation) if $obj->annotation; |
|
94
|
4
|
|
|
|
|
77
|
$ioh->printf("\$%-10s %s\n\n",$elt,$v) ; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
10
|
my $h = $node->fetch_element('distributions') ; |
|
99
|
2
|
|
|
|
|
99
|
foreach my $dname ($h->fetch_all_indexes) { |
|
100
|
6
|
|
|
|
|
804
|
my $d = $node->grab("distributions:$dname") ; |
|
101
|
|
|
|
|
|
|
|
|
102
|
6
|
|
|
|
|
1940
|
my $note = $d->annotation; |
|
103
|
6
|
100
|
|
|
|
56
|
$ioh->print("# $note\n") if $note; |
|
104
|
6
|
|
|
|
|
28
|
$ioh->printf("%-10s %s\n",$dname,$d->fetch) ; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
2
|
|
|
|
|
317
|
return 1; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Config::Model::Backend::Approx - Approx configuration file editor |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# This backend is loaded by Config::Model::Node |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This module provides a backend to read and write configuration files for Approx. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 Methods |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 read (object => approx_root, io_handle => ...) |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Read F and load the data in the C |
|
130
|
|
|
|
|
|
|
configuration tree. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 write (object => approx_root, io_handle => ...) |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Write data from the C configuration tree into |
|
135
|
|
|
|
|
|
|
F. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L, L, |