blib/lib/Config/Model/models/Itself/CommonElement.pl

filter: Statementstmt 100% 29 / 29 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 35 / 35 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Config/Model/models/Itself/Class.pl ↑ Summary blib/lib/Config/Model/models/Itself/Element.pl »
1 1 ▶#
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶# This file is part of Config-Model-Itself
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 #
4 1 # This software is Copyright (c) 2007-2026 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 # Copyright (c) 2007-2011 Dominique Dumont.
11 #
12 # This file is part of Config-Model-Itself.
13 #
14 # Config-Model-Itself is free software; you can redistribute it
15 # and/or modify it under the terms of the GNU Lesser Public License
16 # as published by the Free Software Foundation; either version 2.1
17 # of the License, or (at your option) any later version.
18 #
19 # Config-Model-Itself is distributed in the hope that it will be
20 # useful, but WITHOUT ANY WARRANTY; without even the implied
21 # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 # See the GNU Lesser Public License for more details.
23 #
24 # You should have received a copy of the GNU Lesser Public License
25 # along with Config-Model-Itself; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27  
28 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
29 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 6 my @warp_in_string_like_parameter = (
32 warp => {
33 follow => {
34 'type' => '?type',
35 'vtype' => '?value_type',
36 },
37 'rules' => [{
38 when => '$type eq "leaf" and ($vtype eq "uniline" or $vtype eq "string" or $vtype eq "enum")',
39 apply => { level => 'normal', }
40 }]
41 },
42  
43 );
44  
45 6 my %warn_if_match_payload = (
46 type => 'hash',
47 index_type => 'string',
48 level => 'hidden',
49 cargo => {
50 type => 'node',
51 config_class_name => 'Itself::CommonElement::WarnIfMatch',
52 },
53 @warp_in_string_like_parameter,
54 );
55  
56 6 my @warp_in_leaf_parameter = (
57 warp => {
58 follow => {
59 'type' => '?type',
60 },
61 'rules' => [{
62 when => '$type eq "leaf"',
63 apply => { level => 'normal', }
64 }]
65 },
66  
67 );
68  
69 6 my %warn_if = (
70 type => 'hash',
71 index_type => 'string',
72 level => 'hidden',
73 cargo => {
74 type => 'node',
75 config_class_name => 'Itself::CommonElement::WarnIfMatch',
76 },
77 @warp_in_leaf_parameter,
78 );
79  
80 6 my %assert_payload = (
81 type => 'hash',
82 index_type => 'string',
83 level => 'hidden',
84 cargo => {
85 type => 'node',
86 config_class_name => 'Itself::CommonElement::Assert',
87 },
88 @warp_in_leaf_parameter,
89 );
90  
91 return [
92 [
93 6 name => 'Itself::CommonElement::WarnIfMatch',
94 element => [
95 msg => {
96 type => 'leaf',
97 value_type => 'string',
98 description =>
99 'Warning message to show user. "$_" contains the bad value. Example "value $_ is bad". Leave blank or undef to use generated message',
100 },
101 fix => {
102 type => 'leaf',
103 value_type => 'string',
104 description =>
105 'Perl instructions to fix the value. These instructions may be triggered by user. $_ contains the value to fix. $_ is stored as the new value once the instructions are done. C<$self> contains the value object. Use with care.',
106 },
107 ],
108 ],
109 [
110 name => 'Itself::CommonElement::Assert',
111 include => 'Itself::CommonElement::WarnIfMatch',
112 include_after => 'code',
113 element => [
114 code => {
115 type => 'leaf',
116 value_type => 'string',
117 description =>
118 'Perl instructions to test the value. $_ contains the value to test. C<$self> contains the value object. Use with care.',
119 },
120 ],
121 ],
122 [
123 name => 'Itself::CommonElement::Update',
124 gist => '@{files} files',
125 element => [
126 when_missing => {
127 type => 'leaf',
128 value_type => 'enum',
129 choice => [qw/die warn ignore/],
130 description => 'Action when no data is found in any external file',
131 },
132 files => {
133 type => 'list',
134 cargo => {
135 type => 'node',
136 config_class_name => 'Itself::CommonElement::UpdateFiles',
137 },
138 description => 'List of file specifictions to get external data from.'
139 }
140 ]
141 ],
142 [
143 name => 'Itself::CommonElement::UpdateFiles',
144 gist => "{file}:{subpath}",
145 element => [
146 type => {
147 type => 'leaf',
148 value_type => 'enum',
149 choice => [qw/ini json yaml toml/],
150 description => 'the syntax of the external file',
151 },
152 file => {
153 type => 'leaf',
154 value_type => 'uniline',
155 description => 'file path. Either absolute or relative to the running directory of cme.'
156 },
157 subpath => {
158 type => 'leaf',
159 value_type => 'uniline',
160 description => 'The subpath to get data in the file. For instance, the C<bar> item of this '.
161 'JSON string C<{"for" : { "bar" : "baz" }}> can be retrieved with C<for.bar>. '.
162 'See L<Config::Model::Value/update> amd L<Config::Model::Value::UpdateFromFile> '.
163 'for more details.'
164 }
165 ]
166 ],
167 [
168 name => 'Itself::CommonElement',
169  
170 # warp often depend on this one, so list it first
171 'element' => [
172  
173 'mandatory' => {
174 type => 'leaf',
175 value_type => 'boolean',
176 level => 'hidden',
177 warp => {
178 follow => { type => '?type'},
179 'rules' => [{
180 when => '$type eq "leaf"',
181 apply => {
182 upstream_default => 0,
183 level => 'normal',
184 }
185 }]
186 }
187 },
188  
189 # node element (may be within a hash or list)
190  
191 'config_class_name' => {
192 type => 'leaf',
193 level => 'hidden',
194 value_type => 'reference',
195 refer_to => '! class',
196 warp => {
197 follow => { t => '?type' },
198 rules => [
199 '$t eq "warped_node" ' => {
200  
201 # should be able to warp refer_to ??
202 level => 'normal',
203 },
204 '$t eq "node"' => {
205  
206 # should be able to warp refer_to ??
207 level => 'normal',
208 mandatory => 1,
209 },
210 ]
211 }
212 },
213  
214 # warped_node: warp parameter for warped_node. They must be
215 # warped out when type is not a warped_node
216  
217 # end warp elements for warped_node
218  
219 # leaf element
220  
221 'choice' => {
222 type => 'list',
223 level => 'hidden',
224 description => 'Specify the possible values of an enum. This can also be used in a '
225 .'reference element so the possible enum value will be the combination of the '
226 .'specified choice and the referred to values',
227 warp => {
228 follow => {
229 t => '?type',
230 vt => '?value_type',
231 },
232 'rules' => [
233 ' ($t eq "leaf" and ( $vt eq "enum"
234 or $vt eq "reference")
235 )
236 or $t eq "check_list"' => { level => 'normal', },
237 ]
238 },
239 cargo => { type => 'leaf', value_type => 'uniline' },
240 },
241  
242 'min' => {
243 type => 'leaf',
244 value_type => 'number',
245 level => 'hidden',
246 description => 'minimum value',
247 warp => {
248 follow => {
249 'type' => '?type',
250 'vtype' => '?value_type',
251 },
252 'rules' => [
253 ' $type eq "leaf"
254 and ( $vtype eq "integer"
255 or $vtype eq "number"
256 )
257 '
258 => { level => 'normal', }
259 ]
260 }
261 },
262  
263 'max' => {
264 type => 'leaf',
265 value_type => 'number',
266 level => 'hidden',
267 description => 'maximum value',
268 warp => {
269 follow => {
270 'type' => '?type',
271 'vtype' => '?value_type',
272 },
273 'rules' => [
274 ' $type eq "leaf"
275 and ( $vtype eq "integer"
276 or $vtype eq "number"
277 )
278 '
279 => { level => 'normal', }
280 ]
281 }
282 },
283  
284 'min_index' => {
285 type => 'leaf',
286 value_type => 'integer',
287 level => 'hidden',
288 description => 'minimum number of keys',
289 warp => {
290 follow => { 'type' => '?type', },
291 'rules' => [
292 '$type eq "hash"' =>
293 { level => 'normal', },
294 ]
295 }
296 },
297  
298 'max_index' => {
299 type => 'leaf',
300 value_type => 'integer',
301 level => 'hidden',
302 description => 'maximum number of keys',
303 warp => {
304 follow => { 'type' => '?type', },
305 'rules' => [
306 '$type eq "hash" or $type eq "list"' =>
307 { level => 'normal', },
308 ]
309 }
310 },
311  
312 update => {
313 type => 'node',
314 description => 'Update instructions to get value from an external file when '.
315 ' running "cme update". This require Config::Model >= 2.157.',
316 config_class_name => 'Itself::CommonElement::Update',
317 },
318  
319 'default' => {
320 type => 'leaf',
321 level => 'hidden',
322 value_type => 'string',
323 description => 'Specify default value. This default value is written '
324 .'in the configuration data',
325 warp => {
326 follow => {
327 t => '?type'
328 },
329 rules => [
330 {
331 apply => {
332 level => 'normal'
333 },
334 when => '$t eq "leaf" and &parent->element_name ne "cargo"'
335 }
336 ]
337 },
338 },
339  
340 'upstream_default' => {
341 type => 'leaf',
342 level => 'hidden',
343 value_type => 'string',
344 description =>
345 'Another way to specify a default value. But this default value is considered as "built_in" the application and is not written in the configuration data (unless modified)',
346 warp => {
347 follow => {
348 t => '?type'
349 },
350 rules => [
351 {
352 apply => {
353 level => 'normal'
354 },
355 when => '$t eq "leaf" and &parent->element_name ne "cargo"',
356 }
357 ]
358 },
359 },
360  
361 'convert' => {
362 type => 'leaf',
363 value_type => 'enum',
364 level => 'hidden',
365 description => 'Convert value or index to uppercase (uc) or lowercase (lc).',
366 warp => {
367 follow => { 't' => '?type' },
368 'rules' => [
369 '$t eq "leaf" or $t eq "hash"' => {
370 choice => [qw/uc lc/],
371 level => 'normal',
372 }
373 ]
374 }
375 },
376  
377 'match' => {
378 type => 'leaf',
379 value_type => 'uniline',
380 level => 'hidden',
381 description =>
382 'Perl regular expression to assert the validity of the value. To check the '
383 . q!whole value, use C<^> and C<$>. For instance C<^foo|bar$> allows !
384 . q!C<foo> or C<bar> but not C<foobar>. To be case insentive, !
385 . q!use the C<(?i)> extended pattern. For instance, the regexp !
386 . q!C<^(?i)foo|bar$> also allows the values !
387 . q!C<Foo> and C<Bar>.!,
388 @warp_in_string_like_parameter,
389 },
390  
391 'assert' => {
392 %assert_payload,
393 description =>
394 'Raise an error if the test code snippet does returns false. Note this snippet is '
395 . 'also run on undefined value, which may not be what you want.',
396 },
397  
398 'warn_if' => {
399 %assert_payload,
400 description => 'Warn user if the code snippet returns true',
401 },
402  
403 'warn_unless' => {
404 %assert_payload,
405 description =>
406 'Warn user if the code snippet returns false',
407 },
408  
409 'warn_if_match' => {
410 %warn_if_match_payload,
411 description =>
412 'Warn user if a I<defined> value matches the regular expression. ',
413 },
414  
415 'warn_unless_match' => {
416 %warn_if_match_payload,
417 description =>
418 'Warn user if I<defined> value does not match the regular expression',
419 },
420  
421 'warn' => {
422 type => 'leaf',
423 value_type => 'string',
424 level => 'hidden',
425 description =>
426 'Unconditionally issue a warning with this string when this parameter is used. This should be used mostly with "accept"',
427 warp => {
428 follow => { t => '?type' },
429 'rules' => [ '$t eq "leaf"' => { level => 'normal', }, ]
430 },
431 },
432  
433 'grammar' => {
434 type => 'leaf',
435 value_type => 'string',
436 level => 'hidden',
437 description =>
438 "Feed this grammar to Parse::RecDescent to perform validation",
439 @warp_in_string_like_parameter,
440 },
441  
442 'default_list' => {
443 type => 'check_list',
444 level => 'hidden',
445 refer_to => '- choice',
446 description => 'Specify items checked by default',
447 warp => {
448 follow => { t => '?type', o => '?ordered' },
449 'rules' => [
450 '$t eq "check_list" and not $o ' =>
451 { level => 'normal', },
452 '$t eq "check_list" and $o ' => {
453 level => 'normal',
454 ordered => 1,
455 },
456 ]
457 },
458 },
459  
460 'upstream_default_list' => {
461 type => 'check_list',
462 level => 'hidden',
463 refer_to => '- choice',
464 description =>
465 'Specify items checked by default in the application',
466 warp => {
467 follow => { t => '?type', o => '?ordered' },
468 'rules' => [
469 '$t eq "check_list" and not $o ' =>
470 { level => 'normal', },
471 '$t eq "check_list" and $o ' => {
472 level => 'normal',
473 ordered => 1,
474 },
475 ]
476 },
477 },
478  
479 # hash element
480  
481 # list element
482  
483 ],
484 ],
485 ];
« blib/lib/Config/Model/models/Itself/Class.pl ↑ Summary blib/lib/Config/Model/models/Itself/Element.pl »