blib/lib/Config/Model.pm

filter: Statementstmt 82.0% 788 / 960 Branchbran 67.2% 293 / 436 Conditioncond 61.6% 132 / 214 MC/DCmcdc 28.8% 36 / 125 Subroutinesub 91.2% 83 / 91 Podpod 23.8% 15 / 63 totaltotal 71.3% 1347 / 1889 CC 358 SCAR 25.9
CC
358
Cov
75%
translate_id_auto_create
56.0
translate_id_default_info
42.0
translate_legacy_backend_info
38.5
CRAP 13.3
« blib/lib/Config/Model/FuseUI.pm ↑ Summary blib/lib/Config/Model/Backend/IniFile.pm »
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 2.169;
11  
12 59 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 59 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 59 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 59 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 59 ▶use MouseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 59 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 59 ▶use Storable ('dclone');
Subroutine BEGIN: called CC=1 SCAR=0.0
22 59 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 59 ▶use Log::Log4perl 1.11 qw(get_logger :levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 59 ▶use Config::Model::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 59 ▶use Hash::Merge 0.12 qw/merge/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 59 ▶use Path::Tiny 0.053;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 59 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 59 ▶use Config::Model::Lister;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 59 with "Config::Model::Role::Constants";
33  
34 59 ▶use parent qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 59 our @EXPORT_OK = qw/cme initialize_log4perl/;
36  
37 59 ▶use feature qw/signatures postderef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 59 ▶no warnings qw/experimental::signatures experimental::postderef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 # used in some tests where we don't want to load
41 # ~/.log4config-model config
42 59 my $force_default_log;
43 1 ▶sub force_usage_of_default_log_config () {
Subroutine force_usage_of_default_log_config: called CC=1 SCAR=0.0
Pod undocumented
44 1 return $force_default_log = 1;
45 }
46  
47 59 my $legacy_logger = get_logger("Model::Legacy") ;
48 59 my $loader_logger = get_logger("Model::Loader") ;
49 59 my $logger = get_logger("Model") ;
50  
51 # used to keep one Config::Model object to simplify programs based on
52 # cme function
53 59 my $model_storage;
54  
55 59 enum LegacyTreatment => qw/die warn note ignore /;
56  
57 59 has skip_include => ( isa => 'Bool', is => 'ro', default => 0 );
58 59 has model_dir => ( isa => 'Str', is => 'ro', default => 'Config/Model/models' );
59 59 has legacy => ( isa => 'LegacyTreatment', is => 'rw', default => 'warn' );
60 has instances => (
61 isa => 'HashRef[Config::Model::Instance]',
62 is => 'ro',
63 78 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
64 59 traits => ['Hash'],
65 handles => {
66 store_instance => 'set',
67 get_instance => 'get',
68 has_instance => 'defined',
69 delete_instance => 'delete',
70 },
71 );
72  
73 # Config::Model stores 3 versions of each model
74  
75 # raw_model is the model exactly as passed by the user. Since the format is quite
76 # liberal (e.g legacy parameters, grouped declaration of elements like '[qw/foo bar/] => {}}',
77 # element description in class or in element declaration)), this raw format is not
78 # usable without normalization (done by normalize_class_parameters)
79  
80 # the key if this hash is a model name
81 has raw_models => (
82 isa => 'HashRef',
83 is => 'ro',
84 78 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
85 59 traits => ['Hash'],
86 handles => {
87 raw_model_exists => 'exists',
88 raw_model_defined => 'defined',
89 raw_model => 'get',
90 get_raw_model => 'get',
91 store_raw_model => 'set',
92 raw_model_names => 'keys',
93 },
94 );
95  
96 # the result of normalization is stored here. Normalized model aggregate user models and
97 # augmented features (the one found in Foo.d directory). inclusion of other class is NOT
98 # yet done. normalized_models are created while loading files (load method) or creating
99 # configuration classes (create_config_class)
100 has normalized_models => (
101 isa => 'HashRef',
102 is => 'ro',
103 78 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
104 59 traits => ['Hash'],
105 handles => {
106 normalized_model_exists => 'exists',
107 normalized_model_defined => 'defined',
108 normalized_model => 'get',
109 store_normalized_model => 'set',
110 normalized_model_names => 'keys',
111 },
112 );
113  
114 # This attribute contain the model that will be used by Config::Model::Node. They
115 # are created on demand when get_model is called. When created the inclusion of
116 # other classes is done according to the class 'include' parameter. Note that get_model
117 # will try to call load if the required normalized_model is not known (lazy loading)
118 has models => (
119 isa => 'HashRef',
120 is => 'ro',
121 78 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
122 59 traits => ['Hash'],
123 handles => {
124 model_exists => 'exists',
125 model_defined => 'defined',
126 _get_model => 'get',
127 _store_model => 'set',
128 },
129 );
130  
131 # model snippet may be loaded when the target class is not available
132 # so they must be stored before being used.
133 has model_snippets => (
134 isa => 'ArrayRef',
135 is => 'ro',
136 78 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
137 59 traits => ['Array'],
138 handles => {
139 add_snippet => 'push',
140 all_snippets => 'elements',
141 },
142 );
143  
144  
145 59 enum 'LOG_LEVELS', [ qw/ERROR WARN INFO DEBUG TRACE/ ];
146  
147 59 has log_level => (
148 isa => 'LOG_LEVELS',
149 is => 'ro',
150 );
151  
152 59 my %log_map = (
153 ERROR => $ERROR,
154 WARN => $WARN,
155 INFO => $INFO,
156 DEBUG => $DEBUG,
157 TRACE => $TRACE
158 );
159  
160 has skip_inheritance => (
161 isa => 'Bool',
162 is => 'ro',
163 default => 0,
164 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
165 0 my $self = shift;
166 0 $self->show_legacy_issue("skip_inheritance is deprecated, use skip_include");
167 0 $self->skip_include = $self->skip_inheritance;
168 59 } );
169  
170 # keep this as a separate sub from BUILD. So user can call it before
171 # creating Config::Model object
172 41 ▶sub initialize_log4perl (@args) {
Subroutine initialize_log4perl: called CC=9 SCAR=22.3
Pod documented
173 41 ▶ if (ref $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0]) 0 41 41
174 # may be called as $self-> initialize_log4perl
175 0 shift @args;
176 }
177  
178 41 my %args = @args;
179  
180 41 my $log4perl_syst_conf_file = path('/etc/log4config-model.conf');
181 # avoid undef warning when homedir is not defined (e.g. with Debian cowbuilder)
182 41 ▶ my $home = File::HomeDir->my_home // '';
Condition50%1/2
"File::HomeDir"->my_home // ""
l!l
410
MC/DC0%0/1
"File::HomeDir"->my_home // ""
"File::HomeDir"->my_home
Truth table50%1/2
A
A= "File::HomeDir"->my_home
Aresult
11
00
183 41 my $log4perl_user_conf_file = path( $home . '/.log4config-model' );
184  
185 41 my $fallback_conf_file = path($INC{"Config/Model.pm"})
186 ->parent->child("Model/log4perl.conf") ;
187  
188  
189 41 ▶ my $log4perl_file =
Branch: 3 branches
BranchTrueFalseTotal
$force_default_log ? : 2 39 41
$log4perl_user_conf_file->is_file ? : 0 39 39
$log4perl_syst_conf_file->is_file ? : 0 39 39
190 $force_default_log ? $fallback_conf_file # for tests
191 : $log4perl_user_conf_file->is_file ? $log4perl_user_conf_file
192 : $log4perl_syst_conf_file->is_file ? $log4perl_syst_conf_file
193 : $fallback_conf_file;
194 my %log4perl_conf =
195 1107 map { split /\s*=\s*/,$_,2; }
196 41 grep { chomp; ! /^\s*#/ } $log4perl_file->lines;
197  
198 41 my $verbose = $args{verbose};
199 41 ▶ if (defined $verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $verbose) 2 39 41
200 2 ▶ my @loggers = ref $verbose ? @$verbose : $verbose;
Branch: 1 branch
BranchTrueFalseTotal
ref $verbose ? : 1 1 2
201 2 foreach my $logger (@loggers) {
202 3 $log4perl_conf{"log4perl.logger.Verbose.$logger"} = "INFO, PlainMsgOnScreen";
203 }
204 }
205  
206 41 Log::Log4perl::init(\%log4perl_conf);
207  
208 41 return \%log4perl_conf; # for tests
209 }
210  
211 78 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.2
Pod documented
212 78 my $self = shift;
213 78 my $args = shift;
214 78 ▶ if (my $level = $self->log_level) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $level = $self->log_level) { } 0 78 78
215 0 Log::Log4perl->easy_init($log_map{$level});
216 }
217 else {
218 78 ▶ initialize_log4perl(verbose => $args->{verbose}) unless Log::Log4perl->initialized();
Branch: 1 branch
BranchTrueFalseTotal
unless "Log::Log4perl"->initialized 39 39 78
219 }
220 78 return;
221 }
222  
223 454 ▶sub show_legacy_issue {
Subroutine show_legacy_issue: called CC=6 SCAR=19.1
Pod undocumented
224 454 my $self = shift;
225 454 my $ref = shift;
226 454 ▶ my $behavior = shift || $self->legacy;
Condition66%2/3
shift() || $self->legacy
l!l&&r!l&&!r
401530
MC/DC0%0/2
shift() || $self->legacy
shift() $self->legacy
Truth table66%2/3
A || B
A= shift()B= $self->legacy
ABresult
1X1
011
000
227  
228 454 ▶ my @msg = ref $ref ? @$ref : $ref;
Branch: 1 branch
BranchTrueFalseTotal
ref $ref ? : 0 454 454
229 454 unshift @msg, "Model ";
230 454 ▶ if ( $behavior eq 'warn' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($behavior eq 'warn') { } 340 114 454
elsif ($behavior eq 'note' or $behavior eq 'info') { } 114 0 114
231 340 $legacy_logger->warn(@msg);
232 ▶ } elsif ( $behavior eq 'note' or $behavior eq 'info') {
Condition33%1/3
$behavior eq "note" or $behavior eq "info"
l!l&&r!l&&!r
11400
MC/DC0%0/2
$behavior eq "note" or $behavior eq "info"
$behavior eq "note" $behavior eq "info"
Truth table33%1/3
A or B
A= $behavior eq "note"B= $behavior eq "info"
ABresult
1X1
011
000
233 114 $legacy_logger->info( @msg);
234 } else {
235 0 die @msg, "\n";
236 }
237 454 return;
238 }
239  
240 153 ▶sub _tweak_instance_args {
Subroutine _tweak_instance_args: called CC=11 SCAR=24.6
241 153 my ($args) = @_ ;
242  
243 153 my $application = $args->{application} ;
244 153 my $cat = '';
245 153 ▶ if (defined $application) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $application) 42 111 153
246 42 my ( $categories, $appli_info, $appli_map ) = Config::Model::Lister::available_models;
247  
248 # root_class_name may override class found (or not) by appli in tests
249 42 ▶ if (not $args->{root_class_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"root_class_name"}) 5 37 42
250 5 ▶ $args->{root_class_name} = $appli_map->{$application} ||
Condition50%1/2
$appli_map->{$application} || die("Unknown application $application. Expected one of " . join(' ', sort(keys %$appli_map)) . "\n")
l!l
50
MC/DC0%0/1
$appli_map->{$application} || die("Unknown application $application. Expected one of " . join(' ', sort(keys %$appli_map)) . "\n")
$appli_map->{$application}
Truth table50%1/2
A
A= $appli_map->{$application}
Aresult
11
00
251 die "Unknown application $application. Expected one of "
252 . join(' ',sort keys %$appli_map)."\n";
253 }
254  
255 42 ▶ $cat = $appli_info->{_category} // ''; # may be empty in tests
Condition50%1/2
$appli_info->{"_category"} // ""
l!l
042
MC/DC0%0/1
$appli_info->{"_category"} // ""
$appli_info->{"_category"}
Truth table50%1/2
A
A= $appli_info->{"_category"}
Aresult
11
00
256 # config_dir may be specified in application file
257 42 ▶ $args->{config_dir} //= $appli_info->{$application}{config_dir};
Condition33%1/3
$args->{"config_dir"} //= $appli_info->{$application}{"config_dir"}
l!l&&r!l&&!r
0042
MC/DC0%0/2
$args->{"config_dir"} //= $appli_info->{$application}{"config_dir"}
$args->{"config_dir"} $appli_info->{$application}{"config_dir"}
Truth table33%1/3
A //= B
A= $args->{"config_dir"}B= $appli_info->{$application}{"config_dir"}
ABresult
1X1
011
000
258 42 ▶ $args->{appli_info} = $appli_info->{$application} // {};
Condition50%1/2
$appli_info->{$application} // {}
l!l
420
MC/DC0%0/1
$appli_info->{$application} // {}
$appli_info->{$application}
Truth table50%1/2
A
A= $appli_info->{$application}
Aresult
11
00
259 }
260  
261 153 my $app_name = $application;
262 153 ▶ if ($cat eq 'application') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cat eq "application") 0 153 153
263 # store dir in name to distinguish different runs of the same
264 # app in different directories.
265 0 $application .= " in " . cwd;
266 }
267 $args->{name}
268 = delete $args->{instance_name} # backward compat with test
269 || delete $args->{name} # preferred parameter
270 153 ▶ || $app_name # fallback in most cases
Condition100%8/8
delete $args->{'instance_name'} || delete $args->{'name'} || $app_name || 'default'
l!l
14310
delete $args->{"instance_name"} or delete $args->{"name"} or $app_name
l!l&&r!l&&!r
138510
delete $args->{"instance_name"} or delete $args->{"name"}
l!l&&r!l&&!r
1271115
MC/DC100%3/3
delete $args->{'instance_name'} || delete $args->{'name'} || $app_name || 'default'
delete $args->{"instance_name"} delete $args->{"name"} $app_name
Truth table100%4/4
A or B or C
A= delete $args->{"instance_name"}B= delete $args->{"name"}C= $app_name
ABCresult
1XX1
01X1
0011
0000
271 || 'default'; # fallback mostly in tests
272 153 return;
273 }
274  
275 5 ▶sub cme (@args) {
Subroutine cme: called CC=6 SCAR=18.2
Pod documented
276 5 ▶ my %args = @args == 1 ? ( application => $args[0]) : @args ;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 3 2 5
277  
278 5 ▶ if (my $force = delete $args{'force-load'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $force = delete $args{"force-load"}) 1 4 5
279 1 ▶ $args{check} = 'no' if $force;
Branch: 1 branch
BranchTrueFalseTotal
if $force 1 0 1
280 }
281  
282 5 my $cat =_tweak_instance_args(\%args);
283  
284 5 ▶ my $m_args = delete $args{model_args} // {} ; # used for tests
Condition50%1/2
delete $args{"model_args"} // {}
l!l
05
MC/DC0%0/1
delete $args{"model_args"} // {}
delete $args{"model_args"}
Truth table50%1/2
A
A= delete $args{"model_args"}
Aresult
11
00
285 # model_storage is used to keep Config::Model object alive
286 5 ▶ $model_storage //= Config::Model->new(%$m_args);
Condition66%2/3
$model_storage //= "Config::Model"->new(%$m_args)
l!l&&r!l&&!r
320
MC/DC0%0/2
$model_storage //= "Config::Model"->new(%$m_args)
$model_storage "Config::Model"->new(%$m_args)
Truth table66%2/3
A //= B
A= $model_storageB= "Config::Model"->new(%$m_args)
ABresult
1X1
011
000
287  
288 5 return $model_storage->instance(%args);
289 }
290  
291 148 ▶sub instance ($self, @args) {
Subroutine instance: called CC=6 SCAR=18.1
Pod documented
292 148 ▶ my %args = @args == 1 ? ( application => $args[0]) : @args ;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 0 148 148
293  
294 # also creates a default name
295 148 _tweak_instance_args(\%args);
296  
297 148 ▶ if ( $args{name} and $self->has_instance($args{name}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"name"} and $self->has_instance($args{"name"})) 4 144 148
Condition66%2/3
$args{"name"} and $self->has_instance($args{"name"})
!ll&&!rl&&r
01444
MC/DC50%1/2
$args{"name"} and $self->has_instance($args{"name"})
$args{"name"} $self->has_instance($args{"name"})
Truth table66%2/3
A and B
A= $args{"name"}B= $self->has_instance($args{"name"})
ABresult
0X0
100
111
298 4 return $self->get_instance($args{name});
299 }
300  
301 croak "Model: can't create instance without application or root_class_name "
302 144 ▶ unless $args{root_class_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"root_class_name"} 0 144 144
303  
304 144 ▶ if ( defined $args{model_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"model_file"}) 17 127 144
305 17 my $file = delete $args{model_file};
306 17 $self->load( $args{root_class_name}, $file );
307 }
308  
309 144 my $i = Config::Model::Instance->new(
310 config_model => $self,
311 %args # for optional parameters like *directory
312 );
313  
314 144 $self->store_instance($args{name}, $i);
315 144 return $i;
316 }
317  
318 0 ▶sub instance_names {
Subroutine instance_names: not called CC=1 SCAR=6.9
Pod undocumented
319 0 my $self = shift;
320 0 my @all = sort keys %{ $self->instances };
321 0 return @all;
322 }
323  
324 # unpacked model is:
325 # {
326 # element_list => [ ... ],
327 # element => { element_name => element_data (left as is) },
328 # class_description => <class description string>,
329 # include => 'class_name',
330 # include_after => 'element_name',
331 # }
332 # description, summary, level, status are moved
333 # into element description.
334  
335 59 my @legal_params_to_move = (
336 qw/read_config write_config rw_config/, # read/write stuff
337  
338 # this parameter is filled by class generated by a program. It may
339 # be used to avoid interactive edition of a generated model
340 'generated_by',
341 qw/class_description author copyright gist license include include_after include_backend class/
342 );
343  
344 59 my @other_legal_params = qw/author element status description summary level accept warp/;
345  
346 # keep as external API. All internal call go through _store_model
347 # See comments around raw_models attribute for explanations
348 117 ▶sub create_config_class ($self, %raw_model) {
Subroutine create_config_class: called CC=3 SCAR=11.4
Pod documented
349 my $config_class_name = delete $raw_model{name}
350 117 ▶ or croak "create_config_class: no config class name";
Branch: 1 branch
BranchTrueFalseTotal
my $config_class_name = delete $raw_model{"name"} or croak("create_config_class: no config class name") 117 0 117
351  
352 117 get_logger("Model")->info("Creating class $config_class_name");
353  
354 117 ▶ if ( $self->model_exists($config_class_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->model_exists($config_class_name)) 0 117 117
355 0 Config::Model::Exception::ModelDeclaration->throw(
356 error => "create_config_class: attempt to clobber $config_class_name"
357 . " config class name " );
358 }
359  
360 117 $self->store_raw_model( $config_class_name, dclone( \%raw_model ) );
361  
362 117 my $model = $self->normalize_class_parameters( $config_class_name, \%raw_model );
363  
364 115 $self->store_normalized_model( $config_class_name, $model );
365  
366 115 return $config_class_name;
367 }
368  
369 266 ▶sub merge_included_class {
Subroutine merge_included_class: called CC=8 SCAR=30.4
Pod undocumented
370 266 my ( $self, $config_class_name ) = @_;
371  
372 266 my $normalized_model = $self->normalized_model($config_class_name);
373 266 my $model = dclone $normalized_model ;
374  
375 # add included elements
376 266 ▶ if ( $self->skip_include and defined $normalized_model->{include} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->skip_include and defined $normalized_model->{'include'}) { } 0 266 266
Condition33%1/3
$self->skip_include and defined $normalized_model->{"include"}
!ll&&!rl&&r
26600
MC/DC0%0/2
$self->skip_include and defined $normalized_model->{"include"}
$self->skip_include defined $normalized_model->{"include"}
Truth table33%1/3
A and B
A= $self->skip_includeB= defined $normalized_model->{"include"}
ABresult
0X0
100
111
377 0 my $inc = $normalized_model->{include};
378 0 ▶ $model->{include} = ref $inc ? $inc : [$inc];
Branch: 1 branch
BranchTrueFalseTotal
ref $inc ? : 0 0 0
379 $model->{include_after} = $normalized_model->{include_after}
380 0 ▶ if defined $normalized_model->{include_after};
Branch: 1 branch
BranchTrueFalseTotal
if defined $normalized_model->{"include_after"} 0 0 0
381 }
382 else {
383 # include class in raw_copy, normalized_model is left as is
384 266 $self->include_class( $config_class_name, $model );
385 }
386  
387 # add included backend
388 265 ▶ if ( $self->skip_include and defined $normalized_model->{include_backend} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->skip_include and defined $normalized_model->{'include_backend'}) { } 0 265 265
Condition33%1/3
$self->skip_include and defined $normalized_model->{"include_backend"}
!ll&&!rl&&r
26500
MC/DC0%0/2
$self->skip_include and defined $normalized_model->{"include_backend"}
$self->skip_include defined $normalized_model->{"include_backend"}
Truth table33%1/3
A and B
A= $self->skip_includeB= defined $normalized_model->{"include_backend"}
ABresult
0X0
100
111
389 0 my $inc = $normalized_model->{include_backend};
390 0 ▶ $model->{include_backend} = ref $inc ? $inc : [$inc];
Branch: 1 branch
BranchTrueFalseTotal
ref $inc ? : 0 0 0
391 }
392 else {
393 # include read/write config specifications in raw_copy,
394 # normalized_model is left as is
395 265 $self->include_backend( $config_class_name, $model );
396 }
397  
398 265 return $model;
399 }
400  
401 265 ▶sub include_backend {
Subroutine include_backend: called CC=9 SCAR=23.6
Pod documented
402 265 my $self = shift;
403 265 ▶ my $class_name = shift || croak "include_backend: undef includer";
Condition50%1/2
shift() || croak('include_backend: undef includer')
l!l
2650
MC/DC0%0/1
shift() || croak('include_backend: undef includer')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
404 265 ▶ my $target_model = shift || die "include_backend:: undefined target_model";
Condition50%1/2
shift() || die('include_backend:: undefined target_model')
l!l
2650
MC/DC0%0/1
shift() || die('include_backend:: undefined target_model')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
405  
406 265 my $included_classes = delete $target_model->{include_backend};
407 265 ▶ return () unless defined $included_classes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $included_classes 264 1 265
408  
409 1 foreach my $included_class (@$included_classes) {
410 # takes care of recursive include, because get_model will perform
411 # includes (and normalization). Is already a dclone
412 1 my $included_model = $self->get_model_clone($included_class);
413  
414 1 foreach my $rw (qw/rw_config read_config write_config config_dir/) {
415 4 ▶ if ($target_model->{$rw} and $included_model->{$rw}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($target_model->{$rw} and $included_model->{$rw}) { } 0 4 4
elsif ($included_model->{$rw}) { } 1 3 4
Condition33%1/3
$target_model->{$rw} and $included_model->{$rw}
!ll&&!rl&&r
400
MC/DC0%0/2
$target_model->{$rw} and $included_model->{$rw}
$target_model->{$rw} $included_model->{$rw}
Truth table33%1/3
A and B
A= $target_model->{$rw}B= $included_model->{$rw}
ABresult
0X0
100
111
416 0 my $msg = "Included $rw from $included_class cannot clobber "
417 . "existing data in $class_name";
418 0 Config::Model::Exception::ModelDeclaration->throw( error => $msg );
419 }
420 elsif ($included_model->{$rw}) {
421 1 $target_model->{$rw} = $included_model->{$rw};
422 }
423 }
424 }
425 1 return;
426 }
427  
428 425 ▶sub copy_element_information ($self, $model, $raw_model, $config_class_name) {
Subroutine copy_element_information: called CC=6 SCAR=18.2
Pod undocumented
429 425 ▶ if (my $elt_info = delete $raw_model->{element}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elt_info = delete $raw_model->{"element"}) 378 47 425
430 # TODO: remove in 2029, translate packed info into hash with aliases
431 # i.e. [ [qw/foo bar/] => {...} ]
432 # to [ foo => {...}, bar => { alias => 'foo' } ]
433 378 my $unpacked_info = $self->translate_packed_element_into_alias($config_class_name, $elt_info, 'name');
434  
435 # translate [ A => <info>, B => <info> ]
436 # in { A => <info>, B => <info> }
437 378 my $hash_info = $self->translate_array_to_hash($unpacked_info);
438  
439 # translate start alias in plain alias
440 # i.e. foo => "*bar"
441 # to foo => { alias => "bar" }
442 378 my $new_info = $self->translate_star_alias($hash_info) ;
443  
444 # TODO: remove in 2030, once all tests and synopsis are cleaned up or translated to YAML
445 378 $self->translate_legacy_info_in_hash($config_class_name, $new_info );
446  
447 378 foreach my $name ( keys $new_info->%* ) {
448 1832 my $info = $new_info->{$name};
449  
450 1832 my $actual_info;
451 1832 ▶ if (ref $info) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info) { } 1832 0 1832
452 # warp can be found only in element item
453 1832 ▶ if (my $alias = $info->{alias}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $alias = $info->{'alias'}) { } 424 1408 1832
454 424 $actual_info = $new_info->{$alias};
455 424 ▶ if (not defined $actual_info) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $actual_info) 0 424 424
456 0 Config::Model::Exception::ModelDeclaration->throw(
457 error => "Element alias '$info' points to unknown element. ".
458 " Aliased element must be declared before alias. Expected one of ".
459 join(' ',sort keys $new_info->%*)
460 );
461 }
462 }
463 else {
464 1408 $actual_info = $info;
465 }
466 }
467 else {
468 0 Config::Model::Exception::ModelDeclaration->throw(
469 error => "Unpexpected element info: $info"
470 );
471 }
472  
473 1832 $model->{element}{$name} = dclone($actual_info);
474 }
475 }
476 425 return;
477 }
478  
479 # translate [qw/A B C/ => <info>]
480 # in [ A => <info>, B => {alias => A }, c => { alias => 'A'} ] (with $star = 0)
481 # in [ A => <info>, B => '*A' }, c => '*A' ] (with $star = 1)
482 425 ▶sub translate_packed_element_into_alias($self, $config_class_name, $elt_info, $info_name, $star = 0) {
Subroutine translate_packed_element_into_alias: called CC=9 SCAR=22.0
Pod undocumented
483 425 ▶ if (ref $elt_info eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elt_info eq "HASH") 0 425 425
484 0 Config::Model::Exception::ModelDeclaration->throw(
485 error => "Element declaration of $config_class_name is not an array ref"
486 );
487 }
488  
489 425 ▶ if (ref ($elt_info->[0]) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elt_info->[0] eq "HASH") 1 424 425
490 # we already have a list of hash like
491 # [ { name => A, ...}, {name => B, alias =>A},...]
492 1 return $elt_info;
493 }
494  
495 424 my @raw_info = $elt_info->@*;
496 424 my @new_info;
497  
498 424 ▶ while (@raw_info) {
Branch: 1 branch
BranchTrueFalseTotal
if (@raw_info) 1499 424 1923
499 1499 my ( $item, $info ) = splice @raw_info, 0, 2;
500  
501 1499 ▶ my @element_names = ref($item) ? @$item : ($item);
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 368 1131 1499
502 1499 my $first = shift @element_names;
503 1499 push @new_info, $first, $info;
504  
505 1499 ▶ if (@element_names > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@element_names > 0) 258 1241 1499
506 258 $self->show_legacy_issue(
507 "$config_class_name: element $info_name '@element_names': ".
508 "should use aliases to $first instead of array ref.", 'warn'
509 );
510 }
511 1499 foreach my $name (@element_names) {
512 408 ▶ push @new_info, $name, $star ? "*$first" : { alias => $first };
Branch: 1 branch
BranchTrueFalseTotal
$star ? : 8 400 408
513 }
514 }
515  
516 424 return \@new_info;
517 }
518  
519 # translate [ A => <info>, B => <info> ]
520 # or [ { name => A, ...}, {name => B, ...}, ...]
521 # in { A => <info>, B => <info> }
522 424 ▶sub translate_array_to_hash($self, $elt_info) {
Subroutine translate_array_to_hash: called CC=3 SCAR=11.2
Pod undocumented
523 424 ▶ if (ref $elt_info eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elt_info eq "HASH") 0 424 424
524 # already in new format
525 0 return $elt_info;
526 }
527  
528 424 ▶ if (ref ($elt_info->[0]) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elt_info->[0] eq "HASH") 1 423 424
529 # we have a list of hash like
530 # [ { name => A, ...}, {name => B },...]
531 1 return { map { delete $_->{name} => $_ ;} $elt_info->@* };
532 }
533  
534 423 return { $elt_info->@* };
535 }
536  
537 426 ▶sub copy_aliased_element_properties ($self, $model, $raw_model, $config_class_name, $properties) {
Subroutine copy_aliased_element_properties: called CC=11 SCAR=25.2
Pod undocumented
538 426 foreach my $prop_name ($properties->@*) {
539 my $raw_prop = $self->translate_legacy_aliased_element_properties(
540 $config_class_name,
541 1276 delete $raw_model->{$prop_name},
542 $prop_name
543 );
544  
545 1276 ▶ next unless defined $raw_prop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw_prop 1231 45 1276
546  
547 45 ▶ Config::Model::Exception::ModelDeclaration->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $raw_prop eq "HASH" 0 45 45
548 error => "Data for parameter $prop_name of $config_class_name"
549 . " is not a hash ref" )
550 unless ref($raw_prop) eq 'HASH';
551  
552  
553 45 ▶ while (my ( $elt_name, $prop ) = each $raw_prop->%*) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$raw_prop) 69 45 114
554 69 my $actual_prop;
555 69 ▶ if (not ref $prop and $prop =~ /^\*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $prop and $prop =~ /^\*(.*)/u) { } 6 63 69
Condition100%3/3
not ref $prop and $prop =~ /^\*(.*)/u
!ll&&!rl&&r
1626
MC/DC100%2/2
not ref $prop and $prop =~ /^\*(.*)/u
not ref $prop $prop =~ /^\*(.*)/u
Truth table100%3/3
not(A) and B
A= not ref $propB= $prop =~ /^\*(.*)/u
ABresult
0X0
100
111
556 6 $actual_prop = $raw_prop->{$1};
557 6 ▶ if (not defined $actual_prop) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $actual_prop) 0 6 6
558 0 my @allowed = grep {! /^\*/ } sort keys $raw_prop->%*;
559 0 Config::Model::Exception::ModelDeclaration->throw(
560 error => "$prop_name alias '$prop' points to unknown $prop_name. ".
561 " Expected one of @allowed"
562 );
563 }
564 }
565 else {
566 63 $actual_prop = $prop;
567 }
568 # move some property information into element declaration (without clobberring)
569 69 ▶ if ($prop_name eq 'warp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop_name eq "warp") 3 66 69
570 3 $self->translate_warp_info( $config_class_name, $elt_name, $actual_prop );
571 }
572 69 ▶ if (not defined $model->{element}{$elt_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $model->{"element"}{$elt_name}) 0 69 69
573 0 Config::Model::Exception::ModelDeclaration->throw(
574 error => "create class $config_class_name: '$prop_name' "
575 . "declaration for non declared element '$elt_name'" );
576 }
577  
578 69 ▶ $model->{element}{$elt_name}{$prop_name} //= $actual_prop;
Condition33%1/3
$model->{"element"}{$elt_name}{$prop_name} //= $actual_prop
l!l&&r!l&&!r
0690
MC/DC0%0/2
$model->{"element"}{$elt_name}{$prop_name} //= $actual_prop
$model->{"element"}{$elt_name}{$prop_name} $actual_prop
Truth table33%1/3
A //= B
A= $model->{"element"}{$elt_name}{$prop_name}B= $actual_prop
ABresult
1X1
011
000
579 }
580 }
581 426 return;
582 }
583  
584 # reversed means declared like prop_name => { prop_value => [qw/eltA eltB/]}
585 426 ▶sub copy_reversed_element_properties ( $self, $model, $raw_model, $config_class_name, $properties) {
Subroutine copy_reversed_element_properties: called CC=9 SCAR=22.2
Pod undocumented
586 426 foreach my $prop_name ($properties->@*) {
587 my $raw_prop =
588 $self->translate_legacy_reversed_element_properties( $config_class_name,
589 851 delete $raw_model->{$prop_name}, $prop_name );
590  
591 851 ▶ next unless defined $raw_prop;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw_prop 823 28 851
592  
593 28 ▶ Config::Model::Exception::ModelDeclaration->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $raw_prop eq "HASH" 0 28 28
594 error => "Data for parameter $prop_name of $config_class_name"
595 . " is not a hash ref" )
596 unless ref($raw_prop) eq 'HASH';
597  
598 28 ▶ while (my ($prop_value, $elts) = each $raw_prop->%*) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$raw_prop) 30 27 57
599 30 ▶ foreach my $elt_name (ref $elts ? $elts->@* : ($elts)) {
Branch: 1 branch
BranchTrueFalseTotal
ref $elts ? : 29 1 30
600 100 ▶ if ( not defined $model->{element}{$elt_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $model->{"element"}{$elt_name}) 1 99 100
601 1 Config::Model::Exception::ModelDeclaration->throw(
602 error => "create class $config_class_name: '$prop_name' "
603 . "declaration for non declared element '$elt_name'" );
604 }
605  
606 99 ▶ $model->{element}{$elt_name}{$prop_name} //= $prop_value;
Condition33%1/3
$model->{"element"}{$elt_name}{$prop_name} //= $prop_value
l!l&&r!l&&!r
0990
MC/DC0%0/2
$model->{"element"}{$elt_name}{$prop_name} //= $prop_value
$model->{"element"}{$elt_name}{$prop_name} $prop_value
Truth table33%1/3
A //= B
A= $model->{"element"}{$elt_name}{$prop_name}B= $prop_value
ABresult
1X1
011
000
607 }
608 }
609 }
610 425 return;
611 }
612  
613 # translate [qw/A B C/ => <info>]
614 # in { A => <info>, B => '*A', c => '*A' }
615 1276 ▶sub translate_legacy_aliased_element_properties($self, $cfg_class_name, $properties, $prop_name) {
Subroutine translate_legacy_aliased_element_properties: called CC=2 SCAR=6.9
Pod undocumented
616 1276 ▶ if (ref $properties ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $properties ne "ARRAY") 1232 44 1276
617 1232 return $properties;
618 }
619  
620 # translate [qw/A B C/ => <info>]
621 # in { A => <info>, B => '*A', c => '*A' }
622 44 my $new = $self->translate_packed_element_into_alias($cfg_class_name, $properties, $prop_name, 1);
623 44 return $self->translate_array_to_hash($new);
624 }
625  
626 # translate for $prop_name: [qw/A B C/ => <prop_value>]
627 # in { <prop_value> => [qw/A B C/]
628 851 ▶sub translate_legacy_reversed_element_properties($self, $cfg_class_name, $properties, $prop_name) {
Subroutine translate_legacy_reversed_element_properties: called CC=6 SCAR=18.0
Pod undocumented
629 851 ▶ if (ref $properties ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $properties ne "ARRAY") 824 27 851
630 824 return $properties;
631 }
632  
633 27 my @raw_info = $properties->@*;
634 27 my %new_info;
635  
636 27 ▶ while (@raw_info) {
Branch: 1 branch
BranchTrueFalseTotal
if (@raw_info) 28 27 55
637 28 my ( $item, $prop_value ) = splice @raw_info, 0, 2;
638  
639 28 ▶ my @element_names = ref($item) ? @$item : ($item);
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 24 4 28
640 28 ▶ $new_info{$prop_value} //=[];
Condition50%1/2
$new_info{$prop_value} //= []
l!l
028
MC/DC0%0/1
$new_info{$prop_value} //= []
$new_info{$prop_value}
Truth table50%1/2
A
A= $new_info{$prop_value}
Aresult
11
00
641 28 push $new_info{$prop_value}->@*, @element_names;
642  
643 28 ▶ if (@element_names > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@element_names > 0) 28 0 28
644 28 $self->show_legacy_issue(
645 "$cfg_class_name: element $prop_name '@element_names': ".
646 "should use reversed declaration (i.e $prop_value => [ @element_names]) ".
647 "instead of array ref.", 'warn'
648 );
649 }
650 }
651  
652 27 return \%new_info;
653 }
654  
655 # must be compatible with formats:
656 # [ name => { info }, name2 => {info} ]
657 # [ [qw/name1 name2/] => { info } ]
658 # [ { name => ..., info }, ... ]
659 429 ▶sub extract_element_list ($self, $raw_model) {
Subroutine extract_element_list: called CC=6 SCAR=17.9
Pod undocumented
660 429 my $list = $raw_model->{element};
661 429 ▶ return () unless defined $list;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $list 48 381 429
662  
663 381 my $i = 0;
664 381 my @element_list;
665 381 ▶ while ($i < $list->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$list) 1440 381 1821
666 1440 my $item = $list->[$i++];
667 1440 ▶ if (ref $item eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item eq 'ARRAY') { } 364 1076 1440
elsif (ref $item eq 'HASH') { } 2 1074 1076
668 364 push @element_list, $item->@*;
669 364 $i++;
670 }
671 elsif (ref $item eq 'HASH') {
672 2 ▶ my $name = $item->{name} // carp "Missing name in element";
Condition33%1/3
$item->{"name"} // carp("Missing name in element")
l!l&&r!l&&!r
200
MC/DC0%0/2
$item->{"name"} // carp("Missing name in element")
$item->{"name"} carp("Missing name in element")
Truth table33%1/3
A // B
A= $item->{"name"}B= carp("Missing name in element")
ABresult
1X1
011
000
673 2 push @element_list, $name;
674 }
675 else {
676 1074 push @element_list, $item;
677 1074 $i++;
678 }
679 }
680  
681 381 return @element_list;
682 }
683  
684 # translate [ pattern => {info}, ... ]
685 # in [ { pattern => '', info}, ...]
686 426 ▶sub translate_legacy_accept_info ($self, $config_class_name, $accept_info) {
Subroutine translate_legacy_accept_info: called CC=9 SCAR=22.0
Pod undocumented
687 426 ▶ return unless defined $accept_info;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $accept_info 378 48 426
688 48 my @new;
689 48 ▶ if (ref $accept_info->[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $accept_info->[0] eq 'HASH') { } 1 47 48
690 # already translated
691 1 @new = $accept_info->@*;
692 }
693 else {
694 47 $self->show_legacy_issue(
695 "$config_class_name class: accept attribute should be a list of hash "
696 ."with 'pattern' key. I.e. something like [ { pattern => 'xyz.*', info}, ...] instead "
697 ."of [ 'xyz.*' => {info}, ... ]",
698 "note"
699 );
700  
701 47 ▶ while (@$accept_info) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$accept_info) 66 47 113
702 66 my $pattern = shift $accept_info->@*;
703 66 my $info = shift $accept_info->@*;
704 66 $info->{name} = $pattern;
705 66 push @new, $info;
706 }
707 }
708  
709 # now check if name is provided
710 48 foreach my $item (@new) {
711 67 ▶ if (not defined $item->{name} and not defined $item->{pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $item->{"name"} or defined $item->{"pattern"}) 1 66 67
Condition66%2/3
defined $item->{"name"} or defined $item->{"pattern"}
l!l&&r!l&&!r
6601
MC/DC50%1/2
defined $item->{"name"} or defined $item->{"pattern"}
defined $item->{"name"} defined $item->{"pattern"}
Truth table66%2/3
A or B
A= defined $item->{"name"}B= defined $item->{"pattern"}
ABresult
1X1
011
000
712 1 $self->show_legacy_issue(
713 "$config_class_name class: accept attribute should feature a name parameter, using pattern instead",
714 "note"
715 );
716 1 $item->{name} = $item->{pattern};
717 }
718 67 ▶ if (defined $item->{name} and not defined $item->{pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $item->{"name"} and not defined $item->{"pattern"}) 66 1 67
Condition66%2/3
defined $item->{"name"} and not defined $item->{"pattern"}
!ll&&!rl&&r
1066
MC/DC50%1/2
defined $item->{"name"} and not defined $item->{"pattern"}
defined $item->{"name"} not defined $item->{"pattern"}
Truth table66%2/3
A and not(B)
A= defined $item->{"name"}B= not defined $item->{"pattern"}
ABresult
0X0
100
111
719 # happens when old representation is dumped by Config::Model::Itself
720 66 $self->show_legacy_issue(
721 "$config_class_name class: accept attribute should feature a pattern parameter, using name instead",
722 "note"
723 );
724 66 $item->{pattern} = $item->{name};
725 }
726 }
727  
728 48 return \@new;
729 }
730  
731 426 ▶sub extract_accept_parameter ($self, $config_class_name, $model, $raw_model) {
Subroutine extract_accept_parameter: called CC=4 SCAR=13.9
Pod undocumented
732 # order of pattern spec is important, so we keep the patterns in a list
733 426 my @accept_list;
734 my %accept_hash;
735 426 ▶ my $accept_info = delete $raw_model->{'accept'} || [];
Condition100%2/2
delete $raw_model->{'accept'} || []
l!l
48378
MC/DC100%1/1
delete $raw_model->{'accept'} || []
delete $raw_model->{'accept'}
Truth table100%2/2
A
A= delete $raw_model->{'accept'}
Aresult
11
00
736  
737 426 foreach my $info ($accept_info->@*) {
738 67 my $name = delete $info->{name};
739 67 my $pattern = $info->{pattern};
740 67 ▶ if (not $pattern) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pattern) 1 66 67
741 1 Config::Model::Exception::ModelDeclaration->throw(
742 error => "create class $config_class_name: Missing pattern attribute for accept spec"
743 );
744 }
745  
746 66 push @accept_list, $name;
747 66 $accept_hash{$name} = $info;
748 }
749  
750 425 $model->{accept} = \%accept_hash;
751 425 $model->{accept_list} = \@accept_list;
752 425 return;
753 }
754  
755 425 ▶sub check_element_duplicates ($self, $config_class_name, $element_list) {
Subroutine check_element_duplicates: called CC=3 SCAR=11.2
Pod undocumented
756 # check for duplicate in @element_list.
757 425 my %check_list;
758 425 foreach my $name ($element_list->@*) {
759 1832 $check_list{$name}++
760 };
761  
762 425 my @extra = grep { $check_list{$_} > 1 } keys %check_list;
763 425 ▶ if (@extra) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extra) 0 425 425
764 0 Config::Model::Exception::ModelDeclaration->throw(
765 error => "class $config_class_name: @extra element "
766 . "is declared more than once. Check the included parts" );
767 }
768 425 return;
769 }
770  
771 426 ▶sub normalize_class_parameters ($self, $config_class_name, $raw_model) {
Subroutine normalize_class_parameters: called CC=6 SCAR=18.7
Pod undocumented
772 426 my $model = {};
773  
774 # sanity check
775 426 my $raw_name = delete $raw_model->{name};
776 426 ▶ if ( defined $raw_name and $config_class_name ne $raw_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $raw_name and $config_class_name ne $raw_name) 0 426 426
Condition66%2/3
defined $raw_name and $config_class_name ne $raw_name
!ll&&!rl&&r
1233030
MC/DC0%0/2
defined $raw_name and $config_class_name ne $raw_name
defined $raw_name $config_class_name ne $raw_name
Truth table66%2/3
A and B
A= defined $raw_nameB= $config_class_name ne $raw_name
ABresult
0X0
100
111
777 0 my $e = "internal: config_class_name $config_class_name ne model name $raw_name";
778 0 Config::Model::Exception::ModelDeclaration->throw( error => $e );
779 }
780  
781 426 my @element_list = $self->extract_element_list($raw_model);
782  
783 426 foreach my $info (@legal_params_to_move) {
784 5538 ▶ next unless defined $raw_model->{$info};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw_model->{$info} 5163 375 5538
785 375 $model->{$info} = delete $raw_model->{$info};
786 }
787  
788 # first deal with perl file and cds_file backend
789 426 $self->translate_legacy_backend_info( $config_class_name, $model );
790  
791 # deal with legacy accept parameter
792 $raw_model->{accept}
793 426 = $self->translate_legacy_accept_info($config_class_name, $raw_model->{accept});
794  
795 # handle accept parameter
796 426 $self->extract_accept_parameter($config_class_name, $model, $raw_model);
797  
798 425 $self->check_element_duplicates($config_class_name, \@element_list);
799  
800 # element is handled first
801 425 $self->copy_element_information($model, $raw_model, $config_class_name);
802  
803 # copy factorized element properties that are declared as class properties
804 425 $self->copy_element_properties($model, $raw_model, $config_class_name);
805  
806 424 ▶ if (keys %$raw_model) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$raw_model) 0 424 424
807 0 my $msg = sprintf(
808 "create class $config_class_name: unexpected property '%s'. Expected '%s'",
809 join( ', ', sort keys %$raw_model ),
810 join( "', '", @legal_params_to_move, @other_legal_params )
811 );
812 0 Config::Model::Exception::ModelDeclaration->throw(error => $msg);
813 }
814  
815 424 $model->{element_list} = \@element_list;
816  
817 424 return $model;
818 }
819  
820 425 ▶sub copy_element_properties($self, $model, $raw_model, $config_class_name) {
Subroutine copy_element_properties: called CC=1 SCAR=0.0
Pod undocumented
821 # 2026-05-14 experiment: also copy warp information. This does not apply to
822 # warp property inside cargo spec.
823 425 $self->copy_aliased_element_properties( $model, $raw_model,
824 $config_class_name, [qw/description summary warp/] );
825 425 $self->copy_reversed_element_properties( $model, $raw_model,
826 $config_class_name, [qw/status level/] );
827 424 return;
828 }
829  
830 # translate aliases in hash of hash with explicit alias attribute
831 # i.e. { foo => "*bar" }
832 # to { foo => { alias => "bar" } }
833 380 ▶sub translate_star_alias ($self, $elt_hash) {
Subroutine translate_star_alias: called CC=3 SCAR=11.0
Pod undocumented
834 380 my %new;
835 380 foreach my $item (keys $elt_hash->%*) {
836 1837 my $raw_info = $elt_hash->{$item};
837  
838 1837 my $info = {};
839 1837 ▶ if (ref $raw_info eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw_info eq 'HASH') { } 1810 27 1837
840 1810 $info = $raw_info;
841 }
842 else {
843 # we have an alias
844 27 $info->{alias} = $raw_info =~ s/^\*//r;;
845 }
846 1837 $new{$item} = $info;
847 }
848  
849 380 return \%new;
850 }
851  
852 # translate info in hash
853 # i.e { foo => {old info} }
854 # to { foo => {new info} }
855 378 ▶sub translate_legacy_info_in_hash ($self, $config_class_name, $elt_hash) {
Subroutine translate_legacy_info_in_hash: called CC=2 SCAR=6.9
Pod undocumented
856 378 foreach my $item (keys $elt_hash->%*) {
857 1832 $self->translate_legacy_info($config_class_name, $item, $elt_hash->{$item} )
858 }
859  
860 378 return;
861 }
862  
863  
864 1832 ▶sub translate_legacy_info ($self, $config_class_name, $elt_name, $info) {
Subroutine translate_legacy_info: called CC=26 SCAR=33.0
Pod undocumented
865 1832 $self->translate_warped_node_info( $config_class_name, $elt_name, $info );
866  
867 #translate legacy warp information
868 1832 ▶ if ( defined $info->{warp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"warp"}) 117 1715 1832
869 117 $self->translate_warp_info( $config_class_name, $elt_name, $info->{warp} );
870 }
871  
872 1832 $self->translate_cargo_info( $config_class_name, $elt_name, $info );
873  
874 1832 ▶ if ( defined $info->{cargo}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"cargo"} and defined $info->{"cargo"}{"type"} and $info->{"cargo"}{"type"} eq "warped_node") 10 1822 1832
Condition83%5/6
defined $info->{"cargo"} and defined $info->{"cargo"}{"type"} and $info->{"cargo"}{"type"} eq "warped_node"
!ll&&!rl&&r
149233010
defined $info->{"cargo"} and defined $info->{"cargo"}{"type"}
!ll&&!rl&&r
14920340
MC/DC66%2/3
defined $info->{"cargo"} and defined $info->{"cargo"}{"type"} and $info->{"cargo"}{"type"} eq "warped_node"
defined $info->{"cargo"} defined $info->{"cargo"}{"type"} $info->{"cargo"}{"type"} eq "warped_node"
Truth table75%3/4
A and B and C
A= defined $info->{"cargo"}B= defined $info->{"cargo"}{"type"}C= $info->{"cargo"}{"type"} eq "warped_node"
ABCresult
0XX0
10X0
1100
1111
875 && defined $info->{cargo}{type}
876 && $info->{cargo}{type} eq 'warped_node' ) {
877 10 $self->translate_warped_node_info( $config_class_name, $elt_name, $info->{cargo} );
878 }
879  
880 1832 ▶ if ( defined $info->{cargo}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"cargo"} and defined $info->{"cargo"}{"warp"}) 11 1821 1832
Condition100%3/3
defined $info->{"cargo"} and defined $info->{"cargo"}{"warp"}
!ll&&!rl&&r
149232911
MC/DC100%2/2
defined $info->{"cargo"} and defined $info->{"cargo"}{"warp"}
defined $info->{"cargo"} defined $info->{"cargo"}{"warp"}
Truth table100%3/3
A and B
A= defined $info->{"cargo"}B= defined $info->{"cargo"}{"warp"}
ABresult
0X0
100
111
881 and defined $info->{cargo}{warp} ) {
882 11 $self->translate_warp_info($config_class_name, $elt_name, $info->{cargo}{warp} );
883 }
884  
885 # compute cannot be warped
886 1832 ▶ if ( defined $info->{compute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"compute"}) 33 1799 1832
887 33 $self->translate_compute_info( $config_class_name, $elt_name, $info, 'compute' );
888 33 $self->translate_allow_compute_override( $config_class_name, $elt_name, $info );
889 }
890 1832 ▶ if ( defined $info->{cargo}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"cargo"} and defined $info->{"cargo"}{"compute"}) 2 1830 1832
Condition100%3/3
defined $info->{"cargo"} and defined $info->{"cargo"}{"compute"}
!ll&&!rl&&r
14923382
MC/DC100%2/2
defined $info->{"cargo"} and defined $info->{"cargo"}{"compute"}
defined $info->{"cargo"} defined $info->{"cargo"}{"compute"}
Truth table100%3/3
A and B
A= defined $info->{"cargo"}B= defined $info->{"cargo"}{"compute"}
ABresult
0X0
100
111
891 and defined $info->{cargo}{compute} ) {
892 2 $self->translate_compute_info( $config_class_name, $elt_name, $info->{cargo}, 'compute' );
893 2 $self->translate_allow_compute_override( $config_class_name, $elt_name, $info->{cargo} );
894 }
895  
896 # refer_to cannot be warped
897 1832 ▶ if ( defined $info->{refer_to} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"refer_to"}) 57 1775 1832
898 57 $self->translate_compute_info( $config_class_name, $elt_name, $info,
899 refer_to => 'computed_refer_to' );
900 }
901 1832 ▶ if ( defined $info->{cargo}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"cargo"} and defined $info->{"cargo"}{"refer_to"}) 0 1832 1832
Condition66%2/3
defined $info->{"cargo"} and defined $info->{"cargo"}{"refer_to"}
!ll&&!rl&&r
14923400
MC/DC0%0/2
defined $info->{"cargo"} and defined $info->{"cargo"}{"refer_to"}
defined $info->{"cargo"} defined $info->{"cargo"}{"refer_to"}
Truth table66%2/3
A and B
A= defined $info->{"cargo"}B= defined $info->{"cargo"}{"refer_to"}
ABresult
0X0
100
111
902 and defined $info->{cargo}{refer_to} ) {
903 $self->translate_compute_info( $config_class_name, $elt_name,
904 0 $info->{cargo}, refer_to => 'computed_refer_to' );
905 }
906  
907 # translate id default param
908 # default cannot be stored in cargo since is applies to the id itself
909 1832 ▶ if ( defined $info->{type}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"type"} and $info->{"type"} eq "list" || $info->{"type"} eq "hash") 340 1492 1832
Condition100%6/6
defined $info->{"type"} and $info->{"type"} eq "list" || $info->{"type"} eq "hash"
!ll&&!rl&&r
4281064340
$info->{"type"} eq "list" or $info->{"type"} eq "hash"
l!l&&r!l&&!r
1731671064
MC/DC100%3/3
defined $info->{"type"} and $info->{"type"} eq "list" || $info->{"type"} eq "hash"
defined $info->{"type"} $info->{"type"} eq "list" $info->{"type"} eq "hash"
Truth table100%4/4
A and B or C
A= defined $info->{"type"}B= $info->{"type"} eq "list"C= $info->{"type"} eq "hash"
ABCresult
0XX0
1000
11X1
1011
910 and ( $info->{type} eq 'list' or $info->{type} eq 'hash' ) ) {
911 340 ▶ if ( defined $info->{default} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"default"}) 0 340 340
912 0 $self->translate_id_default_info( $config_class_name, $elt_name, $info );
913 }
914 340 ▶ if ( defined $info->{auto_create} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"auto_create"}) 0 340 340
915 0 $self->translate_id_auto_create( $config_class_name, $elt_name, $info );
916 }
917 340 $self->translate_id_min_max( $config_class_name, $elt_name, $info );
918 340 ▶ if ( defined $info->{warp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"warp"}) 6 334 340
919 6 foreach my $rule_effect ( map { $_->{apply} } $info->{warp}{rules}->@*) {
920 12 $self->translate_id_min_max( $config_class_name, $elt_name, $rule_effect );
921 12 ▶ next unless defined $rule_effect->{default};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule_effect->{"default"} 12 0 12
922 0 $self->translate_id_default_info( $config_class_name, $elt_name, $rule_effect );
923 }
924 }
925 340 $self->translate_id_class($config_class_name, $elt_name, $info );
926 }
927  
928 1832 ▶ if ( defined $info->{type} and ( $info->{type} eq 'leaf' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"type"} and $info->{"type"} eq "leaf") 790 1042 1832
Condition100%3/3
defined $info->{"type"} and $info->{"type"} eq "leaf"
!ll&&!rl&&r
428614790
MC/DC100%2/2
defined $info->{"type"} and $info->{"type"} eq "leaf"
defined $info->{"type"} $info->{"type"} eq "leaf"
Truth table100%3/3
A and B
A= defined $info->{"type"}B= $info->{"type"} eq "leaf"
ABresult
0X0
100
111
929 790 $self->translate_legacy_builtin( $config_class_name, $info, $info, );
930 }
931  
932 1832 ▶ if ( defined $info->{type} and ( $info->{type} eq 'check_list' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"type"} and $info->{"type"} eq "check_list") 68 1764 1832
Condition100%3/3
defined $info->{"type"} and $info->{"type"} eq "check_list"
!ll&&!rl&&r
428133668
MC/DC100%2/2
defined $info->{"type"} and $info->{"type"} eq "check_list"
defined $info->{"type"} $info->{"type"} eq "check_list"
Truth table100%3/3
A and B
A= defined $info->{"type"}B= $info->{"type"} eq "check_list"
ABresult
0X0
100
111
933 68 $self->translate_legacy_built_in_list( $config_class_name, $info, $info, );
934 }
935  
936 $legacy_logger->debug(
937 1832 ▶ Data::Dumper->Dump( [$info], [ 'translated_' . $elt_name ] )
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 1832 1832
938 ) if $legacy_logger->is_debug;
939 1832 return;
940 }
941  
942 426 ▶sub translate_legacy_backend_info {
Subroutine translate_legacy_backend_info: called CC=14 SCAR=36.5
Pod undocumented
943 426 my ( $self, $config_class_name, $model ) = @_;
944  
945 # trap multi backend and change array spec into single spec
946 426 foreach my $config (qw/read_config write_config/) {
947 852 my $ref = $model->{$config};
948 852 ▶ if ($ref and ref($ref) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and ref $ref eq "ARRAY") 0 852 852
Condition33%1/3
$ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
85200
MC/DC0%0/2
$ref and ref $ref eq "ARRAY"
$ref ref $ref eq "ARRAY"
Truth table33%1/3
A and B
A= $refB= ref $ref eq "ARRAY"
ABresult
0X0
100
111
949 0 ▶ if (@$ref == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$ref == 1) { } 0 0 0
elsif (@$ref > 1) { } 0 0 0
950 0 $model->{$config} = $ref->[0];
951 }
952 elsif (@$ref > 1){
953 0 $self->show_legacy_issue("$config_class_name $config: multiple backends are obsolete. You now must use only one backend.", 'die');
954 }
955 }
956 }
957  
958 # move read_config spec in re_config
959 426 ▶ if ($model->{read_config}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($model->{"read_config"}) 0 426 426
960 0 $self->show_legacy_issue("$config_class_name: read_config specification is deprecated, please move in rw_config", 'warn');
961 0 $model->{rw_config} = delete $model->{read_config};
962 }
963  
964 # merge write_config spec in rw_config
965 426 ▶ if ($model->{write_config}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($model->{"write_config"}) 0 426 426
966 0 $self->show_legacy_issue("$config_class_name: write_config specification is deprecated, please merge with read_config and move in rw_config", 'warn');
967 0 foreach (keys %{$model->{write_config}}) {
968 0 $model->{rw_config}{$_} = $model->{write_config}{$_}
969 }
970 0 delete $model->{write_config};
971 }
972  
973 426 ▶ my $ref = $model->{'rw_config'} || return;
Condition100%2/2
$model->{'rw_config'} || (return)
l!l
123303
MC/DC100%1/1
$model->{'rw_config'} || (return)
$model->{'rw_config'}
Truth table100%2/2
A
A= $model->{'rw_config'}
Aresult
11
00
974  
975 123 ▶ die "undefined backend in rw_config spec of class $config_class_name\n" unless $ref->{backend} ;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->{"backend"} 0 123 123
976  
977 123 ▶ if ($ref->{backend} eq 'custom') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"backend"} eq "custom") 0 123 123
978 0 my $msg = "$config_class_name: custom read/write backend is obsolete."
979 ." Please replace with a backend inheriting Config::Model::Backend::Any";
980 0 $self->show_legacy_issue( $msg, 'die');
981 }
982  
983 123 ▶ if ( $ref->{backend} =~ /^(perl|ini|cds)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"backend"} =~ /^(perl|ini|cds)$/u) 1 122 123
984 1 my $backend = $ref->{backend};
985 1 $self->show_legacy_issue("$config_class_name: deprecated backend '$backend'. Should be '$ {backend}_file'", 'warn');
986 1 $ref->{backend} .= "_file";
987 }
988  
989 123 ▶ if ( defined $ref->{allow_empty} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"allow_empty"}) 0 123 123
990 0 $self->show_legacy_issue("$config_class_name: backend $ref->{backend}: allow_empty is deprecated. Use auto_create", 'warn');
991 0 $ref->{auto_create} = delete $ref->{allow_empty};
992 }
993 123 return;
994 }
995  
996 1832 ▶sub translate_cargo_info {
Subroutine translate_cargo_info: called CC=5 SCAR=27.2
Pod undocumented
997 1832 my $self = shift;
998 1832 my $config_class_name = shift;
999 1832 my $elt_name = shift;
1000 1832 my $info = shift;
1001  
1002 1832 my $c_type = delete $info->{cargo_type};
1003 1832 ▶ return unless defined $c_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c_type 1832 0 1832
1004 0 $self->show_legacy_issue("$config_class_name->$elt_name: parameter cargo_type is deprecated.");
1005 0 my %cargo;
1006  
1007 0 ▶ if ( defined $info->{cargo_args} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"cargo_args"}) 0 0 0
1008 0 %cargo = %{ delete $info->{cargo_args} };
1009 0 $self->show_legacy_issue(
1010 "$config_class_name->$elt_name: parameter cargo_args is deprecated.");
1011 }
1012  
1013 0 $cargo{type} = $c_type;
1014  
1015 0 ▶ if ( defined $info->{config_class_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"config_class_name"}) 0 0 0
1016 0 $cargo{config_class_name} = delete $info->{config_class_name};
1017 0 $self->show_legacy_issue([
1018 "$config_class_name->$elt_name: parameter config_class_name is ",
1019 "deprecated. This one must be specified within cargo. ",
1020 "Ie. cargo=>{config_class_name => 'FooBar'}"
1021 ]);
1022 }
1023  
1024 0 $info->{cargo} = \%cargo;
1025 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1026 Data::Dumper->Dump( [$info], [ 'translated_' . $elt_name ] )
1027 ) if $legacy_logger->is_debug;
1028 0 return;
1029 }
1030  
1031 35 ▶sub translate_allow_compute_override {
Subroutine translate_allow_compute_override: called CC=2 SCAR=7.5
Pod undocumented
1032 35 my $self = shift;
1033 35 my $config_class_name = shift;
1034 35 my $elt_name = shift;
1035 35 my $info = shift;
1036  
1037 35 ▶ if ( defined $info->{allow_compute_override} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{"allow_compute_override"}) 0 35 35
1038 0 $self->show_legacy_issue(
1039 "$config_class_name->$elt_name: parameter allow_compute_override is deprecated in favor of compute -> allow_override"
1040 );
1041 0 $info->{compute}{allow_override} = delete $info->{allow_compute_override};
1042 }
1043 35 return;
1044 }
1045  
1046 92 ▶sub translate_compute_info {
Subroutine translate_compute_info: called CC=9 SCAR=35.3
Pod undocumented
1047 92 my $self = shift;
1048 92 my $config_class_name = shift;
1049 92 my $elt_name = shift;
1050 92 my $info = shift;
1051 92 my $old_name = shift;
1052 92 ▶ my $new_name = shift || $old_name;
Condition66%2/3
shift() || $old_name
l!l&&r!l&&!r
57350
MC/DC0%0/2
shift() || $old_name
shift() $old_name
Truth table66%2/3
A || B
A= shift()B= $old_name
ABresult
1X1
011
000
1053  
1054 92 ▶ if ( ref( $info->{$old_name} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info->{$old_name} eq "ARRAY") 0 92 92
1055 0 my $compute_info = delete $info->{$old_name};
1056 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1057 "translate_compute_info $elt_name input:\n",
1058 Data::Dumper->Dump( [$compute_info], [qw/compute_info/] )
1059 ) if $legacy_logger->is_debug;
1060  
1061 0 $self->show_legacy_issue([ "$config_class_name->$elt_name: specifying compute info with ",
1062 "an array ref is deprecated" ]);
1063  
1064 0 my ( $user_formula, %var ) = @$compute_info;
1065 0 my $replace_h;
1066 0 ▶ foreach ( keys %var ) { $replace_h = delete $var{$_} if ref( $var{$_} ) };
Branch: 1 branch
BranchTrueFalseTotal
if ref $var{$_} 0 0 0
1067  
1068 # cleanup user formula
1069 0 $user_formula =~ s/\$(\w+)\{/\$replace{/g;
1070  
1071 # cleanup variable
1072 0 foreach ( values %var ) { s/\$(\w+)\{/\$replace{/g };
1073  
1074 # change the hash *in* the info structure
1075 0 $info->{$new_name} = {
1076 formula => $user_formula,
1077 variables => \%var,
1078 };
1079 0 ▶ $info->{$new_name}{replace} = $replace_h if defined $replace_h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $replace_h 0 0 0
1080  
1081 $legacy_logger->debug(
1082 "translate_warp_info $elt_name output:\n",
1083 0 ▶ Data::Dumper->Dump( [ $info->{$new_name} ], [ 'new_' . $new_name ] )
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1084 ) if $legacy_logger->is_debug;
1085 }
1086 92 return;
1087 }
1088  
1089 340 ▶sub translate_id_class {
Subroutine translate_id_class: called CC=5 SCAR=17.4
Pod undocumented
1090 340 my $self = shift;
1091 340 ▶ my $config_class_name = shift || die;
Condition50%1/2
shift() || die()
l!l
3400
MC/DC0%0/1
shift() || die()
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1092 340 my $elt_name = shift;
1093 340 my $info = shift;
1094  
1095  
1096 340 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 340 340
1097 "translate_id_class $elt_name input:\n",
1098 Data::Dumper->Dump( [$info], [qw/info/] )
1099 ) if $legacy_logger->is_debug;
1100  
1101 340 my $class_overide_param = $info->{type}.'_class';
1102 340 my $class_overide = $info->{$class_overide_param};
1103 340 ▶ if ($class_overide) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class_overide) 0 340 340
1104 0 $info->{class} = $class_overide;
1105 0 $self->show_legacy_issue([
1106 "$config_class_name->$elt_name: '$class_overide_param' is deprecated, ",
1107 "Use 'class' instead."
1108 ]);
1109 }
1110  
1111 $legacy_logger->debug(
1112 340 ▶ "translate_id_class $elt_name output:",
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 340 340
1113 Data::Dumper->Dump( [$info], [qw/new_info/])
1114 ) if $legacy_logger->is_debug;
1115 340 return;
1116 }
1117  
1118 # internal: translate default information for id element
1119 0 ▶sub translate_id_default_info {
Subroutine translate_id_default_info: not called CC=6 SCAR=37.4
Pod undocumented
1120 0 my $self = shift;
1121 0 ▶ my $config_class_name = shift || die;
Condition0%0/2
shift() || die()
l!l
00
MC/DC0%0/1
shift() || die()
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1122 0 my $elt_name = shift;
1123 0 my $info = shift;
1124  
1125 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1126 "translate_id_default_info $elt_name input:\n",
1127 Data::Dumper->Dump( [$info], [qw/info/] )
1128 ) if $legacy_logger->is_debug;
1129  
1130 0 my $warn = "$config_class_name->$elt_name: 'default' parameter for list or "
1131 . "hash element is deprecated. ";
1132  
1133 0 my $def_info = delete $info->{default};
1134 0 ▶ if ( ref($def_info) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $def_info eq 'HASH') { } 0 0 0
elsif (ref $def_info eq 'ARRAY') { } 0 0 0
1135 0 $self->show_legacy_issue([ "$config_class_name->$elt_name: 'default' parameter for HASH is obsolete" ], "die");
1136 }
1137 elsif ( ref($def_info) eq 'ARRAY' ) {
1138 0 $info->{default_keys} = $def_info;
1139 0 $self->show_legacy_issue([ $warn, "Use default_keys" ]);
1140 }
1141 else {
1142 0 $info->{default_keys} = [$def_info];
1143 0 $self->show_legacy_issue([ $warn, "Use default_keys" ]);
1144 }
1145  
1146 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1147 "translate_id_default_info $elt_name output:",
1148 Data::Dumper->Dump( [$info], [qw/new_info/])
1149 ) if $legacy_logger->is_debug;
1150 0 return;
1151 }
1152  
1153 # internal: translate auto_create information for id element
1154 0 ▶sub translate_id_auto_create {
Subroutine translate_id_auto_create: not called CC=7 SCAR=40.3
Pod undocumented
1155 0 my $self = shift;
1156 0 ▶ my $config_class_name = shift || die;
Condition0%0/2
shift() || die()
l!l
00
MC/DC0%0/1
shift() || die()
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1157 0 my $elt_name = shift;
1158 0 my $info = shift;
1159  
1160 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1161 "translate_id_auto_create $elt_name input:",
1162 Data::Dumper->Dump( [$info], [qw/info/] )
1163 ) if $legacy_logger->is_debug;
1164  
1165 0 my $warn = "$config_class_name->$elt_name: 'auto_create' parameter for list or "
1166 . "hash element is deprecated. ";
1167  
1168 0 my $ac_info = delete $info->{auto_create};
1169 0 ▶ if ( $info->{type} eq 'hash' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($info->{'type'} eq 'hash') { } 0 0 0
elsif ($info->{'type'} eq 'list') { } 0 0 0
1170 $info->{auto_create_keys} =
1171 0 ▶ ref($ac_info) eq 'ARRAY' ? $ac_info : [$ac_info];
Branch: 1 branch
BranchTrueFalseTotal
ref $ac_info eq 'ARRAY' ? : 0 0 0
1172 0 $self->show_legacy_issue([ $warn, "Use auto_create_keys" ]);
1173 }
1174 elsif ( $info->{type} eq 'list' ) {
1175 0 $info->{auto_create_ids} = $ac_info;
1176 0 $self->show_legacy_issue([ $warn, "Use auto_create_ids" ]);
1177 }
1178 else {
1179 0 die "Unexpected element ($elt_name) type $info->{type} ", "for translate_id_auto_create";
1180 }
1181  
1182 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1183 "translate_id_default_info $elt_name output:\n",
1184 Data::Dumper->Dump( [$info], [qw/new_info/] )
1185 ) if $legacy_logger->is_debug;
1186 0 return;
1187 }
1188  
1189 352 ▶sub translate_id_min_max {
Subroutine translate_id_min_max: called CC=4 SCAR=13.9
Pod undocumented
1190 352 my $self = shift;
1191 352 ▶ my $config_class_name = shift || die;
Condition50%1/2
shift() || die()
l!l
3520
MC/DC0%0/1
shift() || die()
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1192 352 my $elt_name = shift;
1193 352 my $info = shift;
1194  
1195 352 foreach my $bad (qw/min max/) {
1196 704 ▶ next unless defined $info->{$bad};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->{$bad} 694 10 704
1197  
1198 10 my $good = $bad . '_index';
1199 10 my $warn = "$config_class_name->$elt_name: '$bad' parameter for list or "
1200 . "hash element is deprecated. Use '$good'";
1201  
1202 10 $self->show_legacy_issue( $warn);
1203 10 $info->{$good} = delete $info->{$bad};
1204 }
1205 352 return;
1206 }
1207  
1208 1842 ▶sub translate_warped_node_info {
Subroutine translate_warped_node_info: called CC=7 SCAR=26.4
Pod undocumented
1209 1842 my ( $self, $config_class_name, $elt_name, $info ) = @_;
1210  
1211 1842 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 1842 1842
1212 "translate_warped_node_info $elt_name input:\n",
1213 Data::Dumper->Dump( [$info], [qw/info/] )
1214 ) if $legacy_logger->is_debug;
1215  
1216 # type may not be defined when translating class snippet used to augment a class
1217 1842 my $elt_type = $info->{type} ;
1218 1842 foreach my $parm (qw/follow rules/) {
1219 3684 ▶ next unless $info->{$parm};
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{$parm} 3684 0 3684
1220 0 ▶ next if defined $elt_type and $elt_type ne 'warped_node';
Branch: 1 branch
BranchTrueFalseTotal
if defined $elt_type and $elt_type ne "warped_node" 0 0 0
Condition0%0/3
defined $elt_type and $elt_type ne "warped_node"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $elt_type and $elt_type ne "warped_node"
defined $elt_type $elt_type ne "warped_node"
Truth table0%0/3
A and B
A= defined $elt_typeB= $elt_type ne "warped_node"
ABresult
0X0
100
111
1221 0 $self->show_legacy_issue(
1222 "$config_class_name->$elt_name: using $parm parameter in "
1223 ."warped node is deprecated. $parm must be specified in a warp parameter."
1224 );
1225 0 $info->{warp}{$parm} = delete $info->{$parm};
1226 }
1227  
1228 $legacy_logger->debug(
1229 1842 ▶ "translate_warped_node_info $elt_name output:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 1842 1842
1230 Data::Dumper->Dump( [$info], [qw/new_info/] )
1231 ) if $legacy_logger->is_debug;
1232 1842 return;
1233 }
1234  
1235 # internal: translate warp information into 'boolean expr' => { ... }
1236 131 ▶sub translate_warp_info {
Subroutine translate_warp_info: called CC=4 SCAR=14.0
Pod undocumented
1237 131 my ( $self, $config_class_name, $elt_name, $warp_info ) = @_;
1238  
1239 131 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 131 131
1240 "translate_warp_info $elt_name input:\n",
1241 Data::Dumper->Dump( [$warp_info], [qw/warp_info/] )
1242 ) if $legacy_logger->is_debug;
1243  
1244 131 my $follow = $self->translate_follow_arg( $config_class_name, $elt_name, $warp_info->{follow} );
1245  
1246 # now, follow is only { w1 => 'warp1', w2 => 'warp2'}
1247 131 my @warper_items = values %$follow;
1248  
1249 my $rules =
1250 $self->translate_rules_arg( $config_class_name, $elt_name, \@warper_items,
1251 131 $warp_info->{rules} );
1252  
1253 131 ▶ $warp_info->{follow} = $follow if keys $follow->%*;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$follow 127 4 131
1254 131 $warp_info->{rules} = $rules;
1255  
1256 131 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 131 131
1257 "translate_warp_info $elt_name output:\n",
1258 Data::Dumper->Dump( [$warp_info], [qw/new_warp_info/] )
1259 ) if $legacy_logger->is_debug;
1260 131 return;
1261 }
1262  
1263 131 ▶sub translate_follow_arg {
Subroutine translate_follow_arg: called CC=5 SCAR=16.1
Pod undocumented
1264 131 my $self = shift;
1265 131 my $config_class_name = shift;
1266 131 my $elt_name = shift;
1267 131 my $raw_follow = shift;
1268  
1269 131 ▶ if ( ref($raw_follow) eq 'HASH' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $raw_follow eq 'HASH') { } 27 104 131
elsif (ref $raw_follow eq 'ARRAY') { } 2 102 104
elsif (defined $raw_follow) { } 98 4 102
1270  
1271 # follow is { w1 => 'warp1', w2 => 'warp2'}
1272 27 return $raw_follow;
1273 }
1274 elsif ( ref($raw_follow) eq 'ARRAY' ) {
1275 # TODO: remove in 2028
1276 2 $self->show_legacy_issue("$config_class_name $elt_name: using follow with array is deprecated. "
1277 . "Please use hash with named parameters.");
1278  
1279 # translate legacy follow arguments ['warp1','warp2',...]
1280 2 my $follow = {};
1281 2 my $idx = 0;
1282 2 foreach ( @$raw_follow ) { $follow->{ 'f' . $idx++ } = $_ } ;
1283 2 return $follow;
1284 }
1285 elsif ( defined $raw_follow ) {
1286  
1287 # follow is a plain string
1288 98 return { f1 => $raw_follow };
1289 }
1290 else {
1291 4 return {};
1292 }
1293 }
1294  
1295 131 ▶sub translate_rules_arg {
Subroutine translate_rules_arg: called CC=16 SCAR=28.2
Pod undocumented
1296 131 my ( $self, $config_class_name, $elt_name, $warper_items, $raw_rules ) = @_;
1297  
1298 131 my $follow = @$warper_items;
1299  
1300 # $rules is translated to:
1301 # [ { if => <boolean expr>, ...} , ... ]
1302 # legacy:
1303 # [ 'boolean expr' => { ... } ]
1304 # { follow_value => { ... } }
1305 # foo => {...} , bar => {...}
1306 # older legacy:
1307 # [ f1, b1 ] => {..} ,[ f1,b2 ] => {...}, [f2,b1] => {...} ...
1308 131 my @rules;
1309 131 ▶ if ( ref($raw_rules) eq 'HASH' ) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $raw_rules eq 'HASH') { } 35 96 131
elsif (ref $raw_rules eq 'ARRAY' and ref $raw_rules->[0] eq 'HASH') { } 10 86 96
elsif (ref $raw_rules eq 'ARRAY') { } 86 0 86
elsif (defined $raw_rules) { } 0 0 0
1310 # TODO: remove in 2028
1311 # transform the hash { foo => { ...} }
1312 # into array ref [ { if => '$f1 eq foo', ... } ]
1313 35 foreach my $key (keys $raw_rules->%*) {
1314 my %h = (
1315 when => $follow ? "\$f1 eq '$key'" : $key,
1316 46 ▶ apply => $raw_rules->{$key},
Branch: 1 branch
BranchTrueFalseTotal
$follow ? : 46 0 46
1317 );
1318 46 push @rules, \%h;
1319 }
1320 $self->show_legacy_issue(
1321 35 "$config_class_name $elt_name: using a hash for warp rule is deprecated. ".
1322 qq!Please use a array ref [ when => "$rules[0]{when}", apply => ...].!
1323 );
1324 }
1325 ▶ elsif ( ref($raw_rules) eq 'ARRAY' and ref $raw_rules->[0] eq 'HASH') {
Condition66%2/3
ref $raw_rules eq "ARRAY" and ref $raw_rules->[0] eq "HASH"
!ll&&!rl&&r
08610
MC/DC50%1/2
ref $raw_rules eq "ARRAY" and ref $raw_rules->[0] eq "HASH"
ref $raw_rules eq "ARRAY" ref $raw_rules->[0] eq "HASH"
Truth table66%2/3
A and B
A= ref $raw_rules eq "ARRAY"B= ref $raw_rules->[0] eq "HASH"
ABresult
0X0
100
111
1326 # no translation needed
1327 10 @rules = $raw_rules->@*;
1328 }
1329 elsif ( ref($raw_rules) eq 'ARRAY') {
1330 # now translate [ f1a, f1b] => { ... }
1331 # into { when => "$f1 eq f1a or $f1 eq f1b ", ... }
1332 86 my @raw_rules = @{$raw_rules};
1333 86 ▶ for ( my $r_idx = 0 ; $r_idx < $#raw_rules ; $r_idx += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r_idx < $#raw_rules) 177 86 263
1334 177 my $key_set = $raw_rules[$r_idx];
1335 # TODO: remove $key_set as array ref in 2028
1336 177 ▶ my @keys = ref($key_set) ? @$key_set : ($key_set);
Branch: 1 branch
BranchTrueFalseTotal
ref $key_set ? : 6 171 177
1337 177 my @bool_expr;
1338 177 foreach my $key (@keys) {
1339 183 my $expr = sprintf(q!$f1 eq '%s'!, $key);
1340 183 ▶ push @bool_expr, ($follow and $key !~ /\$/) ? $expr : $key;
Branch: 1 branch
BranchTrueFalseTotal
$follow && !($key =~ /\$/u) ? : 139 44 183
Condition100%3/3
$follow and not $key =~ /\$/u
!ll&&!rl&&r
539139
MC/DC100%2/2
$follow and not $key =~ /\$/u
$follow not $key =~ /\$/u
Truth table100%3/3
A and not(B)
A= $followB= not $key =~ /\$/u
ABresult
0X0
100
111
1341 }
1342 177 my $rule_ref = $raw_rules[ $r_idx + 1 ];
1343 177 ▶ if (ref $rule_ref ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rule_ref ne "HASH") 0 177 177
1344 0 Config::Model::Exception::ModelDeclaration->throw(
1345 error => "Warp rule error in element "
1346 . "'$config_class_name->$elt_name': "
1347 . "rule effect must be a hash ref. Got '$rule_ref'" );
1348 }
1349  
1350 177 my %new_rule = (
1351 when => join( ' or ', @bool_expr ),
1352 apply => $rule_ref,
1353 );
1354 177 push @rules, \%new_rule;
1355 177 ▶ $self->show_legacy_issue(
Branch: 1 branch
BranchTrueFalseTotal
if @keys > 1 6 171 177
1356 "$config_class_name $elt_name: using an array for warp rule test is deprecated. ".
1357 "Please use a string with named parameters like «$new_rule{when}»."
1358 ) if @keys > 1;
1359 }
1360 }
1361 elsif ( defined $raw_rules ) {
1362 0 Config::Model::Exception::ModelDeclaration->throw(
1363 error => "Warp rule error in element "
1364 . "'$config_class_name->$elt_name': "
1365 . "rules must be an array ref. Got '$raw_rules'" );
1366 }
1367  
1368 131 for my $rule (@rules) {
1369 # no effect on non leaf type which cannot have old built_in
1370 252 $self->translate_legacy_builtin( $config_class_name, $rule, $rule );
1371 }
1372  
1373 131 return \@rules;
1374 }
1375  
1376 1042 ▶sub translate_legacy_builtin {
Subroutine translate_legacy_builtin: called CC=4 SCAR=22.9
Pod undocumented
1377 1042 my ( $self, $config_class_name, $model, $normalized_model ) = @_;
1378  
1379 1042 my $raw_builtin_default = delete $normalized_model->{built_in};
1380 1042 ▶ return unless defined $raw_builtin_default;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw_builtin_default 1042 0 1042
1381  
1382 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1383 Data::Dumper->Dump( [$normalized_model], ['builtin to translate'] )
1384 ) if $legacy_logger->is_debug;
1385  
1386 0 $self->show_legacy_issue([ "$config_class_name: parameter 'built_in' is deprecated "
1387 . "in favor of 'upstream_default'" ]);
1388  
1389 0 $model->{upstream_default} = $raw_builtin_default;
1390  
1391 0 ▶ $legacy_logger->debug( Data::Dumper->Dump( [$model], ['translated_builtin'] ))
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1392 if $legacy_logger->is_debug;
1393 0 return;
1394 }
1395  
1396 68 ▶sub translate_legacy_built_in_list {
Subroutine translate_legacy_built_in_list: called CC=4 SCAR=22.9
Pod undocumented
1397 68 my ( $self, $config_class_name, $model, $normalized_model ) = @_;
1398  
1399 68 my $raw_builtin_default = delete $normalized_model->{built_in_list};
1400 68 ▶ return unless defined $raw_builtin_default;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw_builtin_default 68 0 68
1401  
1402 0 ▶ $legacy_logger->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1403 Data::Dumper->Dump( [$normalized_model], ['built_in_list to translate'] )
1404 ) if $legacy_logger->is_debug;
1405  
1406 0 $self->show_legacy_issue([ "$config_class_name: parameter 'built_in_list' is deprecated "
1407 . "in favor of 'upstream_default_list'" ]);
1408  
1409 0 $model->{upstream_default_list} = $raw_builtin_default;
1410  
1411 0 ▶ $legacy_logger->debug( Data::Dumper->Dump( [$model], ['translated_built_in_list'] ))
Branch: 1 branch
BranchTrueFalseTotal
if $legacy_logger->is_debug 0 0 0
1412 if $legacy_logger->is_debug;
1413 0 return;
1414 }
1415  
1416 266 ▶sub include_class {
Subroutine include_class: called CC=6 SCAR=18.0
Pod undocumented
1417 266 my $self = shift;
1418 266 ▶ my $class_name = shift || croak "include_class: undef includer";
Condition50%1/2
shift() || croak('include_class: undef includer')
l!l
2660
MC/DC0%0/1
shift() || croak('include_class: undef includer')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1419 266 ▶ my $target_model = shift || die "include_class: undefined target_model";
Condition50%1/2
shift() || die('include_class: undefined target_model')
l!l
2660
MC/DC0%0/1
shift() || die('include_class: undefined target_model')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1420  
1421 266 my $include_class = delete $target_model->{include};
1422  
1423 266 ▶ return () unless defined $include_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $include_class 201 65 266
1424  
1425 65 my $include_after = delete $target_model->{include_after};
1426  
1427 65 ▶ my @includes = ref $include_class ? @$include_class : ($include_class);
Branch: 1 branch
BranchTrueFalseTotal
ref $include_class ? : 7 58 65
1428  
1429 # use reverse because included classes are *inserted* in front
1430 # of the list (or inserted after $include_after
1431 65 foreach my $inc ( reverse @includes ) {
1432 66 $self->include_one_class( $class_name, $target_model, $inc, $include_after );
1433 }
1434 64 return;
1435 }
1436  
1437 66 ▶sub include_one_class {
Subroutine include_one_class: called CC=12 SCAR=25.9
Pod undocumented
1438 66 my $self = shift;
1439 66 ▶ my $class_name = shift || croak "include_class: undef includer";
Condition50%1/2
shift() || croak('include_class: undef includer')
l!l
660
MC/DC0%0/1
shift() || croak('include_class: undef includer')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1440 66 ▶ my $target_model = shift || croak "include_class: undefined target_model";
Condition50%1/2
shift() || croak('include_class: undefined target_model')
l!l
660
MC/DC0%0/1
shift() || croak('include_class: undefined target_model')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1441 66 ▶ my $include_class = shift || croak "include_class: undef include_class param";
Condition50%1/2
shift() || croak('include_class: undef include_class param')
l!l
660
MC/DC0%0/1
shift() || croak('include_class: undef include_class param')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1442 66 my $include_after = shift;
1443  
1444 66 get_logger('Model')->debug("class $class_name includes $include_class");
1445  
1446 66 ▶ if ( defined $include_class
Branch: 1 branch
BranchTrueFalseTotal
if (defined $include_class and defined $self->{"included_class"}{$class_name}{$include_class}) 0 66 66
Condition33%1/3
defined $include_class and defined $self->{"included_class"}{$class_name}{$include_class}
!ll&&!rl&&r
0660
MC/DC0%0/2
defined $include_class and defined $self->{"included_class"}{$class_name}{$include_class}
defined $include_class defined $self->{"included_class"}{$class_name}{$include_class}
Truth table33%1/3
A and B
A= defined $include_classB= defined $self->{"included_class"}{$class_name}{$include_class}
ABresult
0X0
100
111
1447 and defined $self->{included_class}{$class_name}{$include_class} ) {
1448 0 Config::Model::Exception::ModelDeclaration->throw(
1449 error => "Recursion error ? $include_class has "
1450 . "already been included by $class_name." );
1451 }
1452 66 $self->{included_class}{$class_name}{$include_class} = 1;
1453  
1454 # takes care of recursive include, because get_model will perform
1455 # includes (and normalization). Is already a dclone
1456 66 my $included_model = $self->get_model_clone($include_class);
1457  
1458 # now include element in element_list (special treatment because order is
1459 # important)
1460 66 my $target_list = $target_model->{element_list};
1461 66 my $included_list = $included_model->{element_list};
1462 66 my $splice_idx = 0;
1463 66 ▶ if ( defined $include_after and defined $included_model->{element} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $include_after and defined $included_model->{"element"}) 24 42 66
Condition66%2/3
defined $include_after and defined $included_model->{"element"}
!ll&&!rl&&r
42024
MC/DC50%1/2
defined $include_after and defined $included_model->{"element"}
defined $include_after defined $included_model->{"element"}
Truth table66%2/3
A and B
A= defined $include_afterB= defined $included_model->{"element"}
ABresult
0X0
100
111
1464 24 my $idx = 0;
1465 24 my %elt_idx = map { ( $_, $idx++ ); } @$target_list;
1466  
1467 24 ▶ if ( not defined $elt_idx{$include_after} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $elt_idx{$include_after}) 0 24 24
1468 0 my $msg =
1469 "Unknown element for 'include_after': "
1470 . "$include_after, expected "
1471 . join( ' ', sort keys %elt_idx );
1472 0 Config::Model::Exception::ModelDeclaration->throw( error => $msg );
1473 }
1474  
1475 # + 1 because we splice *after* $include_after
1476 24 $splice_idx = $elt_idx{$include_after} + 1;
1477 }
1478  
1479 66 splice( @$target_list, $splice_idx, 0, @$included_list );
1480 66 get_logger('Model')->debug("class $class_name new elt list: @$target_list");
1481  
1482 # now actually include all elements
1483 66 ▶ my $target_element = $target_model->{element} ||= {};
Condition100%2/2
$target_model->{"element"} ||= {}
l!l
4620
MC/DC100%1/1
$target_model->{"element"} ||= {}
$target_model->{"element"}
Truth table100%2/2
A
A= $target_model->{"element"}
Aresult
11
00
1484 66 foreach my $included_elt (@$included_list) {
1485 189 ▶ if ( not defined $target_element->{$included_elt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $target_element->{$included_elt}) { } 188 1 189
1486 188 get_logger('Model')->debug("class $class_name includes elt $included_elt");
1487 188 $target_element->{$included_elt} = $included_model->{element}{$included_elt};
1488 }
1489 else {
1490 1 Config::Model::Exception::ModelDeclaration->throw(
1491 error => "Cannot clobber element '$included_elt' in $class_name"
1492 . " (included from $include_class)" );
1493 }
1494 }
1495 65 get_logger('Model')->debug("class $class_name include $include_class done");
1496 65 return;
1497 }
1498  
1499 0 ▶sub find_model_file_in_dir ($model_name, $model_path) {
Subroutine find_model_file_in_dir: not called CC=3 SCAR=24.8
Pod undocumented
1500 0 foreach my $ext (qw/yml yaml pl/) {
1501 0 my $sub_path = $model_name =~ s!::!/!rg;
1502 0 my $path_load_file = $model_path->child($sub_path . '.' . $ext);
1503 0 ▶ return $path_load_file if $path_load_file->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $path_load_file->exists 0 0 0
1504 }
1505 0 return;
1506 }
1507  
1508 51 ▶sub find_model_file_in_inc {
Subroutine find_model_file_in_inc: called CC=14 SCAR=28.5
Pod undocumented
1509 51 my ($self, $model_name, $load_file) = @_;
1510  
1511 51 ▶ if ($load_file and $load_file =~ m!^/!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($load_file and $load_file =~ m[^/]u) 1 50 51
Condition100%3/3
$load_file and $load_file =~ m[^/]u
!ll&&!rl&&r
28221
MC/DC100%2/2
$load_file and $load_file =~ m[^/]u
$load_file $load_file =~ m[^/]u
Truth table100%3/3
A and B
A= $load_fileB= $load_file =~ m[^/]u
ABresult
0X0
100
111
1512 # do not seach absolute path in @INC.
1513 1 return $load_file;
1514 }
1515  
1516 50 my $path_load_file ;
1517  
1518 50 ▶ if ($load_file and $load_file =~ m!^/! ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($load_file and $load_file =~ m[^/]u) { } 0 50 50
elsif ($self->model_dir and $self->model_dir =~ m[^/]u) { } 0 50 50
Condition66%2/3
$load_file and $load_file =~ m[^/]u
!ll&&!rl&&r
28220
MC/DC0%0/2
$load_file and $load_file =~ m[^/]u
$load_file $load_file =~ m[^/]u
Truth table66%2/3
A and B
A= $load_fileB= $load_file =~ m[^/]u
ABresult
0X0
100
111
1519 # load_file is absolute, do not search in @INC
1520 0 $path_load_file = $load_file;
1521 ▶ } elsif ($self->model_dir and $self->model_dir =~ m!^/!) {
Condition33%1/3
$self->model_dir and $self->model_dir =~ m[^/]u
!ll&&!rl&&r
0500
MC/DC0%0/2
$self->model_dir and $self->model_dir =~ m[^/]u
$self->model_dir $self->model_dir =~ m[^/]u
Truth table33%1/3
A and B
A= $self->model_dirB= $self->model_dir =~ m[^/]u
ABresult
0X0
100
111
1522 # model_dir is absolute, do not search in @INC
1523 0 my $model_path = path($self->model_dir);
1524 0 $path_load_file = find_model_file_in_dir ($model_name, $model_path);
1525 0 ▶ Config::Model::Exception::ModelDeclaration->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $path_load_file 0 0 0
1526 error => "Cannot find $model_name file in $model_path"
1527 ) unless $path_load_file;
1528 }
1529 else {
1530 50 foreach my $inc_str (@INC) {
1531 73 my $inc_path = path($inc_str);
1532 73 ▶ if ($load_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($load_file) { } 22 51 73
1533 22 $path_load_file = $inc_path->child($load_file);
1534 }
1535 else {
1536 51 my $sub_path = $model_name =~ s!::!/!rg;
1537 51 my $model_path = $inc_path->child($self->model_dir);
1538 51 foreach my $ext (qw/yml yaml pl/) {
1539 153 $path_load_file = $model_path->child($sub_path . '.' . $ext);
1540 153 ▶ last if $path_load_file->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $path_load_file->exists 27 126 153
1541 }
1542 }
1543 73 ▶ last if $path_load_file->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $path_load_file->exists 49 24 73
1544 }
1545 }
1546  
1547 50 ▶ Config::Model::Exception::ModelDeclaration->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $path_load_file 0 50 50
1548 error => "Cannot find $model_name file in \@INC"
1549 ) unless $path_load_file;
1550  
1551 50 $loader_logger->debug("model $model_name from file $path_load_file");
1552  
1553 50 return $path_load_file;
1554 }
1555  
1556 50 ▶sub load_model_plugins {
Subroutine load_model_plugins: called CC=7 SCAR=19.5
Pod undocumented
1557 50 my ($self, @model_names) = @_;
1558  
1559 # look for additional model information
1560 50 my %model_graft_by_name;
1561 my %done; # avoid loading twice the same snippet (where system version may clobber dev version)
1562  
1563 50 foreach my $inc_str (@INC) {
1564 439 foreach my $name ( @model_names ) {
1565 2707 my $snippet_path = $name;
1566 2707 $snippet_path =~ s/::/\//g;
1567 2707 my $snippet_dir = path($inc_str)->absolute->child($self->model_dir)->child($snippet_path . '.d');
1568 2707 $loader_logger->trace("looking for snippet in $snippet_dir");
1569 2707 ▶ if ( $snippet_dir->is_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($snippet_dir->is_dir) 1 2706 2707
1570 1 my $iter = $snippet_dir->iterator({ recurse => 1 });
1571  
1572 1 ▶ while ( my $snippet_file = $iter->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $snippet_file = &$iter()) 1 1 2
1573 1 ▶ next unless $snippet_file =~ /\.pl$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $snippet_file =~ /\.pl$/u 0 1 1
1574  
1575 # $snippet_file (Path::Tiny object) was
1576 # constructed from @INC content (i.e. $inc_str)
1577 # and contains an absolute path. Since
1578 # _load_model_in_hash uses 'do' (which may search
1579 # in @INC), the file path passed to
1580 # _load_model_in_hash must be either absolute or
1581 # relative to $inc_str
1582 1 my $snippet_file_rel = $snippet_file->relative($inc_str);
1583  
1584 1 my $done_key = $name . ':' . $snippet_file_rel;
1585 1 ▶ next if $done{$done_key};
Branch: 1 branch
BranchTrueFalseTotal
if $done{$done_key} 0 1 1
1586 1 $loader_logger->info("Found snippet $snippet_file in $inc_str dir");
1587 1 my $snippet_model = $self->_read_model_file($snippet_file);
1588  
1589 1 $self->_merge_model_in_hash( \%model_graft_by_name, $snippet_model, $snippet_file_rel);
1590 1 $done{$done_key} = 1;
1591 }
1592 }
1593 }
1594 }
1595 50 return %model_graft_by_name;
1596 }
1597  
1598 # load a model from file. See comments around raw_models attribute for explanations
1599 # $model_name: model name like Foo::Bar
1600 # $load_file: model file (override model name), used for tests
1601 51 ▶sub load ($self, $model_name, $load_file = '') {
Subroutine load: called CC=5 SCAR=16.1
Pod documented
1602 51 $loader_logger->debug("called on model $model_name");
1603 51 my $path_load_file = $self->find_model_file_in_inc($model_name, $load_file);
1604  
1605 # Searches $load_file in @INC and returns an array containing the
1606 # names of the loaded classes
1607 51 my $model = $self->_read_model_file($path_load_file->absolute);
1608  
1609 50 my ($loaded_classes, $models_by_name) = $self->store_model( $model_name, $model, $path_load_file );
1610  
1611 50 my %model_graft_by_name = $self->load_model_plugins(sort keys $models_by_name->%*);
1612  
1613 # store snippet. May be used later
1614 50 foreach my $name (keys %model_graft_by_name) {
1615 # store snippet for later usage
1616 1 $loader_logger->trace("storing snippet for model $name");
1617 1 $self->add_snippet($model_graft_by_name{$name});
1618 }
1619  
1620 # check if a snippet is available for this class
1621 50 foreach my $snippet ( $self->all_snippets ) {
1622 2 my $class_to_merge = $snippet->{name};
1623 2 ▶ next unless $models_by_name->{$class_to_merge};
Branch: 1 branch
BranchTrueFalseTotal
unless $models_by_name->{$class_to_merge} 1 1 2
1624 1 $self->augment_config_class_really( $class_to_merge, $snippet );
1625 }
1626  
1627 # return the list of classes found in $load_file. Respecting the order of the class
1628 # declaration is important for Config::Model::Itself so the class are written back
1629 # in the same order.
1630 50 return $loaded_classes->@*;
1631 }
1632  
1633 # path_load_file is used to build error messages
1634 50 ▶sub store_model ($self, $model_name, $model, $path_load_file ) {
Subroutine store_model: called CC=2 SCAR=6.9
Pod undocumented
1635 50 my %models_by_name;
1636 50 my @loaded_classes = $self->_merge_model_in_hash( \%models_by_name, $model, $path_load_file );
1637  
1638 50 $self->store_raw_model( $model_name, dclone( \%models_by_name ) );
1639  
1640 50 foreach my $name ( keys %models_by_name ) {
1641 302 my $data = $self->normalize_class_parameters( $name, $models_by_name{$name} );
1642 302 $loader_logger->debug("Store normalized model $name");
1643 302 $self->store_normalized_model( $name, $data );
1644 }
1645 50 return \@loaded_classes, \%models_by_name;
1646 }
1647  
1648 51 ▶sub _merge_model_in_hash {
Subroutine _merge_model_in_hash: called CC=5 SCAR=16.2
1649 51 my ( $self, $hash_ref, $model, $load_file ) = @_;
1650  
1651 51 my @names;
1652 51 foreach my $config_class_info (@$model) {
1653 303 ▶ my %data =
Branch: 2 branches
BranchTrueFalseTotal
ref $config_class_info eq 'HASH' ? : 149 154 303
ref $config_class_info eq 'ARRAY' ? : 154 0 154
1654 ref $config_class_info eq 'HASH' ? %$config_class_info
1655 : ref $config_class_info eq 'ARRAY' ? @$config_class_info
1656 : croak "load $load_file: config_class_info is not a ref";
1657 my $config_class_name = $data{name}
1658 303 ▶ or croak "load: missing config class name in $load_file";
Branch: 1 branch
BranchTrueFalseTotal
my $config_class_name = $data{"name"} or croak("load: missing config class name in $load_file") 303 0 303
1659  
1660 # check config class parameters and fill %model
1661 303 $hash_ref->{$config_class_name} = \%data;
1662 303 push @names, $config_class_name;
1663 }
1664  
1665 51 return @names;
1666 }
1667  
1668 52 ▶sub _read_model_file {
Subroutine _read_model_file: called CC=6 SCAR=18.5
1669 52 my ( $self, $load_file ) = @_;
1670  
1671 52 $loader_logger->info("read model file $load_file");
1672  
1673 52 my $err_msg = '';
1674 # do searches @INC if the file path is not absolute
1675 52 my $model_list = do $load_file;
1676  
1677 52 ▶ unless ($model_list) {
Branch: 2 branches
BranchTrueFalseTotal
if ($model_list) { } 51 1 52
if (do { ref $model_list ne "ARRAY" }) 1 50 51
1678 1 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 1 1
elsif (not defined $model_list) { } 1 0 1
1679 0 $err_msg = "couldn't parse $load_file: $@";
1680 }
1681 elsif ( not defined $model_list ) {
1682 1 $err_msg = "couldn't do $load_file: $!"
1683 }
1684 else {
1685 0 $err_msg = "couldn't run $load_file";
1686 }
1687 }
1688 0 elsif ( ref($model_list) ne 'ARRAY' ) {
1689 1 $model_list = [$model_list];
1690 }
1691  
1692 52 ▶ Config::Model::Exception::ModelDeclaration->throw( message => "read model error: $err_msg" )
Branch: 1 branch
BranchTrueFalseTotal
if $err_msg 1 51 52
1693 if $err_msg;
1694  
1695 51 return $model_list;
1696 }
1697  
1698 6 ▶sub augment_config_class {
Subroutine augment_config_class: called CC=2 SCAR=7.0
Pod documented
1699 6 my ( $self, %augment_data ) = @_;
1700  
1701 # %args must contain existing class name to augment
1702  
1703 # plus other data to merge to raw model
1704 my $config_class_name = delete $augment_data{name}
1705 6 ▶ || croak "augment_config_class: missing class name";
Condition50%1/2
delete $augment_data{'name'} || croak('augment_config_class: missing class name')
l!l
60
MC/DC0%0/1
delete $augment_data{'name'} || croak('augment_config_class: missing class name')
delete $augment_data{'name'}
Truth table50%1/2
A
A= delete $augment_data{'name'}
Aresult
11
00
1706  
1707 6 $self->augment_config_class_really( $config_class_name, \%augment_data );
1708 6 return;
1709 }
1710  
1711 7 ▶sub augment_config_class_really {
Subroutine augment_config_class_really: called CC=5 SCAR=16.1
Pod undocumented
1712 7 my ( $self, $config_class_name, $augment_data ) = @_;
1713  
1714 7 my $orig_model = $self->normalized_model($config_class_name);
1715 7 ▶ croak "unknown class to augment: $config_class_name" unless defined $orig_model;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $orig_model 0 7 7
1716  
1717 7 my $model_addendum = $self->normalize_class_parameters( $config_class_name, dclone($augment_data) );
1718  
1719 7 my $merge = Hash::Merge->new('RIGHT_PRECEDENT');
1720 7 my $new_model = $merge->merge( $orig_model, $model_addendum );
1721  
1722 # remove duplicates in element_list and accept_list while keeping order
1723 7 foreach my $list_name (qw/element_list accept_list/) {
1724 14 my %seen;
1725 my @newlist;
1726 14 foreach my $elt ( @{ $new_model->{$list_name} } ) {
1727 115 ▶ push @newlist, $elt unless $seen{$elt};
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$elt} 108 7 115
1728 115 $seen{$elt} = 1;
1729 }
1730  
1731 14 $new_model->{$list_name} = \@newlist;
1732 }
1733  
1734 7 $self->store_normalized_model( $config_class_name => $new_model );
1735 7 return;
1736 }
1737  
1738 3717 ▶sub model {
Subroutine model: called CC=5 SCAR=16.2
Pod documented
1739 3717 my $self = shift;
1740 3717 ▶ my $config_class_name = shift
Condition50%1/2
shift() || die('Model::get_model: missing config class name argument')
l!l
37170
MC/DC0%0/1
shift() || die('Model::get_model: missing config class name argument')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1741 || die "Model::get_model: missing config class name argument";
1742  
1743 3717 ▶ $self->load($config_class_name)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->normalized_model_exists($config_class_name) 28 3689 3717
1744 unless $self->normalized_model_exists($config_class_name);
1745  
1746 3716 ▶ if ( not $self->model_defined($config_class_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->model_defined($config_class_name)) 266 3450 3716
1747 266 $loader_logger->debug("creating model $config_class_name");
1748  
1749 266 my $model = $self->merge_included_class($config_class_name);
1750 265 $self->_store_model( $config_class_name, $model );
1751 }
1752  
1753 3715 ▶ return $self->_get_model($config_class_name)
Condition50%1/2
$self->_get_model($config_class_name) || croak("get_model error: unknown config class name: $config_class_name")
l!l
37150
MC/DC0%0/1
$self->_get_model($config_class_name) || croak("get_model error: unknown config class name: $config_class_name")
$self->_get_model($config_class_name)
Truth table50%1/2
A
A= $self->_get_model($config_class_name)
Aresult
11
00
1754 || croak "get_model error: unknown config class name: $config_class_name";
1755  
1756 }
1757  
1758 0 ▶sub get_model {
Subroutine get_model: not called CC=1 SCAR=6.9
Pod undocumented
1759 0 my ($self,$model) = @_;
1760 0 carp "get_model is deprecated in favor of get_model_clone";
1761 0 return $self->get_model_clone($model);
1762 }
1763  
1764 994 ▶sub get_model_clone {
Subroutine get_model_clone: called CC=1 SCAR=0.0
Pod documented
1765 994 my ($self,$model) = @_;
1766 994 return dclone($self->model($model));
1767 }
1768  
1769 # internal
1770 3 ▶sub get_model_doc {
Subroutine get_model_doc: called CC=23 SCAR=31.7
Pod undocumented
1771 3 my ( $self, $top_class_name, $done ) = @_;
1772  
1773 3 ▶ $done //= {};
Condition100%2/2
$done //= {}
l!l
21
MC/DC100%1/1
$done //= {}
$done
Truth table100%2/2
A
A= $done
Aresult
11
00
1774 3 ▶ if ( not defined $self->normalized_model($top_class_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->normalized_model($top_class_name)) 2 1 3
1775 2 eval { $self->model($top_class_name); };
1776 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 1 2
1777 1 my $e = $@;
1778 1 ▶ if ($e->isa('Config::Model::Exception::ModelDeclaration')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->isa('Config::Model::Exception::ModelDeclaration')) { } 1 0 1
1779 1 Config::Model::Exception::Fatal->throw(
1780 message => "Unknown configuration class : $top_class_name ($@)"
1781 );
1782 }
1783 else {
1784 0 $e->rethrow;
1785 }
1786 }
1787 }
1788  
1789 2 my @classes = ($top_class_name);
1790 2 my %result;
1791  
1792 2 ▶ while (@classes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@classes) 18 2 20
1793 18 my $class_name = shift @classes;
1794 18 ▶ next if $done->{$class_name} ;
Branch: 1 branch
BranchTrueFalseTotal
if $done->{$class_name} 8 10 18
1795  
1796 10 ▶ my $c_model = $self->model($class_name)
Condition50%1/2
$self->model($class_name) || croak("get_model_doc model error : unknown config class name: $class_name")
l!l
100
MC/DC0%0/1
$self->model($class_name) || croak("get_model_doc model error : unknown config class name: $class_name")
$self->model($class_name)
Truth table50%1/2
A
A= $self->model($class_name)
Aresult
11
00
1797 || croak "get_model_doc model error : unknown config class name: $class_name";
1798  
1799 10 my $full_name = "Config::Model::models::$class_name";
1800  
1801 10 my %see_also;
1802  
1803 10 my @pod = (
1804  
1805 # Pod::Weaver compatibility
1806 "# PODNAME: $full_name",
1807 "# ABSTRACT: Configuration class " . $class_name, '',
1808  
1809 # assume utf8 for all docs
1810 "=encoding utf8", '',
1811  
1812 # plain old pod compatibility
1813 "=head1 NAME", '',
1814 "$full_name - Configuration class " . $class_name, '',
1815  
1816 "=head1 DESCRIPTION", '',
1817 "Configuration classes used by L<Config::Model>", ''
1818 );
1819  
1820 10 my %legalese;
1821  
1822 10 my $i = 0;
1823  
1824 10 my $class_desc = $c_model->{class_description};
1825 10 ▶ push @pod, $class_desc, '' if defined $class_desc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $class_desc 2 8 10
1826  
1827 10 my @elt = ( "=head1 Elements", '' );
1828 10 foreach my $elt_name ( @{ $c_model->{element_list} } ) {
1829 75 my $elt_info = $c_model->{element}{$elt_name};
1830 75 ▶ my $summary = $elt_info->{summary} || '';
Condition50%1/2
$elt_info->{'summary'} || ''
l!l
075
MC/DC0%0/1
$elt_info->{'summary'} || ''
$elt_info->{'summary'}
Truth table50%1/2
A
A= $elt_info->{'summary'}
Aresult
11
00
1831 75 ▶ $summary &&= " - $summary";
Condition50%1/2
$summary &&= " - $summary"
!ll
750
MC/DC0%0/1
$summary &&= " - $summary"
$summary
Truth table50%1/2
A
A= $summary
Aresult
00
11
1832 75 push @elt, "=head2 $elt_name$summary", '';
1833 75 push @elt, $self->get_element_description($elt_info), '';
1834  
1835 75 foreach ( $elt_info, $elt_info->{cargo} ) {
1836 150 ▶ if ( my $ccn = $_->{config_class_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ccn = $_->{"config_class_name"}) 16 134 150
1837 16 push @classes, $ccn;
1838 16 $see_also{$ccn} = 1;
1839 }
1840 150 ▶ if ( my $migr = $_->{migrate_from} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $migr = $_->{"migrate_from"}) 0 150 150
1841 0 push @elt, $self->get_migrate_doc( $elt_name, 'is migrated with', $migr );
1842 }
1843 150 ▶ if ( my $migr = $_->{migrate_values_from} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $migr = $_->{"migrate_values_from"}) 0 150 150
1844 0 push @elt, "Note: $elt_name values are migrated from '$migr'", '';
1845 }
1846 150 ▶ if ( my $comp = $_->{compute} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comp = $_->{"compute"}) 0 150 150
1847 0 push @elt, $self->get_migrate_doc( $elt_name, 'is computed with', $comp );
1848 }
1849 }
1850 }
1851  
1852 10 foreach my $what (qw/author copyright license/) {
1853 30 my $item = $c_model->{$what};
1854 30 ▶ push @{ $legalese{$what} }, $item if $item;
Branch: 1 branch
BranchTrueFalseTotal
if $item 6 24 30
1855 }
1856  
1857 10 my @end;
1858 10 foreach my $what (qw/author copyright license/) {
1859 30 ▶ next unless @{ $legalese{$what} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$legalese{$what} or [];} 24 6 30
Condition100%2/2
$legalese{$what} || []
l!l
624
MC/DC100%1/1
$legalese{$what} || []
$legalese{$what}
Truth table100%2/2
A
A= $legalese{$what}
Aresult
11
00
1860 push @end, "=head1 " . uc($what), '', '=over', '',
1861 6 ▶ ( map { ( "=item $_", '' ); } map { ref $_ ? @$_ : $_ } @{ $legalese{$what} } ),
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 2 4 6
1862 '', '=back', '';
1863 }
1864  
1865 my @see_also = (
1866 "=head1 SEE ALSO",
1867 '',
1868 "=over",
1869 '',
1870 "=item *",
1871 '',
1872 "L<cme>",
1873 '',
1874 10 ( map { ( "=item *", '', "L<Config::Model::models::$_>", '' ); } sort keys %see_also ),
1875 "=back",
1876 ''
1877 );
1878  
1879 10 $result{$full_name} = join( "\n", @pod, @elt, @see_also, @end, '=cut', '' ) . "\n";
1880 10 $done->{$class_name} = 1;
1881 }
1882 2 return \%result;
1883 }
1884  
1885 0 ▶sub get_migrate_doc {
Subroutine get_migrate_doc: not called CC=3 SCAR=24.8
Pod undocumented
1886 0 my ( $self, $elt_name, $desc, $migr ) = @_;
1887  
1888 0 my $mv = $migr->{variables};
1889 0 my $mform = $migr->{formula};
1890  
1891 0 ▶ if ( $mform =~ /\n/) { $mform =~ s/^/ /mg; $mform = "\n\n$mform\n\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($mform =~ /\n/u) { } 0 0 0
1892 0 else { $mform = "'C<$mform>' " }
1893  
1894 my $mdoc = "Note: $elt_name $desc ${mform}and with: \n\n=over\n\n=item *\n\n"
1895 0 . join( "\n\n=item *\n\n", map { qq!C<\$$_> => C<$mv->{$_}>! } sort keys %$mv );
1896 0 ▶ if ( my $rep = $migr->{replace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rep = $migr->{"replace"}) 0 0 0
1897 $mdoc .= "\n\n=item *\n\n"
1898 0 . join( "\n\n=item *\n\n", map { qq!C<\$replace{$_}> => C<$rep->{$_}>! } sort keys %$rep );
1899 }
1900 0 $mdoc .= "\n\n=back\n\n";
1901  
1902 0 return ( $mdoc, '' );
1903 }
1904  
1905 75 ▶sub get_element_description {
Subroutine get_element_description: called CC=18 SCAR=29.0
Pod undocumented
1906 75 my ( $self, $elt_info ) = @_;
1907  
1908 75 my $type = $elt_info->{type};
1909 75 my $cargo = $elt_info->{cargo};
1910 75 my $vt = $elt_info->{value_type};
1911  
1912 75 my $of = '';
1913 75 my $cargo_type = $cargo->{type};
1914 75 my $cargo_vt = $cargo->{value_type};
1915 75 ▶ $of = " of " . ( $cargo_vt or $cargo_type ) if defined $cargo_type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cargo_type 16 59 75
Condition66%2/3
$cargo_vt || $cargo_type
l!l&&r!l&&!r
1060
MC/DC0%0/2
$cargo_vt || $cargo_type
$cargo_vt $cargo_type
Truth table66%2/3
A || B
A= $cargo_vtB= $cargo_type
ABresult
1X1
011
000
1916  
1917 75 ▶ my $ccn = $elt_info->{config_class_name} || $cargo->{config_class_name};
Condition100%3/3
$elt_info->{'config_class_name'} || $cargo->{'config_class_name'}
l!l&&r!l&&!r
10659
MC/DC100%2/2
$elt_info->{'config_class_name'} || $cargo->{'config_class_name'}
$elt_info->{'config_class_name'} $cargo->{'config_class_name'}
Truth table100%3/3
A || B
A= $elt_info->{'config_class_name'}B= $cargo->{'config_class_name'}
ABresult
1X1
011
000
1918 75 ▶ $of .= " of class L<$ccn|Config::Model::models::$ccn> " if $ccn;
Branch: 1 branch
BranchTrueFalseTotal
if $ccn 16 59 75
1919  
1920 75 ▶ my $desc = $elt_info->{description} || '';
Condition100%2/2
$elt_info->{'description'} || ''
l!l
669
MC/DC100%1/1
$elt_info->{'description'} || ''
$elt_info->{'description'}
Truth table100%2/2
A
A= $elt_info->{'description'}
Aresult
11
00
1921 75 ▶ if ($desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc) 6 69 75
1922 6 ▶ $desc .= '.' if $desc =~ /\w$/;
Branch: 1 branch
BranchTrueFalseTotal
if $desc =~ /\w$/u 6 0 6
1923 6 ▶ $desc .= ' ' unless $desc =~ /\s$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $desc =~ /\s$/u 6 0 6
1924 }
1925  
1926 75 ▶ if ( my $status = $elt_info->{status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $status = $elt_info->{"status"}) 0 75 75
1927 0 $desc .= 'B<' . ucfirst($status) . '> ';
1928 }
1929  
1930 75 ▶ my $info = $elt_info->{mandatory} ? 'Mandatory. ' : 'Optional. ';
Branch: 1 branch
BranchTrueFalseTotal
$elt_info->{'mandatory'} ? : 2 73 75
1931  
1932 75 ▶ $info .= "Type " . ( $vt || $type ) . $of . '. ';
Condition66%2/3
$vt || $type
l!l&&r!l&&!r
47280
MC/DC0%0/2
$vt || $type
$vt $type
Truth table66%2/3
A || B
A= $vtB= $type
ABresult
1X1
011
000
1933  
1934 75 foreach my $name (qw/choice/) {
1935 75 my $item = $elt_info->{$name};
1936 75 ▶ next unless defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 63 12 75
1937 12 $info .= "$name: '" . join( "', '", @$item ) . "'. ";
1938 }
1939  
1940 75 my @default_info = ();
1941 # assemble in over item for string value_type
1942 75 foreach my $name (qw/default upstream_default/) {
1943 150 my $item = $elt_info->{$name};
1944 150 ▶ next unless defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 139 11 150
1945 11 push @default_info, [$name, $item] ;
1946 }
1947  
1948 75 my $elt_help = $self->get_element_value_help($elt_info);
1949  
1950 # breaks pod if $info is multiline
1951 75 my $ret = $desc . "I< $info > ";
1952  
1953 75 ▶ if (@default_info) {
Branch: 1 branch
BranchTrueFalseTotal
if (@default_info) 11 64 75
1954 11 $ret .= "\n\n=over 4\n\n";
1955 11 for ( @default_info) { $ret .= "=item $_->[0] value :\n\n$_->[1]\n\n"; }
1956 11 $ret .= "=back\n\n";
1957 }
1958  
1959 75 $ret.= $elt_help;
1960 75 return $ret;
1961 }
1962  
1963 75 ▶sub get_element_value_help {
Subroutine get_element_value_help: called CC=3 SCAR=11.0
Pod undocumented
1964 75 my ( $self, $elt_info ) = @_;
1965  
1966 75 my $help = $elt_info->{help};
1967 75 ▶ return '' unless defined $help;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $help 73 2 75
1968  
1969 2 my $help_text = "\n\nHere are some explanations on the possible values:\n\n=over\n\n";
1970 2 foreach my $v ( sort keys %$help ) {
1971 6 $help_text .= "=item '$v'\n\n$help->{$v}\n\n";
1972 }
1973  
1974 2 return $help_text . "=back\n\n";
1975 }
1976  
1977 2 ▶sub generate_doc {
Subroutine generate_doc: called CC=10 SCAR=25.4
Pod documented
1978 2 my ( $self, $top_class_name, $dir_str, $done ) = @_;
1979  
1980 2 ▶ $done //= {} ;
Condition50%1/2
$done //= {}
l!l
02
MC/DC0%0/1
$done //= {}
$done
Truth table50%1/2
A
A= $done
Aresult
11
00
1981 2 my $res = $self->get_model_doc($top_class_name, $done);
1982  
1983 1 ▶ if ( defined $dir_str and $dir_str ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir_str and $dir_str) { } 1 0 1
Condition33%1/3
defined $dir_str and $dir_str
!ll&&!rl&&r
001
MC/DC0%0/2
defined $dir_str and $dir_str
defined $dir_str $dir_str
Truth table33%1/3
A and B
A= defined $dir_strB= $dir_str
ABresult
0X0
100
111
1984 1 foreach my $class_name ( sort keys %$res ) {
1985 5 my $dir = path($dir_str);
1986 5 ▶ $dir->mkpath() unless $dir->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir->exists 0 5 5
1987 5 my $file_path = $class_name;
1988 5 $file_path =~ s!::!/!g;
1989 5 my $pl_file = $dir->child("$file_path.pl");
1990 5 ▶ $pl_file->parent->mkpath unless $pl_file->parent->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $pl_file->parent->exists 1 4 5
1991 5 my $pod_file = $dir->child("$file_path.pod");
1992  
1993 5 my $old = '';
1994 5 ▶ if ($pod_file->exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pod_file->exists) 0 5 5
1995 0 $old = $pod_file->slurp_utf8;
1996 }
1997 5 ▶ if ( $old ne $res->{$class_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old ne $res->{$class_name}) 5 0 5
1998 5 $pod_file->spew_utf8( $res->{$class_name} );
1999 5 say "Wrote documentation in $pod_file";
2000 }
2001 }
2002 }
2003 else {
2004 0 foreach my $class_name ( sort keys %$res ) {
2005 0 print "########## $class_name ############ \n\n";
2006 0 print $res->{$class_name};
2007 }
2008 }
2009 1 return;
2010 }
2011  
2012 3 ▶sub get_element_model {
Subroutine get_element_model: called CC=4 SCAR=14.5
Pod documented
2013 3 my $self = shift;
2014 3 ▶ my $config_class_name = shift
Condition50%1/2
shift() || die('Model::get_element_model: missing config class name argument')
l!l
30
MC/DC0%0/1
shift() || die('Model::get_element_model: missing config class name argument')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2015 || die "Model::get_element_model: missing config class name argument";
2016 3 ▶ my $element_name = shift
Condition50%1/2
shift() || die('Model::get_element_model: missing element name argument')
l!l
30
MC/DC0%0/1
shift() || die('Model::get_element_model: missing element name argument')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2017 || die "Model::get_element_model: missing element name argument";
2018  
2019 3 my $model = $self->model($config_class_name);
2020  
2021 3 ▶ my $element_m = $model->{element}{$element_name}
Condition50%1/2
$model->{'element'}{$element_name} || croak("get_element_model error: unknown element name: $element_name")
l!l
30
MC/DC0%0/1
$model->{'element'}{$element_name} || croak("get_element_model error: unknown element name: $element_name")
$model->{'element'}{$element_name}
Truth table50%1/2
A
A= $model->{'element'}{$element_name}
Aresult
11
00
2022 || croak "get_element_model error: unknown element name: $element_name";
2023  
2024 3 return dclone($element_m);
2025 }
2026  
2027 # returns a hash ref containing the raw model, i.e. before expansion of
2028 # multiple keys (i.e. [qw/a b c/] => ... )
2029 # internal. For now ...
2030 0 ▶sub get_normalized_model {
Subroutine get_normalized_model: not called CC=3 SCAR=24.8
Pod undocumented
2031 0 my $self = shift;
2032 0 my $config_class_name = shift;
2033  
2034 0 ▶ $self->load($config_class_name)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->normalized_model($config_class_name) 0 0 0
2035 unless defined $self->normalized_model($config_class_name);
2036  
2037 0 ▶ my $normalized_model = $self->normalized_model($config_class_name)
Condition0%0/2
$self->normalized_model($config_class_name) || croak("get_normalized_model error: unknown config class name: $config_class_name")
l!l
00
MC/DC0%0/1
$self->normalized_model($config_class_name) || croak("get_normalized_model error: unknown config class name: $config_class_name")
$self->normalized_model($config_class_name)
Truth table0%0/2
A
A= $self->normalized_model($config_class_name)
Aresult
11
00
2038 || croak "get_normalized_model error: unknown config class name: $config_class_name";
2039  
2040 0 return dclone($normalized_model);
2041 }
2042  
2043 104 ▶sub get_element_name ($self, %args) {
Subroutine get_element_name: called CC=7 SCAR=20.2
Pod documented
2044 my $class = $args{class}
2045 104 ▶ || croak "get_element_name: missing 'class' parameter";
Condition50%1/2
$args{'class'} || croak(q[get_element_name: missing 'class' parameter])
l!l
1040
MC/DC0%0/1
$args{'class'} || croak(q[get_element_name: missing 'class' parameter])
$args{'class'}
Truth table50%1/2
A
A= $args{'class'}
Aresult
11
00
2046  
2047 104 ▶ if (delete $args{for}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args{"for"}) 0 104 104
2048 0 carp "get_element_name: 'for' parameter is deprecated";
2049 }
2050  
2051 104 my $model = $self->model($class);
2052 104 my @result;
2053  
2054 # this is a bit convoluted, but the order of the returned element
2055 # must respect the order of the elements declared in the model by
2056 # the user
2057 104 foreach my $elt ( @{ $model->{element_list} } ) {
2058 542 my $elt_data = $model->{element}{$elt};
2059 542 ▶ my $l = $elt_data->{level} || get_default_property('level');
Condition66%2/3
$elt_data->{'level'} || get_default_property('level')
l!l&&r!l&&!r
315110
MC/DC0%0/2
$elt_data->{'level'} || get_default_property('level')
$elt_data->{'level'} get_default_property('level')
Truth table66%2/3
A || B
A= $elt_data->{'level'}B= get_default_property('level')
ABresult
1X1
011
000
2060 542 ▶ push @result, $elt if $l ne 'hidden' ;
Branch: 1 branch
BranchTrueFalseTotal
if $l ne "hidden" 535 7 542
2061 }
2062  
2063 104 ▶ return wantarray ? @result : join( ' ', @result );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 104 0 104
2064 }
2065  
2066 923 ▶sub get_element_property ($self, %args) {
Subroutine get_element_property: called CC=9 SCAR=22.6
Pod documented
2067 my $elt = $args{element}
2068 923 ▶ || croak "get_element_property: missing 'element' parameter";
Condition50%1/2
$args{'element'} || croak(q[get_element_property: missing 'element' parameter])
l!l
9230
MC/DC0%0/1
$args{'element'} || croak(q[get_element_property: missing 'element' parameter])
$args{'element'}
Truth table50%1/2
A
A= $args{'element'}
Aresult
11
00
2069 my $prop = $args{property}
2070 923 ▶ || croak "get_element_property: missing 'property' parameter";
Condition50%1/2
$args{'property'} || croak(q[get_element_property: missing 'property' parameter])
l!l
9230
MC/DC0%0/1
$args{'property'} || croak(q[get_element_property: missing 'property' parameter])
$args{'property'}
Truth table50%1/2
A
A= $args{'property'}
Aresult
11
00
2071 my $class = $args{class}
2072 923 ▶ || croak "get_element_property:: missing 'class' parameter";
Condition50%1/2
$args{'class'} || croak(q[get_element_property:: missing 'class' parameter])
l!l
9230
MC/DC0%0/1
$args{'class'} || croak(q[get_element_property:: missing 'class' parameter])
$args{'class'}
Truth table50%1/2
A
A= $args{'class'}
Aresult
11
00
2073  
2074 923 my $model = $self->model($class);
2075  
2076 # must take into account 'accept' model parameter
2077 923 ▶ if ( not defined $model->{element}{$elt} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $model->{"element"}{$elt}) 60 863 923
2078 60 $logger->debug("test accept for class $class elt $elt prop $prop");
2079 60 foreach my $acc_re ( @{ $model->{accept_list} } ) {
2080 126 ▶ return $model->{accept}{$acc_re}{$prop} || get_default_property($prop)
Branch: 1 branch
BranchTrueFalseTotal
if $elt =~ /^$acc_re$/u 60 66 126
Condition66%2/3
$model->{'accept'}{$acc_re}{$prop} || get_default_property($prop)
l!l&&r!l&&!r
1590
MC/DC0%0/2
$model->{'accept'}{$acc_re}{$prop} || get_default_property($prop)
$model->{'accept'}{$acc_re}{$prop} get_default_property($prop)
Truth table66%2/3
A || B
A= $model->{'accept'}{$acc_re}{$prop}B= get_default_property($prop)
ABresult
1X1
011
000
2081 if $elt =~ /^$acc_re$/;
2082 }
2083 }
2084  
2085 863 ▶ return $self->model($class)->{element}{$elt}{$prop}
Condition66%2/3
$self->model($class)->{'element'}{$elt}{$prop} || get_default_property($prop)
l!l&&r!l&&!r
917720
MC/DC0%0/2
$self->model($class)->{'element'}{$elt}{$prop} || get_default_property($prop)
$self->model($class)->{'element'}{$elt}{$prop} get_default_property($prop)
Truth table66%2/3
A || B
A= $self->model($class)->{'element'}{$elt}{$prop}B= get_default_property($prop)
ABresult
1X1
011
000
2086 || get_default_property($prop);
2087 }
2088  
2089 1 ▶sub list_class_element {
Subroutine list_class_element: called CC=3 SCAR=11.0
Pod documented
2090 1 my $self = shift;
2091 1 ▶ my $pad = shift || '';
Condition50%1/2
shift() || ''
l!l
01
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2092  
2093 1 my $res = '';
2094 1 foreach my $class_name ( $self->normalized_model_names ) {
2095 7 $res .= $self->list_one_class_element($class_name);
2096 }
2097 1 return $res;
2098 }
2099  
2100 7 ▶sub list_one_class_element {
Subroutine list_one_class_element: called CC=5 SCAR=16.2
Pod undocumented
2101 7 my $self = shift;
2102 7 my $class_name = shift;
2103 7 ▶ my $pad = shift || '';
Condition50%1/2
shift() || ''
l!l
07
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2104  
2105 7 my $res = $pad . "Class: $class_name\n";
2106 7 my $c_model = $self->normalized_model($class_name);
2107 7 my $elts = $c_model->{element_list}; # array ref
2108  
2109 7 ▶ return $res unless defined $elts and @$elts;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elts and @$elts 1 6 7
Condition66%2/3
defined $elts and @$elts
!ll&&!rl&&r
016
MC/DC50%1/2
defined $elts and @$elts
defined $elts @$elts
Truth table66%2/3
A and B
A= defined $eltsB= @$elts
ABresult
0X0
100
111
2110  
2111 6 foreach my $elt_name (@$elts) {
2112 36 my $type = $c_model->{element}{$elt_name}{type};
2113 36 $res .= $pad . " - $elt_name ($type)\n";
2114 }
2115 6 return $res;
2116 }
2117  
2118 59 __PACKAGE__->meta->make_immutable;
2119  
2120 59 1;
2121  
2122 # ABSTRACT: a framework to validate, migrate and edit configuration files
2123  
2124 __END__
« blib/lib/Config/Model/FuseUI.pm ↑ Summary blib/lib/Config/Model/Backend/IniFile.pm »