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