blib/lib/Config/Model/Node.pm

filter: Statementstmt 91.8% 459 / 500 Branchbran 72.2% 156 / 216 Conditioncond 63.9% 87 / 136 MC/DCmcdc 34.1% 27 / 79 Subroutinesub 93.9% 77 / 82 Podpod 71.7% 38 / 53 totaltotal 79.1% 844 / 1066 CC 176 SCAR 24.3
CC
176
Cov
82%
find_element
72.0
load_data
43.1
fetch_element
17.4
CRAP 11.3
« blib/lib/Config/Model/AnyId.pm ↑ Summary blib/lib/Config/Model/DumpAsData.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::Node 2.169;
11  
12 59 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 59 with "Config::Model::Role::NodeLoader";
14  
15 59 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 59 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 59 ▶use Config::Model::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 59 ▶use Config::Model::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 59 ▶use Config::Model::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 59 ▶use Config::Model::Loader;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 59 ▶use Config::Model::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 59 ▶use Config::Model::DumpAsData;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 59 ▶use Config::Model::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 59 ▶use Config::Model::TreeSearcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 59 ▶use Config::Model::Describe;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use Config::Model::BackendMgr;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 59 ▶use Log::Log4perl qw(get_logger :levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 59 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 59 ▶use List::MoreUtils qw(insert_after_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 59 extends qw/Config::Model::AnyThing/;
33  
34 59 with "Config::Model::Role::Grab";
35 59 with "Config::Model::Role::HelpAsText";
36 59 with "Config::Model::Role::ComputeFunction";
37 59 with "Config::Model::Role::Constants";
38 59 with "Config::Model::Role::Utils";
39  
40 59 ▶use feature qw/signatures postderef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 59 ▶no warnings qw/experimental::signatures experimental::postderef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 59 my %legal_properties = (
44 status => {qw/obsolete 1 deprecated 1 standard 1/},
45 level => {qw/important 1 normal 1 hidden 1/},
46 );
47  
48 59 my $logger = get_logger("Tree::Node");
49 59 my $fix_logger = get_logger("Anything::Fix");
50 59 my $change_logger = get_logger("ChangeTracker");
51 59 my $deep_check_logger = get_logger('DeepCheck');
52 59 my $user_logger = get_logger('User');
53  
54 # Here are the legal element types
55 59 my %create_sub_for = (
56 node => \&create_node,
57 leaf => \&create_leaf,
58 hash => \&create_id,
59 list => \&create_id,
60 check_list => \&create_id,
61 warped_node => \&create_warped_node,
62 );
63  
64 # Node internal documentation
65 #
66 # Since the class holds a significant number of element, here's its
67 # main structure.
68 #
69 # $self
70 # = (
71 # config_model : Weak reference to Config::Model object
72 # config_class_name
73 # model : model of the config class
74 # instance : Weak reference to Config::Model::Instance object
75 # element_name : Name of the element containing this node
76 # (undef for root node).
77 # parent : weak reference of parent node (undef for root node)
78 # element : actual storage of configuration elements
79  
80 # ) ;
81  
82 59 has initialized => ( is => 'rw', isa => 'Bool', default => 0 );
83  
84 59 has config_class_name => ( is => 'ro', isa => 'Str', required => 1 );
85  
86 59 has gist => (
87 is => 'rw',
88 isa => 'Str',
89 default => '',
90 );
91  
92 18 ▶sub fetch_gist ($self) {
Subroutine fetch_gist: called CC=3 SCAR=11.1
Pod documented
93 18 ▶ my $gist = $self->gist // '';
Condition50%1/2
$self->gist // ""
l!l
180
MC/DC0%0/1
$self->gist // ""
$self->gist
Truth table50%1/2
A
A= $self->gist
Aresult
11
00
94 # handle hash or list element count
95 18 $gist =~ s!\@\{([\w -]+)\}!$self->grab($1)->fetch_size!ge;
96  
97 18 ▶ $gist =~ s!{([\w -]+)}!$self->grab($1)->fetch_gist() // ''!ge;
Condition50%1/2
$self->grab($1)->fetch_gist // ""
l!l
220
MC/DC0%0/1
$self->grab($1)->fetch_gist // ""
$self->grab($1)->fetch_gist
Truth table50%1/2
A
A= $self->grab($1)->fetch_gist
Aresult
11
00
98  
99 # cleanup extra white spaces
100 18 $gist =~ s!\s+! !g;
101 18 $gist =~ s/^\s//;
102 18 $gist =~ s/\s$//;
103  
104 18 return $gist;
105 }
106  
107 59 has config_file => ( is => 'ro', isa => 'Config::Model::TypeContraints::Path', required => 0 );
108 59 has element_name => ( is => 'ro', isa => 'Maybe[Str]', required => 0 );
109  
110 59 has instance => (
111 is => 'ro',
112 isa => 'Config::Model::Instance',
113 weak_ref => 1,
114 required => 1,
115 handles => [qw/read_check/],
116 );
117  
118 59 has config_model => (
119 is => 'ro',
120 isa => 'Config::Model',
121 weak_ref => 1,
122 lazy => 1,
123 builder => '_config_model'
124 );
125  
126 818 ▶sub _config_model ($self) {
Subroutine _config_model: called CC=1 SCAR=0.0
127 818 return $self->instance->config_model;
128 }
129  
130 59 has model => ( is => 'rw', isa => 'HashRef' );
131 59 has needs_save => ( is => 'rw', isa => 'Bool', default => 0 );
132  
133 59 has backend_mgr => ( is => 'ro', isa => 'Maybe[Config::Model::BackendMgr]' );
134  
135 # used to avoid warning twice about a deprecated element. Internal methods
136 has warned_deprecated_element => (
137 is => 'ro',
138 isa => 'HashRef[Str]',
139 traits => ['Hash'],
140 818 ▶ default => sub { {}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
141 59 handles => {
142 warn_element_done => 'set',
143 was_element_warned => 'defined',
144 }
145 ) ;
146  
147 # attribute is defined in Config::Model::Anything
148 11 ▶sub _backend_support_annotation ($self) {
Subroutine _backend_support_annotation: called CC=3 SCAR=11.2
149 11 ▶ return $self->backend_mgr ? $self->backend_mgr->support_annotation
Branch: 2 branches
BranchTrueFalseTotal
$self->backend_mgr ? : 6 5 11
$self->parent ? : 5 0 5
150 : $self->parent ? $self->parent->backend_support_annotation
151 : undef ; # no backend at all. test only
152 }
153  
154 818 ▶sub BUILD ($self, $) {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
155 818 ▶ my $caller_class = defined $self->parent ? $self->parent->name : 'user';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->parent ? : 675 143 818
156  
157 818 my $class_name = $self->config_class_name;
158 818 $logger->debug("New $class_name requested by $caller_class");
159  
160 818 $self->{original_model} = $self->config_model->model($class_name);
161 818 $self->model( dclone($self->{original_model}) ) ;
162  
163 818 $self->check_properties;
164  
165 818 return $self;
166 }
167  
168 ## Create_* methods are all internal and should not be used directly
169  
170 4548 ▶sub create_element ($self, @args) {
Subroutine create_element: called CC=8 SCAR=21.3
Pod undocumented
171 4548 my %args = _resolve_arg_shortcut(\@args, 'name');
172 4548 my $element_name = $args{name};
173 4548 ▶ my $check = $args{check} || 'yes';
Condition50%1/2
$args{'check'} || 'yes'
l!l
45480
MC/DC0%0/1
$args{'check'} || 'yes'
$args{'check'}
Truth table50%1/2
A
A= $args{'check'}
Aresult
11
00
174  
175 4548 my $element_info = $self->{model}{element}{$element_name};
176  
177 4548 ▶ if ( not defined $element_info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $element_info) 2 4546 4548
178 2 ▶ if ( $check eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check eq 'yes') { } 1 1 2
179 Config::Model::Exception::UnknownElement->throw(
180 object => $self,
181 where => $self->location || 'configuration root',
182 element => $element_name,
183 autoadd => $args{autoadd},
184 1 ▶ );
Condition50%1/2
$self->location || 'configuration root'
l!l
01
MC/DC0%0/1
$self->location || 'configuration root'
$self->location
Truth table50%1/2
A
A= $self->location
Aresult
11
00
185 }
186 else {
187 1 return; # just skip when check is no or skip
188 }
189 }
190  
191 Config::Model::Exception::Model->throw(
192 4546 ▶ error => "element '$element_name' error: " . "passed information is not a hash ref",
Branch: 1 branch
BranchTrueFalseTotal
unless ref $element_info eq "HASH" 0 4546 4546
193 object => $self
194 ) unless ref($element_info) eq 'HASH';
195  
196 Config::Model::Exception::Model->throw(
197 error => "create element '$element_name' error: " . "missing 'type' parameter",
198 object => $self
199 4546 ▶ ) unless defined $element_info->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $element_info->{"type"} 0 4546 4546
200  
201 4546 my $method = $create_sub_for{ $element_info->{type} };
202  
203 croak $self->{config_class_name},
204 4546 ▶ " error: unknown element type $element_info->{type}, expected ",
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 0 4546 4546
205 join(' ', sort keys %create_sub_for)
206 unless defined $method;
207  
208 4546 return $self->$method( $element_name, $check );
209 }
210  
211 197 ▶sub create_node ($self, $element_name, $check) {
Subroutine create_node: called CC=2 SCAR=7.0
Pod undocumented
212 197 my $element_info = dclone( $self->{model}{element}{$element_name} );
213 197 my $config_class_name = $element_info->{config_class_name};
214  
215 Config::Model::Exception::Model->throw(
216 error => "create node '$element_name' error: " . "missing config class name parameter",
217 object => $self
218 197 ▶ ) unless defined $element_info->{config_class_name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $element_info->{"config_class_name"} 0 197 197
219  
220 my @args = (
221 config_class_name => $config_class_name,
222 instance => $self->{instance},
223 197 element_name => $element_name,
224 parent => $self,
225 container => $self,
226 );
227  
228 197 return $self->{element}{$element_name} = $self->load_node(@args);
229 }
230  
231 134 ▶sub create_warped_node ($self, $element_name, $check) {
Subroutine create_warped_node: called CC=1 SCAR=0.0
Pod undocumented
232  
233 134 my $element_info = dclone( $self->{model}{element}{$element_name} );
234  
235 my @args = (
236 instance => $self->{instance},
237 134 element_name => $element_name,
238 parent => $self,
239 check => $check,
240 container => $self,
241 );
242  
243 134 require Config::Model::WarpedNode;
244  
245 134 return $self->{element}{$element_name} =
246 Config::Model::WarpedNode->new( %$element_info, @args );
247 }
248  
249 3617 ▶sub create_leaf ($self, $element_name, $check) {
Subroutine create_leaf: called CC=3 SCAR=11.4
Pod undocumented
250  
251 3617 my $element_info = dclone( $self->{model}{element}{$element_name} );
252  
253 3617 delete $element_info->{type};
254 3617 ▶ my $leaf_class = delete $element_info->{class} || 'Config::Model::Value';
Condition100%2/2
delete $element_info->{'class'} || 'Config::Model::Value'
l!l
463571
MC/DC100%1/1
delete $element_info->{'class'} || 'Config::Model::Value'
delete $element_info->{'class'}
Truth table100%2/2
A
A= delete $element_info->{'class'}
Aresult
11
00
255  
256 3617 ▶ if ( not defined *{ $leaf_class . '::' } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined *{$leaf_class . '::';}) 0 3617 3617
257 0 my $file = $leaf_class . '.pm';
258 0 $file =~ s!::!/!g;
259 0 require $file;
260 }
261  
262 3617 $element_info->{container} = $element_info->{parent} = $self;
263 3617 $element_info->{element_name} = $element_name;
264 3617 $element_info->{instance} = $self->{instance};
265  
266 3617 return $self->{element}{$element_name} = $leaf_class->new(%$element_info);
267 }
268  
269 59 my %id_class_hash = (
270 hash => 'HashId',
271 list => 'ListId',
272 check_list => 'CheckList',
273 );
274  
275 598 ▶sub create_id ($self, $element_name, $check) {
Subroutine create_id: called CC=5 SCAR=16.1
Pod undocumented
276  
277 598 my $element_info = dclone( $self->{model}{element}{$element_name} );
278 598 my $type = delete $element_info->{type};
279  
280 598 ▶ Config::Model::Exception::Model->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 598 598
281 error => "create $type element '$element_name' error" . ": missing 'type' parameter",
282 object => $self
283 ) unless defined $type;
284  
285 croak "Undefined id_class for type '$type'"
286 598 ▶ unless defined $id_class_hash{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id_class_hash{$type} 0 598 598
287  
288 my $id_class = delete $element_info->{class}
289 598 ▶ || 'Config::Model::' . $id_class_hash{$type};
Condition100%2/2
delete $element_info->{'class'} || 'Config::Model::' . $id_class_hash{$type}
l!l
5593
MC/DC100%1/1
delete $element_info->{'class'} || 'Config::Model::' . $id_class_hash{$type}
delete $element_info->{'class'}
Truth table100%2/2
A
A= delete $element_info->{'class'}
Aresult
11
00
290  
291 598 ▶ if ( not defined *{ $id_class . '::' } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined *{$id_class . '::';}) 83 515 598
292 83 my $file = $id_class . '.pm';
293 83 $file =~ s!::!/!g;
294 83 require $file;
295 }
296  
297 598 $element_info->{container} = $element_info->{parent} = $self;
298 598 $element_info->{element_name} = $element_name;
299 598 $element_info->{instance} = $self->{instance};
300  
301 598 return $self->{element}{$element_name} = $id_class->new(%$element_info);
302 }
303  
304 # check validity of level and status declaration.
305 818 ▶sub check_properties ($self) {
Subroutine check_properties: called CC=9 SCAR=22.5
Pod undocumented
306 # a model should no longer contain attributes attached to
307 # an element (like description, level ...). There are copied here
308 # because Node needs them as hash or lists
309 818 foreach my $bad (qw/description summary level status/) {
310 die $self->config_class_name, ": illegal '$bad' parameter in model ",
311 "(Should be handled by Config::Model directly)\n"
312 3272 ▶ if defined $self->{model}{$bad};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"model"}{$bad} 0 3272 3272
313 }
314  
315 818 foreach my $elt_name ( @{ $self->{model}{element_list} } ) {
316  
317 5185 foreach my $prop (qw/summary description/) {
318 10370 my $info_to_move = delete $self->{model}{element}{$elt_name}{$prop};
319 10370 ▶ $self->{$prop}{$elt_name} = $info_to_move
Branch: 1 branch
BranchTrueFalseTotal
if defined $info_to_move 1965 8405 10370
320 if defined $info_to_move;
321 }
322  
323 5185 foreach my $prop ( keys %legal_properties ) {
324 my $prop_v
325 10370 ▶ = delete $self->{model}{element}{$elt_name}{$prop}
Condition66%2/3
delete $self->{"model"}{"element"}{$elt_name}{$prop} // get_default_property($prop)
l!l&&r!l&&!r
185101850
MC/DC0%0/2
delete $self->{"model"}{"element"}{$elt_name}{$prop} // get_default_property($prop)
delete $self->{"model"}{"element"}{$elt_name}{$prop} get_default_property($prop)
Truth table66%2/3
A // B
A= delete $self->{"model"}{"element"}{$elt_name}{$prop}B= get_default_property($prop)
ABresult
1X1
011
000
326 // get_default_property($prop) ;
327 10370 $self->{$prop}{$elt_name} = $prop_v;
328  
329 croak "Config class $self->{config_class_name} error: ",
330 0 "Unknown $prop: '$prop_v'. Expected ", join( " or ", keys %{ $self->{$prop} } )
331 10370 ▶ unless defined $legal_properties{$prop}{$prop_v};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $legal_properties{$prop}{$prop_v} 0 10370 10370
332 }
333 }
334 818 return;
335 }
336  
337 24404 ▶sub init ($self, @args) {
Subroutine init: called CC=4 SCAR=13.9
Pod undocumented
338 24404 ▶ return if $self->{initialized};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"initialized"} 23630 774 24404
339 774 $self->{initialized} = 1; # avoid recursions
340  
341 774 my $model = $self->{model};
342  
343 774 ▶ return unless defined $model->{rw_config};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $model->{"rw_config"} 676 98 774
344  
345 98 my $initial_load_backup = $self->instance->initial_load;
346 98 $self->instance->initial_load_start;
347  
348 $self->{backend_mgr} ||= Config::Model::BackendMgr->new(
349 # config_dir spec given by application info
350 config_dir => $self->instance->config_dir,
351 node => $self,
352 rw_config => $model->{rw_config}
353 98 ▶ );
Condition33%1/3
$self->{"backend_mgr"} ||= "Config::Model::BackendMgr"->new("config_dir", $self->instance->config_dir, "node", $self, "rw_config", $model->{"rw_config"})
l!l&&r!l&&!r
0980
MC/DC0%0/2
$self->{"backend_mgr"} ||= "Config::Model::BackendMgr"->new("config_dir", $self->instance->config_dir, "node", $self, "rw_config", $model->{"rw_config"})
$self->{"backend_mgr"} "Config::Model::BackendMgr"->new("config_dir", $self->instance->config_dir, "node", $self, "rw_config", $model->{"rw_config"})
Truth table33%1/3
A ||= B
A= $self->{"backend_mgr"}B= "Config::Model::BackendMgr"->new("config_dir", $self->instance->config_dir, "node", $self, "rw_config", $model->{"rw_config"})
ABresult
1X1
011
000
354  
355 98 $self->read_config_data( check => $self->read_check );
356 # setup auto_write
357 98 $self->backend_mgr->auto_write_init();
358  
359 98 $self->instance->initial_load($initial_load_backup);
360 98 return;
361 }
362  
363 98 ▶sub read_config_data ($self, %args) {
Subroutine read_config_data: called CC=5 SCAR=18.9
Pod undocumented
364 98 my $model = $self->{model};
365  
366 98 ▶ if ( $self->location and $args{config_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->location and $args{"config_file"}) 0 98 98
Condition66%2/3
$self->location and $args{"config_file"}
!ll&&!rl&&r
63350
MC/DC0%0/2
$self->location and $args{"config_file"}
$self->location $args{"config_file"}
Truth table66%2/3
A and B
A= $self->locationB= $args{"config_file"}
ABresult
0X0
100
111
367 0 die "read_config_data: cannot override config_file in non root node (",
368 $self->location, ")\n";
369 }
370  
371 # setup auto_read
372 # may use an overridden config file
373 return $self->backend_mgr->read_config_data(
374 check => $args{check},
375 config_file => $args{config_file} || $self->{config_file},
376 98 ▶ auto_create => $args{auto_create} || $self->instance->auto_create,
Condition50%3/6
$args{'config_file'} || $self->{'config_file'}
l!l&&r!l&&!r
0692
$args{'auto_create'} || $self->instance->auto_create
l!l&&r!l&&!r
0098
MC/DC50%1/2
$args{'config_file'} || $self->{'config_file'}
$args{'config_file'} $self->{'config_file'}
MC/DC0%0/2
$args{'auto_create'} || $self->instance->auto_create
$args{'auto_create'} $self->instance->auto_create
Truth table66%2/3
A || B
A= $args{'config_file'}B= $self->{'config_file'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $args{'auto_create'}B= $self->instance->auto_create
ABresult
1X1
011
000
377 );
378 }
379  
380 2050 ▶around notify_change => sub ($orig, $self, %args) {
Subroutine __ANON__: called CC=7 SCAR=19.5
381 2050 ▶ if ($change_logger->is_trace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($change_logger->is_trace) 111 1939 2050
382 111 ▶ my @with = map { "'$_' -> '". ($args{$_} // '<undef>') ."'" } sort keys %args;
Condition100%2/2
$args{$_} // "<undef>"
l!l
67567
MC/DC100%1/1
$args{$_} // "<undef>"
$args{$_}
Truth table100%2/2
A
A= $args{$_}
Aresult
11
00
383 111 $change_logger->trace("called for ", $self->name, " from ", join( ' ', caller ), " with ", join( ' ', @with ));
384 }
385 2050 ▶ return if $self->instance->initial_load and not $args{really};
Branch: 1 branch
BranchTrueFalseTotal
if $self->instance->initial_load and not $args{"really"} 54 1996 2050
Condition100%3/3
$self->instance->initial_load and not $args{"really"}
!ll&&!rl&&r
1992454
MC/DC100%2/2
$self->instance->initial_load and not $args{"really"}
$self->instance->initial_load not $args{"really"}
Truth table100%3/3
A and not(B)
A= $self->instance->initial_loadB= not $args{"really"}
ABresult
0X0
100
111
386  
387 1996 ▶ $logger->trace( "called while needs_write is ", $self->needs_save, " for ", $self->name )
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_trace 111 1885 1996
388 if $logger->is_trace;
389  
390 1996 ▶ if ( defined $self->backend_mgr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->backend_mgr) { } 54 1942 1996
391 54 $self->needs_save(1); # will trigger a save in config_file
392 54 $self->$orig( %args, needs_save => 0 );
393 }
394 else {
395 # save config_file will be done by a node above
396 1942 $self->$orig( %args, needs_save => 1 );
397 }
398 1996 return;
399 59 };
400  
401 19 ▶sub is_auto_write_for_type ($self, @args) {
Subroutine is_auto_write_for_type: called CC=2 SCAR=6.9
Pod undocumented
402 19 ▶ return 0 unless defined $self->backend_mgr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->backend_mgr 18 1 19
403 1 return $self->backend_mgr->is_auto_write_for_type(@args);
404 }
405  
406 21063 ▶sub name ($self) {
Subroutine name: called CC=2 SCAR=7.2
Pod documented
407 21063 ▶ return $self->location() || $self->config_class_name;
Condition66%2/3
$self->location || $self->config_class_name
l!l&&r!l&&!r
1191891450
MC/DC0%0/2
$self->location || $self->config_class_name
$self->location $self->config_class_name
Truth table66%2/3
A || B
A= $self->locationB= $self->config_class_name
ABresult
1X1
011
000
408 }
409  
410 583 ▶sub get_type {
Subroutine get_type: called CC=1 SCAR=0.0
Pod documented
411 583 return 'node';
412 }
413  
414 471 ▶sub get_cargo_type {
Subroutine get_cargo_type: called CC=1 SCAR=0.0
Pod undocumented
415 471 return 'node';
416 }
417  
418 # always true. this method is required so that WarpedNode and Node
419 # have a similar API.
420 0 ▶sub is_accessible {
Subroutine is_accessible: not called CC=1 SCAR=6.9
Pod undocumented
421 0 return 1;
422 }
423  
424 # should I autovivify this element: NO
425 4191 ▶sub has_element ($self, @args) {
Subroutine has_element: called CC=7 SCAR=19.5
Pod documented
426 4191 my %args = _resolve_arg_shortcut(\@args, 'name');
427 4191 my $name = $args{name};
428 4191 my $type = $args{type};
429 4191 ▶ my $autoadd = $args{autoadd} // 1;
Condition100%2/2
$args{"autoadd"} // 1
l!l
28581333
MC/DC100%1/1
$args{"autoadd"} // 1
$args{"autoadd"}
Truth table100%2/2
A
A= $args{"autoadd"}
Aresult
11
00
430  
431 4191 ▶ if ( not defined $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 4191 4191
432 0 Config::Model::Exception::Internal->throw(
433 object => $self,
434 info => "has_element: missing element name",
435 );
436 }
437  
438 4191 ▶ $self->accept_element($name) if $autoadd;
Branch: 1 branch
BranchTrueFalseTotal
if $autoadd 4093 98 4191
439 4191 ▶ return 0 unless defined $self->{model}{element}{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"model"}{"element"}{$name} 239 3952 4191
440 3952 ▶ return 1 unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 3950 2 3952
441 2 ▶ return $self->{model}{element}{$name}{type} eq $type ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'model'}{'element'}{$name}{'type'} eq $type ? : 1 1 2
442 }
443  
444 # should I autovivify this element: NO
445 0 ▶sub find_element ($self, $name, %args) {
Subroutine find_element: not called CC=8 SCAR=42.8
Pod documented
446 0 ▶ croak "find_element: missing element name" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
447  
448 # should be the case if people are using cme edit
449 0 ▶ return $name if defined $self->{model}{element}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"model"}{"element"}{$name} 0 0 0
450  
451 # look for a close element playing with cases;
452 0 ▶ if ( defined $args{case} and $args{case} eq 'any' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"case"} and $args{"case"} eq "any") 0 0 0
Condition0%0/3
defined $args{"case"} and $args{"case"} eq "any"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"case"} and $args{"case"} eq "any"
defined $args{"case"} $args{"case"} eq "any"
Truth table0%0/3
A and B
A= defined $args{"case"}B= $args{"case"} eq "any"
ABresult
0X0
100
111
453 0 foreach my $elt ( keys %{ $self->{model}{element} } ) {
454 0 ▶ return $elt if lc($elt) eq lc($name);
Branch: 1 branch
BranchTrueFalseTotal
if lc $elt eq lc $name 0 0 0
455 }
456 }
457  
458 # now look if the element can be accepted
459 0 $self->accept_element($name);
460 0 ▶ return $name if defined $self->{model}{element}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"model"}{"element"}{$name} 0 0 0
461  
462 0 return;
463 }
464  
465 0 ▶sub element_model ($self, $elt_name) {
Subroutine element_model: not called CC=1 SCAR=6.9
Pod documented
466 0 return $self->{model}{element}{ $elt_name };
467 }
468  
469 14675 ▶sub element_type ($self, $name) {
Subroutine element_type: called CC=5 SCAR=18.6
Pod documented
470 14675 ▶ croak "element_type: missing element name" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 14675 14675
471  
472 14675 ▶ my $element_info = $self->{model}{element}{$name} // $self-> _get_accepted_data($name);
Condition66%2/3
$self->{"model"}{"element"}{$name} // $self->_get_accepted_data($name)
l!l&&r!l&&!r
1467410
MC/DC0%0/2
$self->{"model"}{"element"}{$name} // $self->_get_accepted_data($name)
$self->{"model"}{"element"}{$name} $self->_get_accepted_data($name)
Truth table66%2/3
A // B
A= $self->{"model"}{"element"}{$name}B= $self->_get_accepted_data($name)
ABresult
1X1
011
000
473  
474 14675 ▶ Config::Model::Exception::UnknownElement->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $element_info 0 14675 14675
Condition0%0/2
$self->location || 'configuration root'
l!l
00
MC/DC0%0/1
$self->location || 'configuration root'
$self->location
Truth table0%0/2
A
A= $self->location
Aresult
11
00
475 object => $self,
476 function => 'element_type',
477 where => $self->location || 'configuration root',
478 element => $name,
479 ) unless defined $element_info;
480  
481 14675 return $element_info->{type};
482 }
483  
484 1490 ▶sub get_element_name {
Subroutine get_element_name: called CC=1 SCAR=0.0
Pod undocumented
485 1490 goto &get_element_names;
486 }
487  
488 1531 ▶sub get_element_names ($self, %args) {
Subroutine get_element_names: called CC=16 SCAR=28.2
Pod documented
489 1531 ▶ if (delete $args{for}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args{"for"}) 0 1531 1531
490 0 carp "get_element_names arg 'for' is deprecated";
491 }
492  
493 1531 my $type = $args{type}; # optional
494 1531 my $cargo_type = $args{cargo_type}; # optional
495  
496 1531 $self->init();
497  
498 1531 my @result;
499  
500 1531 my $info = $self->{model};
501 1531 my @element_list = @{ $self->{model}{element_list} };
502  
503 1531 ▶ if ($args{all}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"all"}) 29 1502 1531
504 29 my @res = grep { $self->{level}{$_} ne 'hidden' } @element_list;
505 29 ▶ return wantarray ? @res : "@res";
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 29 0 29
506 }
507  
508 # this is a bit convoluted, but the order of the returned element
509 # must respect the order of the elements declared in the model by
510 # the user
511 1502 foreach my $elt (@element_list) {
512  
513 # create element if they don't exist, this enables warp stuff
514 # to kick in
515 $self->create_element( name => $elt, check => $args{check} || 'yes' )
516 10631 ▶ unless defined $self->{element}{$elt};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"element"}{$elt} 3059 7572 10631
Condition100%2/2
$args{'check'} || 'yes'
l!l
2902157
MC/DC100%1/1
$args{'check'} || 'yes'
$args{'check'}
Truth table100%2/2
A
A= $args{'check'}
Aresult
11
00
517  
518 10631 ▶ next if $self->{level}{$elt} eq 'hidden';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"level"}{$elt} eq "hidden" 97 10534 10631
519  
520 10534 ▶ my $status = $self->{status}{$elt} || get_default_property('status');
Condition33%1/3
$self->{'status'}{$elt} || get_default_property('status')
l!l&&r!l&&!r
1053400
MC/DC0%0/2
$self->{'status'}{$elt} || get_default_property('status')
$self->{'status'}{$elt} get_default_property('status')
Truth table33%1/3
A || B
A= $self->{'status'}{$elt}B= get_default_property('status')
ABresult
1X1
011
000
521 10534 ▶ next if ( $status eq 'deprecated' or $status eq 'obsolete' );
Branch: 1 branch
BranchTrueFalseTotal
if $status eq "deprecated" or $status eq "obsolete" 9 10525 10534
Condition100%3/3
$status eq "deprecated" or $status eq "obsolete"
l!l&&r!l&&!r
7210525
MC/DC100%2/2
$status eq "deprecated" or $status eq "obsolete"
$status eq "deprecated" $status eq "obsolete"
Truth table100%3/3
A or B
A= $status eq "deprecated"B= $status eq "obsolete"
ABresult
1X1
011
000
522  
523 10525 my $elt_type = $self->{element}{$elt}->get_type;
524 10525 my $elt_cargo = $self->{element}{$elt}->get_cargo_type;
525 10525 ▶ if ( ( not defined $type or $type eq $elt_type )
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($type) || $type eq $elt_type and !defined($cargo_type) || $cargo_type eq $elt_cargo) 10399 126 10525
Condition66%6/9
!defined($type) || $type eq $elt_type and !defined($cargo_type) || $cargo_type eq $elt_cargo
!ll&&!rl&&r
012610399
not defined $type or $type eq $elt_type
l!l&&r!l&&!r
1052500
not defined $cargo_type or $cargo_type eq $elt_cargo
l!l&&r!l&&!r
1036336126
MC/DC50%2/4
!defined($type) || $type eq $elt_type and !defined($cargo_type) || $cargo_type eq $elt_cargo
not defined $type $type eq $elt_type not defined $cargo_type $cargo_type eq $elt_cargo
Truth table42%3/7
not(A) or B and not(C) or D
A= not defined $typeB= $type eq $elt_typeC= not defined $cargo_typeD= $cargo_type eq $elt_cargo
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
526 and ( not defined $cargo_type or $cargo_type eq $elt_cargo ) ) {
527 10399 push @result, $elt;
528 }
529 }
530  
531 1502 $logger->trace("got @result");
532  
533 1502 ▶ return wantarray ? @result : join( ' ', @result );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1501 1 1502
534 }
535  
536 2 ▶sub children ($self) {
Subroutine children: called CC=1 SCAR=0.0
Pod documented
537 2 return $self->get_element_names;
538 }
539  
540 239 ▶sub next_element ($self, %args) {
Subroutine next_element: called CC=10 SCAR=23.1
Pod documented
541 239 my $element = $args{name};
542  
543 239 my @elements = @{ $self->{model}{element_list} };
544 239 ▶ @elements = reverse @elements if $args{reverse};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"reverse"} 74 165 239
545  
546 # if element is empty, start from first element
547 239 ▶ my $found_elt = ( defined $element and $element ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $element && $element ? : 201 38 239
Condition100%3/3
defined $element and $element
!ll&&!rl&&r
371201
MC/DC100%2/2
defined $element and $element
defined $element $element
Truth table100%3/3
A and B
A= defined $elementB= $element
ABresult
0X0
100
111
548  
549 239 ▶ while ( my $name = shift @elements ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = shift @elements) 1046 36 1082
550 1046 ▶ if ($found_elt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_elt) 206 840 1046
551 return $name
552 if $self->is_element_available(
553 name => $name,
554 206 ▶ status => $args{status} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_element_available("name", $name, "status", $args{"status"}) 203 3 206
555 }
556 843 ▶ $found_elt = 1 if defined $element and $element eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $element and $element eq $name 201 642 843
Condition66%2/3
defined $element and $element eq $name
!ll&&!rl&&r
0642201
MC/DC50%1/2
defined $element and $element eq $name
defined $element $element eq $name
Truth table66%2/3
A and B
A= defined $elementB= $element eq $name
ABresult
0X0
100
111
557 }
558  
559 36 ▶ croak "next_element: element $element is unknown. Expected @elements"
Branch: 1 branch
BranchTrueFalseTotal
unless $found_elt 0 36 36
560 unless $found_elt;
561 36 return;
562 }
563  
564 3 ▶sub previous_element ($self, @args) {
Subroutine previous_element: called CC=1 SCAR=0.0
Pod documented
565 3 return $self->next_element( @args, reverse => 1 );
566 }
567  
568 31649 ▶sub get_element_property ($self, %args) {
Subroutine get_element_property: called CC=2 SCAR=8.1
Pod documented
569 31649 my ( $prop, $elt ) = $self->check_property_args( 'get_element_property', %args );
570  
571 31649 ▶ return $self->{$prop}{$elt} || get_default_property($prop);
Condition33%1/3
$self->{$prop}{$elt} || get_default_property($prop)
l!l&&r!l&&!r
3164900
MC/DC0%0/2
$self->{$prop}{$elt} || get_default_property($prop)
$self->{$prop}{$elt} get_default_property($prop)
Truth table33%1/3
A || B
A= $self->{$prop}{$elt}B= get_default_property($prop)
ABresult
1X1
011
000
572 }
573  
574 251 ▶sub set_element_property ($self, %args) {
Subroutine set_element_property: called CC=2 SCAR=7.0
Pod documented
575 251 my ( $prop, $elt ) = $self->check_property_args( 'set_element_property', %args );
576  
577 my $new_value = $args{value}
578 251 ▶ || croak "set_element_property:: missing 'value' parameter";
Condition50%1/2
$args{'value'} || croak(q[set_element_property:: missing 'value' parameter])
l!l
2510
MC/DC0%0/1
$args{'value'} || croak(q[set_element_property:: missing 'value' parameter])
$args{'value'}
Truth table50%1/2
A
A= $args{'value'}
Aresult
11
00
579  
580 251 $logger->debug( "Node ", $self->name, ": set $elt property $prop to $new_value" );
581  
582 251 return $self->{$prop}{$elt} = $new_value;
583 }
584  
585 734 ▶sub reset_element_property ($self, %args) {
Subroutine reset_element_property: called CC=1 SCAR=0.0
Pod documented
586 734 my ( $prop, $elt ) = $self->check_property_args( 'reset_element_property', %args );
587  
588 my $original_value = $self->{config_model}->get_element_property(
589 class => $self->{config_class_name},
590 734 %args
591 );
592  
593 734 $logger->debug( "Node ", $self->name, ": reset $elt property $prop to $original_value" );
594  
595 734 return $self->{$prop}{$elt} = $original_value;
596 }
597  
598 # internal: called by the property methods to check their arguments
599 32634 ▶sub check_property_args ($self, $method_name, %args){
Subroutine check_property_args: called CC=4 SCAR=14.6
Pod undocumented
600 my $elt = $args{element}
601 32634 ▶ || croak "$method_name: missing 'element' parameter";
Condition50%1/2
$args{'element'} || croak("${method_name}: missing 'element' parameter")
l!l
326340
MC/DC0%0/1
$args{'element'} || croak("${method_name}: missing 'element' parameter")
$args{'element'}
Truth table50%1/2
A
A= $args{'element'}
Aresult
11
00
602 my $prop = $args{property}
603 32634 ▶ || croak "$method_name: missing 'property' parameter";
Condition50%1/2
$args{'property'} || croak("${method_name}: missing 'property' parameter")
l!l
326340
MC/DC0%0/1
$args{'property'} || croak("${method_name}: missing 'property' parameter")
$args{'property'}
Truth table50%1/2
A
A= $args{'property'}
Aresult
11
00
604  
605 32634 my $prop_values = $legal_properties{$prop};
606 32634 ▶ confess "Unknown property in $method_name: $prop, expected status or ", "level"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prop_values 0 32634 32634
607 unless defined $prop_values;
608  
609 32634 return ( $prop, $elt );
610 }
611  
612 22621 ▶sub fetch_element ($self, @args) {
Subroutine fetch_element: called CC=17 SCAR=28.6
Pod documented
613 22621 my %args = _resolve_arg_shortcut(\@args, 'name');
614 22621 my $element_name = $args{name};
615  
616 22621 ▶ Config::Model::Exception::Internal->throw( error => "fetch_element: missing name" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $element_name 0 22621 22621
617 unless defined $element_name;
618  
619 22621 my $check = $self->_check_check( $args{check} );
620 22621 ▶ my $accept_hidden = $args{accept_hidden} || 0;
Condition100%2/2
$args{'accept_hidden'} || 0
l!l
567516946
MC/DC100%1/1
$args{'accept_hidden'} || 0
$args{'accept_hidden'}
Truth table100%2/2
A
A= $args{'accept_hidden'}
Aresult
11
00
621 22621 ▶ my $autoadd = $args{autoadd} // 1;
Condition100%2/2
$args{"autoadd"} // 1
l!l
262519996
MC/DC100%1/1
$args{"autoadd"} // 1
$args{"autoadd"}
Truth table100%2/2
A
A= $args{"autoadd"}
Aresult
11
00
622  
623 22621 $self->init();
624  
625 22621 my $model = $self->{model};
626  
627 # retrieve element (and auto-vivify if needed)
628 22621 ▶ if ( not defined $self->{element}{$element_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"element"}{$element_name}) 1489 21132 22621
629  
630 # We also need to check if element name is matched by any of 'accept' parameters
631 1489 ▶ $self->accept_element($element_name) if $autoadd;
Branch: 1 branch
BranchTrueFalseTotal
if $autoadd 1488 1 1489
632 1489 ▶ $self->create_element( name => $element_name, check => $check, autoadd => $autoadd ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->create_element("name", $element_name, "check", $check, "autoadd", $autoadd) or return 1480 1 1481
633 }
634  
635 # check level
636 22612 my $element_level = $self->get_element_property(
637 property => 'level',
638 element => $element_name
639 );
640  
641 22612 ▶ if ( $element_level eq 'hidden' and not $accept_hidden ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element_level eq "hidden" and not $accept_hidden) 4 22608 22612
Condition100%3/3
$element_level eq "hidden" and not $accept_hidden
!ll&&!rl&&r
22588204
MC/DC100%2/2
$element_level eq "hidden" and not $accept_hidden
$element_level eq "hidden" not $accept_hidden
Truth table100%3/3
A and not(B)
A= $element_level eq "hidden"B= not $accept_hidden
ABresult
0X0
100
111
642 4 ▶ return 0 if ( $check eq 'no' or $check eq 'skip' );
Branch: 1 branch
BranchTrueFalseTotal
if $check eq "no" or $check eq "skip" 0 4 4
Condition33%1/3
$check eq "no" or $check eq "skip"
l!l&&r!l&&!r
004
MC/DC0%0/2
$check eq "no" or $check eq "skip"
$check eq "no" $check eq "skip"
Truth table33%1/3
A or B
A= $check eq "no"B= $check eq "skip"
ABresult
1X1
011
000
643 4 Config::Model::Exception::UnavailableElement->throw(
644 object => $self,
645 element => $element_name,
646 info => 'hidden element',
647 );
648 }
649  
650 # check status
651 22608 ▶ if ( $self->{status}{$element_name} eq 'obsolete' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"status"}{$element_name} eq "obsolete") 1 22607 22608
652  
653 # obsolete is a status not very different from a missing
654 # item. The only difference is that user will get more
655 # information
656 1 ▶ return 0 if ( $check eq 'no' or $check eq 'skip' );
Branch: 1 branch
BranchTrueFalseTotal
if $check eq "no" or $check eq "skip" 0 1 1
Condition33%1/3
$check eq "no" or $check eq "skip"
l!l&&r!l&&!r
001
MC/DC0%0/2
$check eq "no" or $check eq "skip"
$check eq "no" $check eq "skip"
Truth table33%1/3
A or B
A= $check eq "no"B= $check eq "skip"
ABresult
1X1
011
000
657 1 Config::Model::Exception::ObsoleteElement->throw(
658 object => $self,
659 element => $element_name,
660 );
661 }
662  
663 # do not warn when when is skip or "no"
664 22607 ▶ if ($self->{status}{$element_name} eq 'deprecated' and $check eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"status"}{$element_name} eq "deprecated" and $check eq "yes") 7 22600 22607
Condition100%3/3
$self->{"status"}{$element_name} eq "deprecated" and $check eq "yes"
!ll&&!rl&&r
22564367
MC/DC100%2/2
$self->{"status"}{$element_name} eq "deprecated" and $check eq "yes"
$self->{"status"}{$element_name} eq "deprecated" $check eq "yes"
Truth table100%3/3
A and B
A= $self->{"status"}{$element_name} eq "deprecated"B= $check eq "yes"
ABresult
0X0
100
111
665 # FIXME elaborate more ? or include parameter description ??
666 7 my $msg = "Element '$element_name' of node '". $self->name. "' is deprecated";
667 7 ▶ if (not $self->was_element_warned($element_name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->was_element_warned($element_name)) 5 2 7
668 5 $user_logger->warn($msg);
669 5 $self->warn_element_done($element_name,1);
670 }
671 # this will also force a rewrite of the file even if no other
672 # semantic change was done
673 $self->notify_change(
674 7 note => 'dropping deprecated parameter',
675 path => $self->location . ' ' . $element_name,
676 really => 1,
677 );
678 }
679  
680 22607 return $self->fetch_element_no_check($element_name);
681 }
682  
683 22607 ▶sub fetch_element_no_check ($self, $element_name) {
Subroutine fetch_element_no_check: called CC=1 SCAR=0.0
Pod undocumented
684 22607 return $self->{element}{$element_name};
685 }
686  
687 873 ▶sub fetch_element_value ($self, @args) {
Subroutine fetch_element_value: called CC=3 SCAR=11.8
Pod documented
688 873 ▶ my %args = @args > 1 ? @args : ( name => $args[0] );
Branch: 1 branch
BranchTrueFalseTotal
@args > 1 ? : 0 873 873
689 873 my $element_name = $args{name};
690 873 my $check = $self->_check_check( $args{check} );
691  
692 873 ▶ if ( $self->element_type($element_name) ne 'leaf' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->element_type($element_name) ne "leaf") 0 873 873
693 0 Config::Model::Exception::WrongType->throw(
694 object => $self->fetch_element($element_name),
695 function => 'fetch_element_value',
696 got_type => $self->element_type($element_name),
697 expected_type => 'leaf',
698 );
699 }
700  
701 873 return $self->fetch_element(%args)->fetch( check => $check );
702 }
703  
704 2 ▶sub store_element_value ($self, @args) {
Subroutine store_element_value: called CC=1 SCAR=0.0
Pod documented
705 2 my %args = _resolve_arg_shortcut(\@args, 'name', 'value');
706  
707 2 return $self->fetch_element(%args)->store(%args);
708 }
709  
710 4409 ▶sub is_element_available ($self, @args) {
Subroutine is_element_available: called CC=7 SCAR=19.8
Pod documented
711 4409 my ( $elt_name, $status ) = ( undef, 'deprecated' );
712 4409 ▶ if ( @args == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1) { } 6 4403 4409
713 6 $elt_name = $args[0];
714 }
715 else {
716 4403 my %args = @args;
717 4403 $elt_name = $args{name};
718 4403 ▶ $status = $args{status} if defined $args{status};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"status"} 200 4203 4403
719 }
720  
721 4409 ▶ croak "is_element_available: missing name parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elt_name 0 4409 4409
722 unless defined $elt_name;
723  
724 # force the warp to be done (if possible) so the catalog name
725 # is updated
726 # retrieve element (and auto-vivify if needed)
727 4409 my $element = $self->fetch_element(
728 name => $elt_name,
729 # check => 'no' causes problem because elements below (when
730 # loaded by another backend also below) are initialised with
731 # check 'no'. Deprecated elements are loaded but changes are
732 # not notified because of check/no.
733 check => 'skip',
734 accept_hidden => 1
735 );
736  
737 4409 my $element_level = $self->get_element_property(
738 property => 'level',
739 element => $elt_name
740 );
741  
742 4409 ▶ if ( $element_level eq 'hidden' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element_level eq "hidden") 11 4398 4409
743 11 $logger->trace("element $elt_name is level hidden -> return 0");
744 11 return 0;
745 }
746  
747 4398 my $element_status = $self->get_element_property(
748 property => 'status',
749 element => $elt_name
750 );
751  
752 4398 ▶ if ( $element_status ne 'standard' and $element_status ne $status ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element_status ne "standard" and $element_status ne $status) 0 4398 4398
Condition66%2/3
$element_status ne "standard" and $element_status ne $status
!ll&&!rl&&r
4380180
MC/DC0%0/2
$element_status ne "standard" and $element_status ne $status
$element_status ne "standard" $element_status ne $status
Truth table66%2/3
A and B
A= $element_status ne "standard"B= $element_status ne $status
ABresult
0X0
100
111
753 0 $logger->trace("element $elt_name is status $element_status -> return 0");
754 0 return 0;
755 }
756  
757 4398 return 1;
758 }
759  
760 5581 ▶sub accept_element ($self, $name) {
Subroutine accept_element: called CC=3 SCAR=11.0
Pod documented
761  
762 5581 my $model_data = $self->{model}{element};
763  
764 5581 ▶ return $model_data->{$name} if defined $model_data->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $model_data->{$name} 5351 230 5581
765  
766 230 my $acc = $self-> _get_accepted_data($name);
767  
768 230 ▶ return $self->reset_accepted_element_model( $name, $acc ) if $acc;
Branch: 1 branch
BranchTrueFalseTotal
if $acc 29 201 230
769  
770 201 return;
771 }
772  
773 # return accepted model data or undef
774 231 ▶sub _get_accepted_data ($self, $candidate) {
Subroutine _get_accepted_data: called CC=8 SCAR=20.9
775  
776 231 ▶ return unless defined $self->{model}{accept};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"model"}{"accept"} 0 231 231
777  
778 231 eval {require Text::Levenshtein::Damerau} ;
779 231 my $has_tld = ! $@ ;
780  
781 231 foreach my $accept_name ( @{ $self->{model}{accept_list} } ) {
782 220 my $accept_regexp = $self->{model}{accept}{$accept_name}{pattern};
783 220 ▶ next unless $candidate =~ /^$accept_regexp$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $candidate =~ /^$accept_regexp$/u 190 30 220
784 30 my $element_list = $self->{original_model}{element_list} ;
785  
786 30 ▶ if ($has_tld and $element_list and @$element_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_tld and $element_list and @$element_list) 18 12 30
Condition50%3/6
$has_tld and $element_list and @$element_list
!ll&&!rl&&r
01218
$has_tld and $element_list
!ll&&!rl&&r
0030
MC/DC33%1/3
$has_tld and $element_list and @$element_list
$has_tld $element_list @$element_list
Truth table50%2/4
A and B and C
A= $has_tldB= $element_listC= @$element_list
ABCresult
0XX0
10X0
1100
1111
787 18 my $tld = Text::Levenshtein::Damerau->new($candidate);
788 18 my $tld_arg = {list => $element_list };
789 18 my $dist = $tld->dld_best_distance($tld_arg);
790 18 ▶ if ($dist < 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist < 3) 4 14 18
791 4 my $best = $tld->dld_best_match($tld_arg);
792 4 $user_logger->warn(
793 "Warning: ".$self->location
794 ." '$candidate' is confusingly close to '$best' (edit distance is $dist)."
795 ." Is there a typo ?"
796 );
797 }
798  
799 }
800  
801 30 $logger->info("$candidate parameter accepted with $accept_name accept rule");
802  
803 # shallow clone
804 30 my %accepted_data = $self->{model}{accept}{$accept_name}->%*;
805 30 delete $accepted_data{pattern};
806  
807 30 return \%accepted_data;
808 }
809  
810 201 return ;
811 }
812  
813 5 ▶sub accept_regexp ($self) {
Subroutine accept_regexp: called CC=1 SCAR=0.0
Pod documented
814 5 return map {$self->{model}{accept}{$_}{pattern}} $self->{model}{accept_list}->@*;
815 }
816  
817 29 ▶sub reset_accepted_element_model ($self, $element_name, $accept_model) {
Subroutine reset_accepted_element_model: called CC=5 SCAR=16.1
Pod undocumented
818  
819 29 my $model = dclone $accept_model ;
820 29 my $accept_after = delete $model->{accept_after};
821  
822 29 foreach my $info_to_move (qw/description summary/) {
823 58 my $moved_data = delete $model->{$info_to_move};
824 58 ▶ next unless defined $moved_data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $moved_data 54 4 58
825 4 $self->{$info_to_move}{$element_name} = $moved_data;
826 }
827  
828 29 foreach my $info_to_move (qw/level status/) {
829 58 $self->reset_element_property(
830 element => $element_name,
831 property => $info_to_move
832 );
833 }
834  
835 29 $self->{model}{element}{$element_name} = $model;
836  
837 #add to element list...
838 29 ▶ if ($accept_after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accept_after) { } 3 26 29
839 3 insert_after_string( $accept_after, $element_name, @{ $self->{model}{element_list} } );
840 }
841 else {
842 26 push @{ $self->{model}{element_list} }, $element_name;
843 }
844  
845 29 return ($model);
846 }
847  
848 0 ▶sub element_exists {
Subroutine element_exists: not called CC=2 SCAR=17.9
Pod documented
849 0 my $self = shift;
850 0 my $element_name = shift;
851  
852 0 ▶ return defined $self->{model}{element}{$element_name} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'model'}{'element'}{$element_name} ? : 0 0 0
853 }
854  
855 474 ▶sub is_element_defined ($self, $elt_name) {
Subroutine is_element_defined: called CC=1 SCAR=0.0
Pod documented
856 474 return defined $self->{element}{ $elt_name };
857 }
858  
859 7 ▶sub get ($self, @args) {
Subroutine get: called CC=7 SCAR=19.5
Pod documented
860 7 my %args = _resolve_arg_shortcut(\@args, 'path');
861 7 my $path = delete $args{path};
862 7 ▶ my $get_obj = delete $args{get_obj} || 0;
Condition100%2/2
delete $args{'get_obj'} || 0
l!l
25
MC/DC100%1/1
delete $args{'get_obj'} || 0
delete $args{'get_obj'}
Truth table100%2/2
A
A= delete $args{'get_obj'}
Aresult
11
00
863 7 $path =~ s!^/!!;
864 7 ▶ return $self unless length($path);
Branch: 1 branch
BranchTrueFalseTotal
unless length $path 0 7 7
865 7 my ( $item, $new_path ) = split m!/!, $path, 2;
866 7 $logger->trace("get: path $path, item $item");
867 7 my $elt = $self->fetch_element( name => $item, %args );
868  
869 7 ▶ return unless defined $elt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elt 1 6 7
870 6 ▶ return $elt if ( ( $elt->get_type ne 'leaf' or $get_obj ) and not defined $new_path );
Branch: 1 branch
BranchTrueFalseTotal
if $elt->get_type ne "leaf" || $get_obj and not defined $new_path 1 5 6
Condition100%6/6
$elt->get_type ne "leaf" || $get_obj and not defined $new_path
!ll&&!rl&&r
231
$elt->get_type ne "leaf" or $get_obj
l!l&&r!l&&!r
312
MC/DC33%1/3
$elt->get_type ne "leaf" || $get_obj and not defined $new_path
$elt->get_type ne "leaf" $get_obj not defined $new_path
Truth table60%3/5
A or B and not(C)
A= $elt->get_type ne "leaf"B= $get_objC= not defined $new_path
ABCresult
00X0
1X00
0100
1X11
0111
871 5 return $elt->get( path => $new_path, get_obj => $get_obj, %args );
872 }
873  
874 2 ▶sub set ($self, $path, @args) {
Subroutine set: called CC=2 SCAR=7.4
Pod documented
875 2 $path =~ s!^/!!;
876 2 my ( $item, $new_path ) = split m!/!, $path, 2;
877 2 ▶ if ( $item =~ /([\w\-]+)\[(\d+)\]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /([\w\-]+)\[(\d+)\]/u) { } 0 2 2
878 0 return $self->fetch_element($1)->fetch_with_id($2)->set( $new_path, @args );
879 }
880 else {
881 2 return $self->fetch_element($item)->set( $new_path, @args );
882 }
883 }
884  
885 438 ▶sub load ($self, @args) {
Subroutine load: called CC=3 SCAR=12.3
Pod documented
886 438 my $loader = Config::Model::Loader->new( start_node => $self );
887  
888 438 my %args = _resolve_arg_shortcut(\@args, 'steps');
889 438 ▶ if ( defined $args{step} || defined $args{steps}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"step"} or defined $args{"steps"}) 438 0 438
Condition66%2/3
defined $args{"step"} or defined $args{"steps"}
l!l&&r!l&&!r
2152230
MC/DC0%0/2
defined $args{"step"} or defined $args{"steps"}
defined $args{"step"} defined $args{"steps"}
Truth table66%2/3
A or B
A= defined $args{"step"}B= defined $args{"steps"}
ABresult
1X1
011
000
890 438 return $loader->load( %args );
891 }
892 Config::Model::Exception::Load->throw(
893 0 object => $self,
894 message => "load called with no 'steps' parameter",
895 );
896 0 return;
897 }
898  
899 109 ▶sub load_data ($self, @args) {
Subroutine load_data: called CC=19 SCAR=37.6
Pod documented
900 109 my %args = _resolve_arg_shortcut(\@args, 'data');
901  
902 109 my $raw_perl_data = delete $args{data};
903 109 my $check = $self->_check_check( $args{check} );
904  
905 109 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $raw_perl_data or ref $raw_perl_data ne "HASH") 0 109 109
Condition33%1/3
not defined $raw_perl_data or ref $raw_perl_data ne "HASH"
l!l&&r!l&&!r
00109
MC/DC0%0/2
not defined $raw_perl_data or ref $raw_perl_data ne "HASH"
not defined $raw_perl_data ref $raw_perl_data ne "HASH"
Truth table33%1/3
not(A) or B
A= not defined $raw_perl_dataB= ref $raw_perl_data ne "HASH"
ABresult
1X1
011
000
906 not defined $raw_perl_data
907 or (
908 ref($raw_perl_data) ne 'HASH'
909  
910 #and not $raw_perl_data->isa( 'HASH' )
911 )
912 ) {
913 0 ▶ Config::Model::Exception::LoadData->throw(
Branch: 1 branch
BranchTrueFalseTotal
if $check eq "yes" 0 0 0
914 object => $self,
915 message => "load_data called with non hash ref arg",
916 wrong_data => $raw_perl_data,
917 ) if $check eq 'yes';
918 0 return;
919 }
920  
921 109 my $perl_data = dclone $raw_perl_data ;
922  
923 109 $logger->info(
924 "Node load_data (",
925 $self->location,
926 ") will load elt ",
927 join( ' ', sort keys %$perl_data ) );
928  
929 109 my $has_stored = 0;
930 # data must be loaded according to the element order defined by
931 # the model. This will not load not yet accepted parameters
932 109 foreach my $elt ( @{ $self->{model}{element_list} } ) {
933 433 $logger->trace("check element $elt");
934 433 ▶ next unless defined $perl_data->{$elt};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $perl_data->{$elt} 237 196 433
935  
936 196 ▶ if ( $self->is_element_available( name => $elt )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_element_available('name', $elt) or $check eq 'no') { } 196 0 196
elsif ($check eq 'skip') { } 0 0 0
Condition33%1/3
$self->is_element_available("name", $elt) or $check eq "no"
l!l&&r!l&&!r
19600
MC/DC0%0/2
$self->is_element_available("name", $elt) or $check eq "no"
$self->is_element_available("name", $elt) $check eq "no"
Truth table33%1/3
A or B
A= $self->is_element_available("name", $elt)B= $check eq "no"
ABresult
1X1
011
000
937 or $check eq 'no' ) {
938 196 ▶ if ( $logger->is_trace ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger->is_trace) 2 194 196
939 2 ▶ my $v = defined $perl_data->{$elt} ? $perl_data->{$elt} : '<undef>';
Branch: 1 branch
BranchTrueFalseTotal
defined $perl_data->{$elt} ? : 2 0 2
940 2 $logger->trace("Node load_data for element $elt -> $v");
941 }
942 196 my $obj = $self->fetch_element(
943 name => $elt,
944 check => $check
945 );
946  
947 196 ▶ if ($obj) {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj) { } 196 0 196
elsif (defined $obj) { } 0 0 0
948 196 $has_stored += $obj->load_data( %args, data => delete $perl_data->{$elt} );
949 }
950 elsif ( defined $obj ) {
951  
952 # skip hidden elements and trash corresponding data
953 0 $logger->trace("Node load_data drop element $elt");
954 0 delete $perl_data->{$elt};
955 }
956  
957 }
958 elsif ( $check eq 'skip' ) {
959 0 $logger->trace("Node load_data skips element $elt");
960 }
961 else {
962 Config::Model::Exception::LoadData->throw(
963 message => "load_data: tried to load hidden " . "element '$elt' with",
964 0 wrong_data => $perl_data->{$elt},
965 object => $self,
966 );
967 }
968 }
969  
970 # Load elements matched by accept parameter
971 109 ▶ if ( defined $self->{model}{accept} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"model"}{"accept"}) 109 0 109
972  
973 # Now, $perl_data contains all elements not yet parsed
974 # sort is required to have a predictable order of accepted elements
975 109 foreach my $elt ( sort keys %$perl_data ) {
976  
977 #load value
978 #TODO: annotations
979 12 my $obj = $self->fetch_element( name => $elt, check => $check );
980 12 ▶ next unless $obj; # in cas of known but unavailable elements
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 12 12
981 12 $logger->info("Node load_data: accepting element $elt");
982 12 ▶ $has_stored += $obj->load_data( %args, data => delete $perl_data->{$elt} ) if defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj 12 0 12
983 }
984 }
985  
986 109 ▶ if ( %$perl_data and $check eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$perl_data and $check eq "yes") 0 109 109
Condition33%1/3
%$perl_data and $check eq "yes"
!ll&&!rl&&r
10900
MC/DC0%0/2
%$perl_data and $check eq "yes"
%$perl_data $check eq "yes"
Truth table33%1/3
A and B
A= %$perl_dataB= $check eq "yes"
ABresult
0X0
100
111
987 Config::Model::Exception::LoadData->throw(
988 message => "load_data: unknown elements (expected "
989 0 . join( ' ', @{ $self->{model}{element_list} } ) . ") ",
990 wrong_data => $perl_data,
991 object => $self,
992 );
993 }
994 109 return !! $has_stored;
995 }
996  
997 154 ▶sub dump_tree ($self, %args) {
Subroutine dump_tree: called CC=4 SCAR=17.2
Pod documented
998 154 $self->init();
999 154 ▶ my $full = delete $args{full_dump} || 0;
Condition50%1/2
delete $args{'full_dump'} || 0
l!l
0154
MC/DC0%0/1
delete $args{'full_dump'} || 0
delete $args{'full_dump'}
Truth table50%1/2
A
A= delete $args{'full_dump'}
Aresult
11
00
1000 154 ▶ if ($full) {
Branch: 1 branch
BranchTrueFalseTotal
if ($full) 0 154 154
1001 0 carp "dump_tree: full_dump parameter is deprecated. Please use 'mode => user' instead";
1002 0 ▶ $args{mode} //= 'user';
Condition0%0/2
$args{"mode"} //= "user"
l!l
00
MC/DC0%0/1
$args{"mode"} //= "user"
$args{"mode"}
Truth table0%0/2
A
A= $args{"mode"}
Aresult
11
00
1003 }
1004 154 my $dumper = Config::Model::Dumper->new;
1005 154 return $dumper->dump_tree( node => $self, %args );
1006 }
1007  
1008 0 ▶sub migrate ($self, @args) {
Subroutine migrate: not called CC=1 SCAR=6.9
Pod documented
1009 0 $self->init();
1010 0 Config::Model::Dumper->new->dump_tree( node => $self, mode => 'full', @args );
1011  
1012 0 return $self->needs_save;
1013 }
1014  
1015 9 ▶sub describe ($self, @args) {
Subroutine describe: called CC=1 SCAR=0.0
Pod documented
1016 9 $self->init();
1017  
1018 9 my $descriptor = Config::Model::Describe->new;
1019 9 return $descriptor->describe( node => $self, @args );
1020 }
1021  
1022 1 ▶sub report ($self, @args) {
Subroutine report: called CC=1 SCAR=0.0
Pod documented
1023 1 $self->init();
1024 1 my $reporter = Config::Model::Report->new;
1025 1 return $reporter->report( node => $self );
1026 }
1027  
1028 1 ▶sub audit ($self, @args) {
Subroutine audit: called CC=1 SCAR=0.0
Pod documented
1029 1 $self->init();
1030 1 my $reporter = Config::Model::Report->new;
1031 1 return $reporter->report( node => $self, audit => 1 );
1032 }
1033  
1034 33 ▶sub copy_from ($self, @args) {
Subroutine copy_from: called CC=3 SCAR=11.0
Pod documented
1035 33 my %args = _resolve_arg_shortcut(\@args, 'from');
1036 33 ▶ my $from = $args{from} || croak "copy_from: missing from argument";
Condition50%1/2
$args{'from'} || croak('copy_from: missing from argument')
l!l
330
MC/DC0%0/1
$args{'from'} || croak('copy_from: missing from argument')
$args{'from'}
Truth table50%1/2
A
A= $args{'from'}
Aresult
11
00
1037 33 ▶ my $check = $args{check} || 'yes';
Condition100%2/2
$args{'check'} || 'yes'
l!l
267
MC/DC100%1/1
$args{'check'} || 'yes'
$args{'check'}
Truth table100%2/2
A
A= $args{'check'}
Aresult
11
00
1038 33 $logger->debug( "node " . $self->location . " copy from " . $from->location );
1039 33 my $dump = $from->dump_tree( check => 'no' );
1040 33 return $self->load( step => $dump, check => $check );
1041 }
1042  
1043 # TODO: need Pod::Text attribute -> move that to a role ?
1044 # to translate Pod description to plain text when help is displayed
1045 124 ▶sub get_help ($self, $tag = '', $elt_name = '') {
Subroutine get_help: called CC=9 SCAR=22.2
Pod documented
1046 124 ▶ if ($elt_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt_name) 79 45 124
1047 79 ▶ if ( $tag !~ /^(summary|description)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tag =~ /^(summary|description)$/u) 0 79 79
1048 0 croak "get_help: wrong argument $tag, expected ", "'description' or 'summary'";
1049 }
1050  
1051 79 ▶ return $self->{$tag}{$elt_name} // '';
Condition100%2/2
$self->{$tag}{$elt_name} // ""
l!l
772
MC/DC100%1/1
$self->{$tag}{$elt_name} // ""
$self->{$tag}{$elt_name}
Truth table100%2/2
A
A= $self->{$tag}{$elt_name}
Aresult
11
00
1052 }
1053 45 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) 44 1 45
1054 44 ▶ return $self->{description}{ $tag } // '';
Condition100%2/2
$self->{"description"}{$tag} // ""
l!l
440
MC/DC100%1/1
$self->{"description"}{$tag} // ""
$self->{"description"}{$tag}
Truth table100%2/2
A
A= $self->{"description"}{$tag}
Aresult
11
00
1055 }
1056 1 ▶ return $self->{model}{class_description} // '';
Condition50%1/2
$self->{"model"}{"class_description"} // ""
l!l
10
MC/DC0%0/1
$self->{"model"}{"class_description"} // ""
$self->{"model"}{"class_description"}
Truth table50%1/2
A
A= $self->{"model"}{"class_description"}
Aresult
11
00
1057 }
1058  
1059 2 ▶sub get_info ($self) {
Subroutine get_info: called CC=2 SCAR=6.9
Pod documented
1060 2 my @items = ( 'type: ' . $self->get_type, 'class name: ' . $self->config_class_name, );
1061  
1062 2 my @rexp = $self->accept_regexp;
1063 2 ▶ if (@rexp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rexp) 1 1 2
1064 1 push @items, 'accept: /^' . join( '$/, /^', @rexp ) . '$/';
1065 }
1066  
1067 2 return @items;
1068 }
1069  
1070 9 ▶sub tree_searcher ($self, @args){
Subroutine tree_searcher: called CC=1 SCAR=0.0
Pod documented
1071 9 return Config::Model::TreeSearcher->new( node => $self, @args );
1072 }
1073  
1074 8 ▶sub apply_fixes ($self, $filter='' ) {
Subroutine apply_fixes: called CC=2 SCAR=6.9
Pod documented
1075 # define leaf call back
1076 156 ▶ my $do_apply = sub ($name) {
Subroutine __ANON__: called CC=2 SCAR=6.9
1077 156 ▶ return $filter ? $name =~ /$filter/ : 1;
Branch: 1 branch
BranchTrueFalseTotal
$filter ? : 45 111 156
1078 8 };
1079  
1080 141 ▶ my $fix_leaf = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1081 141 my ( $scanner, $data_ref, $node, $element_name, $index, $leaf_object ) = @_;
1082 141 ▶ $leaf_object->apply_fixes if $do_apply->($element_name);
Branch: 1 branch
BranchTrueFalseTotal
if &$do_apply($element_name) 105 36 141
1083 8 };
1084  
1085 3 ▶ my $fix_hash = sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
1086 3 my ( $scanner, $data_r, $node, $element, @keys ) = @_;
1087  
1088 3 ▶ return unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 0 3 3
1089  
1090 # leaves must be fixed before the hash, hence the
1091 # calls to scan_hash before apply_fixes
1092 3 map { $scanner->scan_hash( $data_r, $node, $element, $_ ) } @keys;
1093  
1094 3 ▶ $node->fetch_element($element)->apply_fixes if $do_apply->($element);
Branch: 1 branch
BranchTrueFalseTotal
if &$do_apply($element) 3 0 3
1095 8 };
1096  
1097 21 ▶ my $fix_list = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
1098 21 my ( $scanner, $data_r, $node, $element, @keys ) = @_;
1099  
1100 21 ▶ return unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 9 12 21
1101  
1102 12 map { $scanner->scan_list( $data_r, $node, $element, $_ ) } @keys;
1103 12 ▶ $node->fetch_element($element)->apply_fixes if $do_apply->($element);
Branch: 1 branch
BranchTrueFalseTotal
if &$do_apply($element) 12 0 12
1104 8 };
1105  
1106 8 my $scan = Config::Model::ObjTreeScanner->new(
1107 hash_element_cb => $fix_hash,
1108 list_element_cb => $fix_list,
1109 leaf_cb => $fix_leaf,
1110 check => 'no',
1111 );
1112  
1113 8 $fix_logger->debug( "apply fix started from ", $self->name );
1114 8 $scan->scan_node( undef, $self );
1115 8 $fix_logger->trace("apply fix done");
1116 8 return $self;
1117 }
1118  
1119 1 ▶sub deep_check ($self, %args){
Subroutine deep_check: called CC=1 SCAR=0.0
Pod documented
1120 1 $deep_check_logger->trace("called on ".$self->name);
1121  
1122 # no deep_check defined (yet). Note that value check is done when
1123 # storing value (even during initial load, so there's no need to
1124 # force a check.
1125 1 ▶ my $check_leaf = sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
1126  
1127 10 ▶ my $check_id = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1128 10 my ( $scanner, $data_r, $node, $element, @keys ) = @_;
1129  
1130 10 $deep_check_logger->trace( "deep check called on from ", $node->name, " elt $element keys @keys" );
1131 10 ▶ return unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 5 5 10
1132 5 $node->fetch_element($element)->deep_check;
1133  
1134 1 };
1135  
1136 my $scan = Config::Model::ObjTreeScanner->new(
1137 hash_element_hook => $check_id,
1138 list_element_hook => $check_id,
1139 leaf_cb => $check_leaf,
1140 auto_vivify => $args{auto_vivify},
1141 1 check => 'no',
1142 );
1143  
1144 1 $deep_check_logger->debug( "deep check started from ", $self->name );
1145 1 $scan->scan_node( undef, $self );
1146 1 $deep_check_logger->trace("deep check done");
1147 1 return;
1148 }
1149  
1150 59 __PACKAGE__->meta->make_immutable;
1151  
1152 59 1;
1153  
1154 # ABSTRACT: Class for configuration tree node
1155  
1156 __END__
« blib/lib/Config/Model/AnyId.pm ↑ Summary blib/lib/Config/Model/DumpAsData.pm »