line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Carp; |
12
|
59
|
|
|
59
|
|
370
|
use strict; |
|
59
|
|
|
|
|
121
|
|
|
59
|
|
|
|
|
3139
|
|
13
|
59
|
|
|
59
|
|
355
|
use warnings; |
|
59
|
|
|
|
|
119
|
|
|
59
|
|
|
|
|
998
|
|
14
|
59
|
|
|
59
|
|
255
|
|
|
59
|
|
|
|
|
117
|
|
|
59
|
|
|
|
|
1370
|
|
15
|
|
|
|
|
|
|
use Config::Model::Exception; |
16
|
59
|
|
|
59
|
|
280
|
use Config::Model::ObjTreeScanner; |
|
59
|
|
|
|
|
126
|
|
|
59
|
|
|
|
|
1167
|
|
17
|
59
|
|
|
59
|
|
285
|
use Text::Wrap; |
|
59
|
|
|
|
|
133
|
|
|
59
|
|
|
|
|
1408
|
|
18
|
59
|
|
|
59
|
|
23972
|
|
|
59
|
|
|
|
|
132298
|
|
|
59
|
|
|
|
|
23057
|
|
19
|
|
|
|
|
|
|
bless {}, shift; |
20
|
|
|
|
|
|
|
} |
21
|
2
|
|
|
2
|
1
|
6
|
|
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %args = @_; |
25
|
2
|
|
|
2
|
1
|
4
|
my $audit = delete $args{audit} || 0; |
26
|
|
|
|
|
|
|
my $node = delete $args{node} |
27
|
2
|
|
|
|
|
7
|
|| croak "dump_tree: missing 'node' parameter"; |
28
|
2
|
|
100
|
|
|
9
|
|
29
|
|
|
|
|
|
|
my $std_cb = sub { |
30
|
2
|
|
33
|
|
|
7
|
my ( $scanner, $data_r, $obj, $element, $index, $value_obj ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# if element is a collection, get the value pointed by $index |
33
|
142
|
|
|
142
|
|
227
|
$value_obj = $obj->fetch_element($element)->fetch_with_id($index) |
34
|
|
|
|
|
|
|
if defined $index; |
35
|
|
|
|
|
|
|
|
36
|
142
|
100
|
|
|
|
238
|
# get value or only customized value |
37
|
|
|
|
|
|
|
my $value = $audit ? $value_obj->fetch_custom : $value_obj->fetch; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$value = '"' . $value . '"' if defined $value and $value =~ /\s/; |
40
|
142
|
100
|
|
|
|
358
|
|
41
|
|
|
|
|
|
|
if ( defined $value ) { |
42
|
142
|
100
|
100
|
|
|
384
|
my $name = defined $index ? " $element:$index" : $element; |
43
|
|
|
|
|
|
|
push @$data_r, $obj->location . " $name = $value"; |
44
|
142
|
100
|
|
|
|
472
|
my $desc = $obj->get_help_as_text($element); |
45
|
41
|
100
|
|
|
|
100
|
if ( defined $desc and $desc ) { |
46
|
41
|
|
|
|
|
149
|
push @$data_r, wrap( "\t", "\t\t", "DESCRIPTION: $desc" ); |
47
|
41
|
|
|
|
|
120
|
} |
48
|
41
|
100
|
66
|
|
|
162
|
my $effect = $value_obj->get_help_as_text($value); |
49
|
2
|
|
|
|
|
10
|
if ( defined $effect and $effect ) { |
50
|
|
|
|
|
|
|
push @$data_r, wrap( "\t", "\t\t", "SELECTED: $effect" ); |
51
|
41
|
|
|
|
|
640
|
} |
52
|
41
|
100
|
66
|
|
|
88
|
push @$data_r, ''; # to get empty line in report |
53
|
2
|
|
|
|
|
7
|
} |
54
|
|
|
|
|
|
|
}; |
55
|
41
|
|
|
|
|
568
|
|
56
|
|
|
|
|
|
|
my @scan_args = ( |
57
|
2
|
|
|
|
|
15
|
fallback => 'all', |
58
|
|
|
|
|
|
|
auto_vivify => 0, |
59
|
2
|
|
|
|
|
7
|
leaf_cb => $std_cb, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my @left = keys %args; |
63
|
|
|
|
|
|
|
croak "Report: unknown parameter:@left" if @left; |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
5
|
# perform the scan |
66
|
2
|
50
|
|
|
|
5
|
my $view_scanner = Config::Model::ObjTreeScanner->new(@scan_args); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my @ret; |
69
|
2
|
|
|
|
|
19
|
$view_scanner->scan_node( \@ret, $node ); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
2
|
return join( "\n", @ret ); |
72
|
2
|
|
|
|
|
8
|
} |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
95
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# ABSTRACT: Reports data from config tree |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=pod |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=encoding UTF-8 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Config::Model::Report - Reports data from config tree |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 VERSION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
version 2.152 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SYNOPSIS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
use Config::Model; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# define configuration tree object |
96
|
|
|
|
|
|
|
my $model = Config::Model->new; |
97
|
|
|
|
|
|
|
$model->create_config_class( |
98
|
|
|
|
|
|
|
name => "Foo", |
99
|
|
|
|
|
|
|
element => [ |
100
|
|
|
|
|
|
|
[qw/foo bar/] => { |
101
|
|
|
|
|
|
|
type => 'leaf', |
102
|
|
|
|
|
|
|
value_type => 'string' |
103
|
|
|
|
|
|
|
}, |
104
|
|
|
|
|
|
|
], |
105
|
|
|
|
|
|
|
description => [ |
106
|
|
|
|
|
|
|
foo => 'some foo explanation', |
107
|
|
|
|
|
|
|
bar => 'some bar explanation', |
108
|
|
|
|
|
|
|
] |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$model->create_config_class( |
112
|
|
|
|
|
|
|
name => "MyClass", |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
element => [ |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
[qw/foo bar/] => { |
117
|
|
|
|
|
|
|
type => 'leaf', |
118
|
|
|
|
|
|
|
value_type => 'string' |
119
|
|
|
|
|
|
|
}, |
120
|
|
|
|
|
|
|
my_enum => { |
121
|
|
|
|
|
|
|
type => 'leaf', |
122
|
|
|
|
|
|
|
value_type => 'enum', |
123
|
|
|
|
|
|
|
choice => [qw/A B C/], |
124
|
|
|
|
|
|
|
help => { |
125
|
|
|
|
|
|
|
A => 'first letter', |
126
|
|
|
|
|
|
|
B => 'second letter', |
127
|
|
|
|
|
|
|
C => 'third letter', |
128
|
|
|
|
|
|
|
}, |
129
|
|
|
|
|
|
|
description => 'some letters', |
130
|
|
|
|
|
|
|
}, |
131
|
|
|
|
|
|
|
hash_of_nodes => { |
132
|
|
|
|
|
|
|
type => 'hash', # hash id |
133
|
|
|
|
|
|
|
index_type => 'string', |
134
|
|
|
|
|
|
|
cargo => { |
135
|
|
|
|
|
|
|
type => 'node', |
136
|
|
|
|
|
|
|
config_class_name => 'Foo' |
137
|
|
|
|
|
|
|
}, |
138
|
|
|
|
|
|
|
}, |
139
|
|
|
|
|
|
|
], |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $inst = $model->instance(root_class_name => 'MyClass' ); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $root = $inst->config_root ; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# put data |
147
|
|
|
|
|
|
|
my $steps = 'foo=FOO my_enum=B hash_of_nodes:fr foo=bonjour - |
148
|
|
|
|
|
|
|
hash_of_nodes:en foo=hello '; |
149
|
|
|
|
|
|
|
$root->load( steps => $steps ); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
print $root->report ; |
152
|
|
|
|
|
|
|
# foo = FOO |
153
|
|
|
|
|
|
|
# |
154
|
|
|
|
|
|
|
# my_enum = B |
155
|
|
|
|
|
|
|
# DESCRIPTION: some letters |
156
|
|
|
|
|
|
|
# SELECTED: second letter |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
# hash_of_nodes:en foo = hello |
159
|
|
|
|
|
|
|
# DESCRIPTION: some foo explanation |
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
# hash_of_nodes:fr foo = bonjour |
162
|
|
|
|
|
|
|
# DESCRIPTION: some foo explanation |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 DESCRIPTION |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This module is used directly by L<Config::Model::Node> to provide |
167
|
|
|
|
|
|
|
a human readable report of the configuration. This report includes |
168
|
|
|
|
|
|
|
the configuration values and (if provided by the model) the description |
169
|
|
|
|
|
|
|
of the configuration item and their effect. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
A C<report> shows C<all> configuration items. An C<audit> |
172
|
|
|
|
|
|
|
shows only configuration items which are different from their default |
173
|
|
|
|
|
|
|
value. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 new |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
No parameter. The constructor should be used only by |
180
|
|
|
|
|
|
|
L<Config::Model::Node>. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 Methods |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 report |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Returns a string containing the configuration values and (if provided |
187
|
|
|
|
|
|
|
by the model) the description of the configuration item and their |
188
|
|
|
|
|
|
|
effect. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Parameters are: |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=over |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item audit |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Set to 1 to report only configuration data different from default |
197
|
|
|
|
|
|
|
values. Default is 0. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item node |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Reference to the L<Config::Model::Node> object that is dumped. All |
202
|
|
|
|
|
|
|
nodes and leaves attached to this node are also dumped. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 AUTHOR |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Dominique Dumont, (ddumont at cpan dot org) |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 SEE ALSO |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L<Config::Model>,L<Config::Model::Node>,L<Config::Model::Walker> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHOR |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Dominique Dumont |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This software is Copyright (c) 2005-2022 by Dominique Dumont. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This is free software, licensed under: |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |