blib/lib/Config/Model/CheckList.pm

filter: Statementstmt 88.0% 374 / 425 Branchbran 75.4% 154 / 204 Conditioncond 62.7% 69 / 110 MC/DCmcdc 46.4% 26 / 56 Subroutinesub 89.7% 61 / 68 Podpod 61.2% 30 / 49 totaltotal 78.2% 714 / 912 CC 160 SCAR 35.3
CC
160
Cov
81%
is_checked
199.0
_store
21.6
get_checked_list_as_hash
20.2
CRAP 34.1
« blib/lib/Config/Model/Role/Grab.pm ↑ Summary blib/lib/Config/Model/Warper.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::CheckList 2.169;
11  
12 19 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 19 ▶use feature qw/postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶no warnings qw/experimental::postderef experimental::signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 19 ▶use Config::Model::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 19 ▶use Config::Model::IdElementReference;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 19 ▶use Config::Model::Warper;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶use List::MoreUtils qw/any none/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 19 ▶use Log::Log4perl qw(get_logger :levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 19 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 19 extends qw/Config::Model::AnyThing/;
27  
28 19 with "Config::Model::Role::WarpMaster";
29 19 with "Config::Model::Role::Grab";
30 19 with "Config::Model::Role::HelpAsText";
31 19 with "Config::Model::Role::ComputeFunction";
32 19 with "Config::Model::Role::Utils";
33 # this requires backup method from Config::Model::AnyThing
34 19 with "Config::Model::Role::WarpSubject";
35  
36 19 my $logger = get_logger("Tree.Element.CheckList");
37 19 my $user_logger = get_logger("User");
38  
39 19 my @introspect_params = qw/refer_to computed_refer_to/;
40  
41 19 my @accessible_params = qw/default_list upstream_default_list choice ordered/;
42 19 my @allowed_warp_params = ( @accessible_params, qw/level/ );
43  
44 183 ▶has [qw/data preset layered/] => ( is => 'rw', isa => 'HashRef', default => sub { {}; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
45 19 has computed_refer_to => ( is => 'rw', isa => 'Maybe[HashRef]' );
46 19 has [qw/refer_to/] => ( is => 'rw', isa => 'Str' );
47 91 ▶has [qw/ordered_data choice/] => ( is => 'rw', isa => 'ArrayRef', default => sub { []; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
48 19 has [qw/ordered/] => ( is => 'ro', isa => 'Bool' );
49  
50 19 has [qw/warp help/] => ( is => 'rw', isa => 'Maybe[HashRef]' );
51  
52 61 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 61 my $orig = shift;
54 61 my $class = shift;
55 61 my %args = @_;
56 61 my %h = map { ( $_ => $args{$_} ); } grep { defined $args{$_} } @allowed_warp_params;
57 61 return $class->$orig( backup => dclone( \%h ), @_ );
58 19 };
59  
60 # used by roles
61 66 ▶sub allowed_warp_params {
Subroutine allowed_warp_params: called CC=1 SCAR=0.0
Pod undocumented
62 66 return @allowed_warp_params;
63 }
64  
65 61 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod documented
66 61 my $self = shift;
67  
68 61 ▶ if ( defined $self->refer_to or defined $self->computed_refer_to ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->refer_to or defined $self->computed_refer_to) 30 31 61
Condition100%3/3
defined $self->refer_to or defined $self->computed_refer_to
l!l&&r!l&&!r
29131
MC/DC100%2/2
defined $self->refer_to or defined $self->computed_refer_to
defined $self->refer_to defined $self->computed_refer_to
Truth table100%3/3
A or B
A= defined $self->refer_toB= defined $self->computed_refer_to
ABresult
1X1
011
000
69 30 $self->submit_to_refer_to();
70 }
71  
72 61 $self->set_properties(); # set will use backup data
73  
74 61 ▶ if ( defined $self->warp ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->warp) 3 58 61
75 3 my $warp_info = $self->warp;
76 3 $self->{warper} = Config::Model::Warper->new(
77 warped_object => $self,
78 %$warp_info,
79 allowed => \@allowed_warp_params
80 );
81 }
82  
83 61 $self->cl_init;
84  
85 61 $logger->info( "Created check_list element " . $self->element_name );
86 61 return $self;
87 }
88  
89 61 ▶sub cl_init {
Subroutine cl_init: called CC=4 SCAR=13.9
Pod undocumented
90 61 my $self = shift;
91  
92 61 ▶ $self->warp if ( $self->{warp} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"warp"} 3 58 61
93  
94 61 ▶ if ( defined $self->{ref_object} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"ref_object"}) 30 31 61
95 my $level = $self->parent->get_element_property(
96 element => $self->{element_name},
97 30 property => 'level',
98 );
99 30 ▶ $self->{ref_object}->get_choice_from_referred_to if $level ne 'hidden';
Branch: 1 branch
BranchTrueFalseTotal
if $level ne "hidden" 28 2 30
100 }
101 61 return;
102 }
103  
104 549 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
105 549 my $self = shift;
106 549 my $name = $self->{parent}->name . ' ' . $self->{element_name};
107 549 return $name;
108 }
109  
110 167 ▶sub value_type { return 'check_list'; }
Subroutine value_type: called CC=1 SCAR=0.0
Pod undocumented
111  
112 # warning : call to 'set' are not cumulative. Default value are always
113 # restored. Lest keeping track of what was modified with 'set' is
114 # too hard for the user.
115 66 ▶sub set_properties ($self, %raw_args) {
Subroutine set_properties: called CC=11 SCAR=24.9
Pod undocumented
116 # cleanup all parameters that are handled by warp
117 66 for (@allowed_warp_params) {
118 330 delete $self->{$_};
119 }
120  
121 66 ▶ if ( $logger->is_trace() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger->is_trace) 0 66 66
122 0 my $keys = join( ',', keys %raw_args );
123 0 $logger->trace("set_properties called on $self->{element_name} with $keys");
124 }
125  
126 # merge data passed to set_properties with data passed to the constructor
127 66 my %args = $self->merge_properties(%raw_args);
128  
129 # these are handled by Node or Warper
130 66 for (qw/level/) {
131 66 delete $args{$_}
132 }
133  
134 66 ▶ $self->{ordered} = delete $args{ordered} || 0;
Condition100%2/2
delete $args{'ordered'} || 0
l!l
462
MC/DC100%1/1
delete $args{'ordered'} || 0
delete $args{'ordered'}
Truth table100%2/2
A
A= delete $args{'ordered'}
Aresult
11
00
135  
136 66 ▶ if ( defined $args{choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"choice"}) 33 33 66
137 33 my @choice = @{ delete $args{choice} };
138 33 $self->{default_choice} = \@choice;
139 33 $self->setup_choice(@choice);
140 }
141  
142 66 ▶ if ( defined $args{default} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"default"}) 0 66 66
143 0 $logger->warn($self->name, ": default param is deprecated, use default_list");
144 0 $args{default_list} = delete $args{default};
145 }
146  
147 66 ▶ if ( defined $args{default_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"default_list"}) 3 63 66
148 3 $self->{default_list} = delete $args{default_list};
149 }
150  
151 # store default data in a hash (more convenient)
152 66 $self->{default_data} = { map { $_ => 1 } @{ $self->{default_list} } };
153  
154 66 ▶ if ( defined $args{upstream_default_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"upstream_default_list"}) 3 63 66
155 3 $self->{upstream_default_list} = delete $args{upstream_default_list};
156 }
157  
158 # store upstream default data in a hash (more convenient)
159 $self->{upstream_default_data} =
160 66 { map { $_ => 1 } @{ $self->{upstream_default_list} } };
161  
162 66 ▶ Config::Model::Exception::Model->throw(
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %args 0 66 66
163 object => $self,
164 error => "Unexpected parameters :" . join( ' ', keys %args ) ) if scalar keys %args;
165  
166 66 ▶ if ( $self->has_warped_slaves ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_warped_slaves) 0 66 66
167 0 my $hash = $self->get_checked_list_as_hash; # force scalar context
168 0 $self->trigger_warp($hash, $self->fetch);
169 }
170 66 return;
171 }
172  
173 144 ▶sub setup_choice ($self, @args) {
Subroutine setup_choice: called CC=8 SCAR=21.3
Pod undocumented
174 0 ▶ my @choice = ref $args[0] ? @{ $args[0] } : @args;
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 0 144 144
175  
176 144 $logger->trace("CheckList $self->{element_name}: setup_choice with @choice");
177  
178 # store all enum values in a hash. This way, checking
179 # whether a value is present in the enum set is easier
180 144 ▶ delete $self->{choice_hash} if defined $self->{choice_hash};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"choice_hash"} 77 67 144
181 144 for (@choice) {
182 908 $self->{choice_hash}{$_} = 1;
183 }
184  
185 144 $self->{choice} = \@choice;
186  
187 # cleanup current preset and data if it does not fit current choices
188 144 foreach my $field (qw/preset data layered/) {
189 432 ▶ next unless defined $self->{$field}; # do not create if not present
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$field} 0 432 432
190 432 foreach my $item ( keys %{ $self->{$field} } ) {
191 109 ▶ delete $self->{$field}{$item} unless defined $self->{choice_hash}{$item};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"choice_hash"}{$item} 0 109 109
192 }
193 }
194 144 return;
195 }
196  
197 # Need to extract Config::Model::Reference (used by Value, and maybe AnyId).
198  
199 30 ▶sub submit_to_refer_to {
Subroutine submit_to_refer_to: called CC=6 SCAR=18.4
Pod undocumented
200 30 my $self = shift;
201  
202 30 ▶ if ( defined $self->refer_to ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->refer_to) { } 29 1 30
elsif (defined $self->computed_refer_to) { } 1 0 1
203 29 $self->{ref_object} = Config::Model::IdElementReference->new(
204 refer_to => $self->refer_to,
205 config_elt => $self,
206 );
207 }
208 elsif ( defined $self->computed_refer_to ) {
209 1 $self->{ref_object} = Config::Model::IdElementReference->new(
210 computed_refer_to => $self->computed_refer_to,
211 config_elt => $self,
212 );
213 1 my $var = $self->{computed_refer_to}{variables};
214  
215 # refer_to registration is done for all element that are used as
216 # variable for complex reference (ie '- $foo' , {foo => '- bar'} )
217 1 foreach my $path ( values %$var ) {
218  
219 # is ref during test case
220 #print "path is '$path'\n";
221 1 ▶ next if $path =~ /\$/; # next if path also contain a variable
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ /\$/u 0 1 1
222 1 my $master = $self->grab($path);
223 1 ▶ next unless $master->can('register_dependency');
Branch: 1 branch
BranchTrueFalseTotal
unless $master->can("register_dependency") 0 1 1
224 1 $master->register_dependency($self);
225 }
226 }
227 else {
228 0 croak "checklist submit_to_refer_to: undefined refer_to or computed_refer_to";
229 }
230 30 return;
231 }
232  
233 111 ▶sub setup_reference_choice ($self, @args) {
Subroutine setup_reference_choice: called CC=1 SCAR=0.0
Pod undocumented
234 111 return $self->setup_choice(@args);
235 }
236  
237 147 ▶sub get_type {
Subroutine get_type: called CC=1 SCAR=0.0
Pod documented
238 147 my $self = shift;
239 147 return 'check_list';
240 }
241  
242 130 ▶sub get_cargo_type { goto &cargo_type }
Subroutine get_cargo_type: called CC=1 SCAR=0.0
Pod undocumented
243  
244 130 ▶sub cargo_type {
Subroutine cargo_type: called CC=1 SCAR=0.0
Pod documented
245 130 my $self = shift;
246 130 return 'leaf';
247 }
248  
249 12 ▶sub apply_fixes {
Subroutine apply_fixes: called CC=1 SCAR=0.0
Pod undocumented
250 # no operation. There's no check_value method because a check list
251 # supposed to be always correct. Hence apply_fixes is empty.
252 }
253  
254 60 ▶sub notify_change ($self, %args) {
Subroutine notify_change: called CC=5 SCAR=16.3
Pod documented
255  
256 60 ▶ return if $self->instance->initial_load and not $args{really};
Branch: 1 branch
BranchTrueFalseTotal
if $self->instance->initial_load and not $args{"really"} 4 56 60
Condition66%2/3
$self->instance->initial_load and not $args{"really"}
!ll&&!rl&&r
5604
MC/DC50%1/2
$self->instance->initial_load and not $args{"really"}
$self->instance->initial_load not $args{"really"}
Truth table66%2/3
A and not(B)
A= $self->instance->initial_loadB= not $args{"really"}
ABresult
0X0
100
111
257  
258 56 $self->SUPER::notify_change( %args, value_type => $self->value_type );
259  
260 # shake all warped or computed objects that depends on me
261 56 foreach my $s ( $self->get_warped_slaves ) {
262 8 ▶ $logger->debug( "calling notify_change on slave ", $s->name )
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_debug 0 8 8
263 if $logger->is_debug;
264 8 $s->needs_check(1);
265 }
266 56 return;
267 }
268  
269  
270 # does not check the validity, but check the item of the check_list
271 11 ▶sub check ($self, @raw_args) {
Subroutine check: called CC=6 SCAR=18.6
Pod documented
272 11 my (@list, %args);
273 11 ▶ if (ref $raw_args[0] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw_args[0] eq 'ARRAY') { } 0 11 11
274 0 @list = shift(@raw_args)->@*;
275 0 %args = @raw_args;
276 }
277 else {
278 11 @list = @raw_args;
279 11 %args = (check => 'yes')
280 }
281 11 my $check = $self->_check_check( $args{check} );
282  
283 11 ▶ if ( defined $self->{ref_object} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"ref_object"}) 3 8 11
284 3 $self->{ref_object}->get_choice_from_referred_to;
285 }
286  
287 11 my @changed;
288 11 for (@list) {
289 14 ▶ push @changed, $_ if $self->_store( $_, 1, $check )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_store($_, 1, $check) 12 0 12
290 }
291  
292 9 ▶ $self->notify_change( note => "check @changed" )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->instance->initial_load 9 0 9
293 unless $self->instance->initial_load;
294 9 return;
295 }
296  
297 270 ▶sub clear_item {
Subroutine clear_item: called CC=6 SCAR=19.5
Pod documented
298 270 my $self = shift;
299 270 my $choice = shift;
300  
301 270 my $inst = $self->instance;
302 270 ▶ my $data_name =
Branch: 2 branches
BranchTrueFalseTotal
$inst->preset ? : 0 270 270
$inst->layered ? : 8 262 270
303 $inst->preset ? 'preset'
304 : $inst->layered ? 'layered'
305 : 'data';
306 270 my $old_v = $self->{$data_name}{$choice};
307 270 my $changed = 0;
308 270 ▶ if ($old_v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_v) 62 208 270
309 62 $changed = 1;
310 }
311 270 delete $self->{$data_name}{$choice};
312  
313 270 ▶ if ( $self->{ordered} and $changed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ordered"} and $changed) 0 270 270
Condition33%1/3
$self->{"ordered"} and $changed
!ll&&!rl&&r
27000
MC/DC0%0/2
$self->{"ordered"} and $changed
$self->{"ordered"} $changed
Truth table33%1/3
A and B
A= $self->{"ordered"}B= $changed
ABresult
0X0
100
111
314 0 my $ord = $self->{ordered_data};
315 0 my @new = grep { $_ ne $choice } @$ord;
316 0 $self->{ordered_data} = \@new;
317 }
318 270 return $changed;
319 }
320  
321 # internal
322 784 ▶sub _store {
Subroutine _store: called CC=21 SCAR=30.7
323 784 my ( $self, $choice, $value, $check ) = @_;
324  
325 784 my $inst = $self->instance;
326  
327 784 ▶ if ( $value != 0 and $value != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value != 0 and $value != 1) 0 784 784
Condition66%2/3
$value != 0 and $value != 1
!ll&&!rl&&r
5802040
MC/DC0%0/2
$value != 0 and $value != 1
$value != 0 $value != 1
Truth table66%2/3
A and B
A= $value != 0B= $value != 1
ABresult
0X0
100
111
328 0 Config::Model::Exception::WrongValue->throw(
329 error => "store: check item value must be boolean, " . "not '$value'.",
330 object => $self
331 );
332 0 return;
333 }
334  
335 784 ▶ my $ok = $self->{choice_hash}{$choice} || 0;
Condition100%2/2
$self->{'choice_hash'}{$choice} || 0
l!l
7759
MC/DC100%1/1
$self->{'choice_hash'}{$choice} || 0
$self->{'choice_hash'}{$choice}
Truth table100%2/2
A
A= $self->{'choice_hash'}{$choice}
Aresult
11
00
336 784 my $changed = 0;
337  
338 784 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 775 9 784
339 775 ▶ my $data_name =
Branch: 2 branches
BranchTrueFalseTotal
$inst->preset ? : 26 749 775
$inst->layered ? : 58 691 749
340 $inst->preset ? 'preset'
341 : $inst->layered ? 'layered'
342 : 'data';
343 775 my $old_v = $self->{$data_name}{$choice} ;
344 775 ▶ if ( not defined $old_v or $old_v ne $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $old_v or $old_v ne $value) 540 235 775
Condition100%3/3
not defined $old_v or $old_v ne $value
l!l&&r!l&&!r
50337235
MC/DC100%2/2
not defined $old_v or $old_v ne $value
not defined $old_v $old_v ne $value
Truth table100%3/3
not(A) or B
A= not defined $old_vB= $old_v ne $value
ABresult
1X1
011
000
345 # no change notif when going from undef to 0 as the
346 # logical value does not change
347 {
348 ## no critic (TestingAndDebugging::ProhibitNoWarning)
349 19 ▶ no warnings qw/uninitialized/;
Subroutine BEGIN: called CC=1 SCAR=0.0
350 540 ▶ $changed = (!$old_v xor !$value);
Condition75%3/4
!$old_v ^^ !$value
l&&rl&&!r!l&&r!l&&!r
37715760
MC/DC100%2/2
!$old_v ^^ !$value
!$old_v !$value
Truth table75%3/4
not(A) ^^ not(B)
A= !$old_vB= !$value
ABresult
110
101
011
000
351 }
352 540 $self->{$data_name}{$choice} = $value;
353 }
354  
355 775 ▶ if ( $self->{ordered} and $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ordered"} and $value) 17 758 775
Condition100%3/3
$self->{"ordered"} and $value
!ll&&!rl&&r
7085017
MC/DC100%2/2
$self->{"ordered"} and $value
$self->{"ordered"} $value
Truth table100%3/3
A and B
A= $self->{"ordered"}B= $value
ABresult
0X0
100
111
356 17 my $ord = $self->{ordered_data};
357 17 ▶ push @$ord, $choice unless scalar grep { $choice eq $_ } @$ord;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar grep({$choice eq $_;} @$ord) 16 1 17
358 }
359 }
360 else {
361 my $err_str =
362 "Unknown check_list item '$choice'. Expected '"
363 9 . join( "', '", @{ $self->{choice} } ) . "'";
364 $err_str .= "\n\t" . $self->{ref_object}->reference_info
365 9 ▶ if defined $self->{ref_object};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ref_object"} 1 8 9
366 9 ▶ if ($check eq 'yes') {
Branch: 2 branches
BranchTrueFalseTotal
if ($check eq 'yes') { } 4 5 9
elsif ($check eq 'skip') { } 5 0 5
367 4 Config::Model::Exception::WrongValue->throw( error => $err_str, object => $self );
368 }
369 elsif ($check eq 'skip') {
370 5 $user_logger->warn($err_str);
371 }
372 }
373  
374 780 ▶ if ( $ok
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and $changed and $self->has_warped_slaves and not $self->instance->layered || $self->instance->preset) 4 776 780
Condition75%9/12
$ok and $changed and $self->has_warped_slaves and not $self->instance->layered || $self->instance->preset
!ll&&!rl&&r
77604
$ok and $changed and $self->has_warped_slaves
!ll&&!rl&&r
6171594
$ok and $changed
!ll&&!rl&&r
5612163
$self->instance->layered || $self->instance->preset
l!l&&r!l&&!r
004
MC/DC60%3/5
$ok and $changed and $self->has_warped_slaves and not $self->instance->layered || $self->instance->preset
$ok $changed $self->has_warped_slaves $self->instance->layered $self->instance->preset
Truth table66%4/6
A and B and C and not(D || E)
A= $okB= $changedC= $self->has_warped_slavesD= $self->instance->layeredE= $self->instance->preset
ABCDEresult
0XXXX0
10XXX0
110XX0
1111X0
111010
111001
375 and $changed
376 and $self->has_warped_slaves
377 and not( $self->instance->layered or $self->instance->preset ) ) {
378 4 my $h = $self->get_checked_list_as_hash;
379 4 my $str = $self->fetch;
380 4 $self->trigger_warp($h , $str);
381 }
382  
383 780 return $changed;
384 }
385  
386 57 ▶sub get_arguments ($self, @raw_args) {
Subroutine get_arguments: called CC=2 SCAR=6.9
Pod undocumented
387 57 my (@list, %args);
388 57 ▶ if (ref $raw_args[0] eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw_args[0] eq 'ARRAY') { } 42 15 57
389 42 @list = shift(@raw_args)->@*;
390 42 %args = ( check => 'yes', @raw_args );
391 }
392 else {
393 15 @list = @raw_args;
394 15 %args = (check => 'yes')
395 }
396 57 my $check = $self->_check_check( $args{check} );
397 57 return \@list, $check, \%args;
398 }
399  
400 4 ▶sub uncheck ($self, @args) {
Subroutine uncheck: called CC=5 SCAR=16.6
Pod documented
401 4 my ($list, $check) = $self->get_arguments(@args);
402  
403 4 ▶ if ( defined $self->{ref_object} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"ref_object"}) 0 4 4
404 0 $self->{ref_object}->get_choice_from_referred_to;
405 }
406  
407 4 my @changed;
408 4 for ( @$list ) {
409 4 ▶ push @changed, $_ if $self->_store( $_, 0, $check )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_store($_, 0, $check) 3 1 4
410 }
411  
412 4 ▶ $self->notify_change( note => "uncheck @changed" )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->instance->initial_load 4 0 4
413 unless $self->instance->initial_load;
414 4 return;
415 }
416  
417 3 ▶sub has_data {
Subroutine has_data: called CC=1 SCAR=0.0
Pod documented
418 3 my $self = shift;
419 3 my @set = $self->get_checked_list(qw/mode custom/) ;
420 3 return scalar @set;
421 }
422  
423 {
424 19 my %accept_mode = map { ( $_ => 1 ) }
425 qw/custom standard preset default layered upstream_default non_upstream_default user backend/;
426  
427 186 ▶ sub is_bad_mode {
Subroutine is_bad_mode: called CC=3 SCAR=13.3
Pod documented
428 186 my ($self, $mode) = @_;
429 186 ▶ if ( $mode and not defined $accept_mode{$mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode and not defined $accept_mode{$mode}) 0 186 186
Condition66%2/3
$mode and not defined $accept_mode{$mode}
!ll&&!rl&&r
122640
MC/DC0%0/2
$mode and not defined $accept_mode{$mode}
$mode not defined $accept_mode{$mode}
Truth table66%2/3
A and not(B)
A= $modeB= not defined $accept_mode{$mode}
ABresult
0X0
100
111
430 0 my $good_ones = join( ' or ', sort keys %accept_mode );
431 0 return "expected $good_ones as mode parameter, not $mode";
432 }
433 }
434 }
435  
436 19 ▶sub is_checked ($self, $choice, %args) {
Subroutine is_checked: called CC=31 SCAR=52.9
Pod documented
437 12 ▶ my $mode = $args{mode} || '';
Condition50%1/2
$args{'mode'} || ''
l!l
012
MC/DC0%0/1
$args{'mode'} || ''
$args{'mode'}
Truth table50%1/2
A
A= $args{'mode'}
Aresult
11
00
438 12 my $check = $self->_check_check( $args{check} );
439  
440 12 ▶ my $ok = $self->{choice_hash}{$choice} || 0;
Condition50%1/2
$self->{'choice_hash'}{$choice} || 0
l!l
120
MC/DC0%0/1
$self->{'choice_hash'}{$choice} || 0
$self->{'choice_hash'}{$choice}
Truth table50%1/2
A
A= $self->{'choice_hash'}{$choice}
Aresult
11
00
441  
442 12 ▶ if ($ok) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ok) { } 12 0 12
elsif ($check eq 'yes') { } 0 0 0
443  
444 12 ▶ if ( my $err = $self->is_bad_mode($mode) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $self->is_bad_mode($mode)) 0 12 12
445 0 croak "is_checked: $err";
446 }
447  
448 12 my $dat = $self->{data}{$choice};
449 12 my $pre = $self->{preset}{$choice};
450 12 my $def = $self->{default_data}{$choice};
451 12 my $ud = $self->{upstream_default_data}{$choice};
452 12 my $lay = $self->{layered}{$choice};
453 12 ▶ my $std_v = $pre // $def // 0;
Condition40%2/5
($pre // $def) // 0
l!l
012
$pre // $def
l!l&&r!l&&!r
0012
MC/DC0%0/2
($pre // $def) // 0
$pre $def
Truth table33%1/3
A // B
A= $preB= $def
ABresult
1X1
011
000
454 12 ▶ my $non_up_def = $dat // $pre // $lay // $def // 0;
Condition36%4/11
((($dat // $pre) // $lay) // $def) // 0
l!l
120
(($dat // $pre) // $lay) // $def
l!l&&r!l&&!r
1200
($dat // $pre) // $lay
l!l&&r!l&&!r
1200
$dat // $pre
l!l&&r!l&&!r
1200
MC/DC0%0/4
((($dat // $pre) // $lay) // $def) // 0
$dat $pre $lay $def
Truth table20%1/5
A // B // C // D
A= $datB= $preC= $layD= $def
ABCDresult
1XXX1
01XX1
001X1
00011
00000
455 12 ▶ my $user_v = $dat // $pre // $lay // $def // $ud // 0;
Condition35%5/14
(((($dat // $pre) // $lay) // $def) // $ud) // 0
l!l
120
((($dat // $pre) // $lay) // $def) // $ud
l!l&&r!l&&!r
1200
(($dat // $pre) // $lay) // $def
l!l&&r!l&&!r
1200
($dat // $pre) // $lay
l!l&&r!l&&!r
1200
$dat // $pre
l!l&&r!l&&!r
1200
MC/DC0%0/5
(((($dat // $pre) // $lay) // $def) // $ud) // 0
$dat $pre $lay $def $ud
Truth table16%1/6
A // B // C // D // E
A= $datB= $preC= $layD= $defE= $ud
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
456  
457 12 ▶ my $result =
Branch: 10 branches
BranchTrueFalseTotal
$mode eq 'custom' ? : 0 12 12
$dat && !$std_v ? : 0 0 0
$mode eq 'preset' ? : 0 12 12
$mode eq 'layered' ? : 0 12 12
$mode eq 'upstream_default' ? : 0 12 12
$mode eq 'default' ? : 0 12 12
$mode eq 'standard' ? : 0 12 12
$mode eq 'non_upstream_default' ? : 0 12 12
$mode eq 'user' ? : 0 12 12
$mode eq 'backend' ? : 0 12 12
Condition11%1/9
$dat and not $std_v
!ll&&!rl&&r
000
$dat // $std_v
l!l&&r!l&&!r
000
$dat // $std_v
l!l&&r!l&&!r
1200
MC/DC0%0/2
$dat and not $std_v
$dat not $std_v
MC/DC0%0/2
$dat // $std_v
$dat $std_v
MC/DC0%0/2
$dat // $std_v
$dat $std_v
Truth table0%0/3
A and not(B)
A= $datB= not $std_v
ABresult
0X0
100
111
Truth table0%0/3
A // B
A= $datB= $std_v
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $datB= $std_v
ABresult
1X1
011
000
458 $mode eq 'custom' ? ( $dat && !$std_v ? 1 : 0 )
459 : $mode eq 'preset' ? $pre
460 : $mode eq 'layered' ? $lay
461 : $mode eq 'upstream_default' ? $ud
462 : $mode eq 'default' ? $def
463 : $mode eq 'standard' ? $std_v
464 : $mode eq 'non_upstream_default' ? $ud
465 : $mode eq 'user' ? $user_v
466 : $mode eq 'backend' ? $dat // $std_v
467 : $dat // $std_v;
468  
469 12 return $result;
470 }
471 elsif ( $check eq 'yes' ) {
472 my $err_str =
473 "Unknown check_list item '$choice'. Expected '"
474 0 . join( "', '", @{ $self->{choice} } ) . "'";
475 $err_str .= "\n\t" . $self->{ref_object}->reference_info
476 0 ▶ if defined $self->{ref_object};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ref_object"} 0 0 0
477 0 Config::Model::Exception::WrongValue->throw(
478 error => $err_str,
479 object => $self
480 );
481 }
482 0 return;
483 }
484  
485 # get_choice is always called when using check_list, so having a
486 # warp safety check here makes sense
487  
488 254 ▶sub get_choice {
Subroutine get_choice: called CC=3 SCAR=11.0
Pod documented
489 254 my $self = shift;
490  
491 254 ▶ if ( defined $self->{ref_object} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"ref_object"}) 80 174 254
492 80 $self->{ref_object}->get_choice_from_referred_to;
493 }
494  
495 254 ▶ if ( not defined $self->{choice} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"choice"}) 1 253 254
496 1 my $msg = "check_list element has no defined choice. " . $self->warp_error;
497 1 Config::Model::Exception::UnavailableElement->throw(
498 info => $msg,
499 object => $self->parent,
500 element => $self->element_name,
501 );
502 }
503  
504 253 return @{ $self->{choice} };
505 }
506  
507 111 ▶sub get_default_choice {
Subroutine get_default_choice: called CC=2 SCAR=6.9
Pod undocumented
508 111 my $self = shift;
509 111 ▶ return @{ $self->{default_choice} || [] };
Condition100%2/2
$self->{'default_choice'} || []
l!l
6105
MC/DC100%1/1
$self->{'default_choice'} || []
$self->{'default_choice'}
Truth table100%2/2
A
A= $self->{'default_choice'}
Aresult
11
00
510 }
511  
512 0 ▶sub get_builtin_choice {
Subroutine get_builtin_choice: not called CC=1 SCAR=6.9
Pod undocumented
513 0 carp "get_builtin_choice is deprecated, use get_upstream_default_choice";
514 0 goto &get_upstream_default_choice;
515 }
516  
517 0 ▶sub get_upstream_default_choice {
Subroutine get_upstream_default_choice: not called CC=2 SCAR=17.9
Pod undocumented
518 0 my $self = shift;
519 0 ▶ return @{ $self->{upstream_default_data} || [] };
Condition0%0/2
$self->{'upstream_default_data'} || []
l!l
00
MC/DC0%0/1
$self->{'upstream_default_data'} || []
$self->{'upstream_default_data'}
Truth table0%0/2
A
A= $self->{'upstream_default_data'}
Aresult
11
00
520 }
521  
522 3 ▶sub get_help {
Subroutine get_help: called CC=4 SCAR=14.0
Pod documented
523 3 my $self = shift;
524 3 my $help = $self->{help};
525  
526 3 ▶ return $help unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
527  
528 3 my $on_value = shift;
529 3 ▶ return $help->{$on_value} if defined $help and defined $on_value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $help and defined $on_value 1 2 3
Condition66%2/3
defined $help and defined $on_value
!ll&&!rl&&r
201
MC/DC50%1/2
defined $help and defined $on_value
defined $help defined $on_value
Truth table66%2/3
A and B
A= defined $helpB= defined $on_value
ABresult
0X0
100
111
530  
531 2 return;
532 }
533  
534 1 ▶sub get_info {
Subroutine get_info: called CC=3 SCAR=11.2
Pod documented
535 1 my $self = shift;
536  
537 1 my @items = ('type: check_list');
538 1 ▶ if ( defined $self->refer_to ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->refer_to) 1 0 1
539 1 push @items, "refer_to: " . $self->refer_to;
540 }
541 1 ▶ push @items, "ordered: " . ( $self->ordered ? 'yes' : 'no' );
Branch: 1 branch
BranchTrueFalseTotal
$self->ordered ? : 0 1 1
542 1 return @items;
543 }
544  
545 9 ▶sub clear {
Subroutine clear: called CC=2 SCAR=6.9
Pod documented
546 9 my $self = shift;
547 # also triggers notify changes
548 9 for my $item ($self->get_choice) {
549 234 $self->clear_item($item);
550 }
551 9 return;
552 }
553  
554 0 ▶sub clear_values { goto &clear; }
Subroutine clear_values: not called CC=1 SCAR=6.9
Pod undocumented
555  
556 3 ▶sub clear_layered {
Subroutine clear_layered: called CC=1 SCAR=0.0
Pod undocumented
557 3 my $self = shift;
558 3 $self->{layered} = {};
559 3 return;
560 }
561  
562 19 my %old_mode = ( built_in_list => 'upstream_default_list', );
563  
564 174 ▶sub get_checked_list_as_hash ($self, @args) {
Subroutine get_checked_list_as_hash: called CC=20 SCAR=30.0
Pod documented
565 174 my %args = _resolve_arg_shortcut(\@args, 'mode');
566 174 ▶ my $mode = $args{mode} || '';
Condition100%2/2
$args{'mode'} || ''
l!l
64110
MC/DC100%1/1
$args{'mode'} || ''
$args{'mode'}
Truth table100%2/2
A
A= $args{'mode'}
Aresult
11
00
567  
568 174 foreach my $k ( keys %old_mode ) {
569 174 ▶ next unless $mode eq $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode eq $k 174 0 174
570 0 $mode = $old_mode{$k};
571 0 carp $self->location, " warning: deprecated mode parameter: $k, ", "expected $mode\n";
572 }
573  
574 174 ▶ if ( my $err = $self->is_bad_mode($mode)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $self->is_bad_mode($mode)) 0 174 174
575 0 croak "get_checked_list_as_hash: $err";
576 }
577  
578 174 my $dat = $self->{data};
579 174 my $pre = $self->{preset};
580 174 my $def = $self->{default_data};
581 174 my $lay = $self->{layered};
582 174 my $ud = $self->{upstream_default_data};
583  
584 # fill empty hash result
585 174 my %h = map { $_ => 0 } $self->get_choice;
586  
587 174 my %predef = ( %$def, %$pre );
588 174 my %std = ( %$ud, %$lay, %$def, %$pre );
589  
590 # use _std_backup if all data values are null (no checked items by user)
591 174 ▶ my %old_dat = ( none { $_; } values %$dat ) ? %{ $self->{_std_backup} || {} } : %$dat;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
&none(sub { $_; } , values %$dat) ? : 62 112 174
Condition100%2/2
$self->{'_std_backup'} || {}
l!l
458
MC/DC100%1/1
$self->{'_std_backup'} || {}
$self->{'_std_backup'}
Truth table100%2/2
A
A= $self->{'_std_backup'}
Aresult
11
00
592  
593 174 ▶ if ( not $mode and any { $_; } values %predef and none { $_; } values %old_dat ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (not $mode and &any(sub { $_; } , values %predef) and &none(sub { $_; } , values %old_dat)) 4 170 174
Condition100%6/6
not $mode and &any(sub { $_; } , values %predef) and &none(sub { $_; } , values %old_dat)
!ll&&!rl&&r
16644
not $mode and &any(sub { $_; } , values %predef)
!ll&&!rl&&r
641028
MC/DC100%3/3
not $mode and &any(sub { $_; } , values %predef) and &none(sub { $_; } , values %old_dat)
not $mode &any(sub { $_; } , values %predef) &none(sub { $_; } , values %old_dat)
Truth table100%4/4
not(A) and B and C
A= not $modeB= &any(sub { $_; } , values %predef)C= &none(sub { $_; } , values %old_dat)
ABCresult
0XX0
10X0
1100
1111
594  
595 # changed from nothing to default checked list that must be written
596 4 $self->{_std_backup} = { %$def, %$pre };
597 4 $self->notify_change( note => "use default checklist" );
598 }
599  
600 # custom test must compare the whole list at once, not just one item at a time.
601 my %result =
602 174 ▶ $mode eq 'custom' ? ( ( grep { $dat->{$_} xor $std{$_} } keys %h ) ? ( %$pre, %$dat ) : () )
Branch: 8 branches
BranchTrueFalseTotal
$mode eq 'custom' ? : 33 141 174
grep({$dat->{$_} xor $std{$_};} keys %h) ? : 22 11 33
$mode eq 'preset' ? : 3 138 141
$mode eq 'layered' ? : 4 134 138
$mode eq 'upstream_default' ? : 1 133 134
$mode eq 'default' ? : 1 132 133
$mode eq 'standard' ? : 4 128 132
$mode eq 'user' ? : 17 111 128
Condition100%4/4
$dat->{$_} ^^ $std{$_}
l&&rl&&!r!l&&r!l&&!r
23720377
MC/DC100%2/2
$dat->{$_} ^^ $std{$_}
$dat->{$_} $std{$_}
Truth table100%4/4
A ^^ B
A= $dat->{$_}B= $std{$_}
ABresult
110
101
011
000
603 : $mode eq 'preset' ? (%$pre)
604 : $mode eq 'layered' ? (%$lay)
605 : $mode eq 'upstream_default' ? (%$ud)
606 : $mode eq 'default' ? (%$def)
607 : $mode eq 'standard' ? %std
608 : $mode eq 'user' ? ( %h, %std, %$dat )
609 : ( %predef, %$dat );
610  
611 174 ▶ return wantarray ? %result : \%result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 166 8 174
612 }
613  
614 166 ▶sub get_checked_list ($self, @args) {
Subroutine get_checked_list: called CC=3 SCAR=11.0
Pod documented
615 166 my %h = $self->get_checked_list_as_hash(@args);
616 166 ▶ my @good_order = $self->{ordered} ? @{ $self->{ordered_data} } : sort keys %h;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ordered'} ? : 15 151 166
617 166 my @res = grep { $h{$_} } @good_order;
618 166 ▶ return wantarray ? @res : \@res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 147 19 166
619 }
620  
621 72 ▶sub fetch ($self, @args) {
Subroutine fetch: called CC=1 SCAR=0.0
Pod documented
622 72 return join( ',', $self->get_checked_list(@args));
623 }
624  
625 2 ▶sub fetch_gist ($self) {
Subroutine fetch_gist: called CC=2 SCAR=6.9
Pod documented
626 2 my $value = join( ',', $self->get_checked_list(check => 'no') );
627 2 ▶ $value = substr( $value, 0, 15 ) . '...' if length($value) > 15;
Branch: 1 branch
BranchTrueFalseTotal
if length $value > 15 1 1 2
628 2 return $value;
629 }
630  
631 1 ▶sub fetch_custom {
Subroutine fetch_custom: called CC=1 SCAR=0.0
Pod undocumented
632 1 my $self = shift;
633 1 return join( ',', $self->get_checked_list('custom') );
634 }
635  
636 0 ▶sub fetch_preset {
Subroutine fetch_preset: not called CC=1 SCAR=6.9
Pod undocumented
637 0 my $self = shift;
638 0 return join( ',', $self->get_checked_list('preset') );
639 }
640  
641 0 ▶sub fetch_layered {
Subroutine fetch_layered: not called CC=1 SCAR=6.9
Pod undocumented
642 0 my $self = shift;
643 0 return join( ',', $self->get_checked_list('layered') );
644 }
645  
646 0 ▶sub get ($self, $path, @args){
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
647 0 ▶ if ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 0 0 0
648 0 Config::Model::Exception::User->throw(
649 object => $self,
650 message => "get() called with a value with non-empty path: '$path'"
651 );
652 }
653 0 return $self->fetch(@args);
654 }
655  
656 3 ▶sub set {
Subroutine set: called CC=2 SCAR=7.2
Pod documented
657 3 my ($self, $path, $list, %args) = @_;
658  
659 3 my $check_validity = $self->_check_check( $args{check} );
660 3 ▶ if ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 0 3 3
661 0 Config::Model::Exception::User->throw(
662 object => $self,
663 message => "set() called with a value with non-empty path: '$path'"
664 );
665 }
666  
667 3 my @list = split /,/, $list;
668 3 return $self->set_checked_list( \@list, check => $check_validity );
669 }
670  
671 18 ▶sub load {
Subroutine load: called CC=1 SCAR=0.0
Pod documented
672 18 goto &store;
673 }
674  
675 23 ▶sub store ($self, @raw_args) {
Subroutine store: called CC=4 SCAR=13.9
Pod documented
676 23 ▶ my %args =
Branch: 2 branches
BranchTrueFalseTotal
@raw_args == 1 ? : 1 22 23
@raw_args == 3 ? : 20 2 22
677 @raw_args == 1 ? ( value => $raw_args[0] )
678 : @raw_args == 3 ? ( 'value', @raw_args )
679 : @raw_args;
680 23 my $check_validity = $self->_check_check( $args{check} );
681  
682 23 my @set = split /\s*,\s*/, $args{value};
683 23 foreach (@set) { s/^"|"$//g; s/\\"/"/g; }
684 23 return $self->set_checked_list(\@set, check => $check_validity);
685 }
686  
687 0 ▶sub store_set { goto &set_checked_list }
Subroutine store_set: not called CC=1 SCAR=6.9
Pod documented
688  
689 50 ▶sub set_checked_list ($self, @args) {
Subroutine set_checked_list: called CC=7 SCAR=19.5
Pod documented
690 50 my ($list, $check) = $self->get_arguments(@args);
691  
692 50 $logger->trace("called with @$list");
693 50 my %set = map { $_ => 1 } @$list;
694 50 my @changed;
695  
696 50 foreach my $c ( $self->get_choice ) {
697 719 ▶ my $v = delete $set{$c} // 0;
Condition100%2/2
delete $set{$c} // 0
l!l
168551
MC/DC100%1/1
delete $set{$c} // 0
delete $set{$c}
Truth table100%2/2
A
A= delete $set{$c}
Aresult
11
00
698 719 ▶ push @changed, "$c:$v" if $self->_store( $c, $v, $check );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_store($c, $v, $check) 135 584 719
699 }
700  
701 # Items left in %set are unknown. _store will handle the error
702 50 foreach my $item (keys %set) {
703 4 $self->_store( $item, 1, $check );
704 }
705  
706 49 $self->{ordered_data} = $list;
707  
708 49 ▶ $self->notify_change( note => "set_checked_list @changed" )
Branch: 1 branch
BranchTrueFalseTotal
if @changed and not $self->instance->initial_load 37 12 49
Condition100%3/3
@changed and not $self->instance->initial_load
!ll&&!rl&&r
5737
MC/DC100%2/2
@changed and not $self->instance->initial_load
@changed not $self->instance->initial_load
Truth table100%3/3
A and not(B)
A= @changedB= not $self->instance->initial_load
ABresult
0X0
100
111
709 if @changed and not $self->instance->initial_load;
710  
711 49 return scalar @changed;
712 }
713  
714 5 ▶sub set_checked_list_as_hash ($self, @raw_args) {
Subroutine set_checked_list_as_hash: called CC=4 SCAR=13.9
Pod documented
715 5 my (%check_list, %args);
716 5 ▶ if (ref $raw_args[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $raw_args[0] eq 'HASH') { } 3 2 5
717 3 %check_list = shift(@raw_args)->%*;
718 3 %args = @raw_args;
719 } else {
720 2 %check_list = @raw_args;
721 2 %args = ( check => 'yes' );
722 }
723  
724 5 my $check_validity = $self->_check_check( $args{check} );
725  
726 5 foreach my $c ( $self->get_choice ) {
727 73 ▶ if ( defined $check_list{$c} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check_list{$c}) { } 37 36 73
728 37 $self->_store( $c, $check_list{$c}, $check_validity );
729 }
730 else {
731 36 $self->clear_item($c);
732 }
733 }
734 5 return 1;
735 }
736  
737 12 ▶sub load_data ($self, @args) {
Subroutine load_data: called CC=4 SCAR=14.1
Pod documented
738 12 my %args = _resolve_arg_shortcut(\@args, 'data');
739  
740 12 my $data = $args{data};
741 12 my $check_validity = $self->_check_check( $args{check} );
742  
743 12 ▶ if ( ref($data) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "ARRAY") 7 5 12
744 7 return $self->set_checked_list($data, check => $check_validity);
745 }
746 5 ▶ if ( ref($data) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "HASH") 3 2 5
747 3 return $self->set_checked_list_as_hash($data, check => $check_validity);
748 }
749 2 ▶ if ( not ref($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data) 2 0 2
750 2 return $self->set_checked_list([$data], check => $check_validity );
751 }
752  
753 Config::Model::Exception::LoadData->throw(
754 0 object => $self,
755 message => "check_list load_data called with unexpected type. "
756 . "Expected plain scalar, array or hash ref",
757 wrong_data => $data,
758 );
759 0 return 0;
760 }
761  
762 1 ▶sub swap ( $self, $a, $b ) {
Subroutine swap: called CC=6 SCAR=18.3
Pod documented
763 1 foreach my $param ( $a, $b ) {
764 2 ▶ unless ( $self->is_checked($param) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_checked($param)) 0 2 2
765 0 my $err_str = "swap: choice $param must be set";
766 0 Config::Model::Exception::WrongValue->throw(
767 error => $err_str,
768 object => $self
769 );
770 }
771 }
772  
773 # perform swap in ordered list
774 1 foreach ( @{ $self->{ordered_data} } ) {
775 5 ▶ if ( $_ eq $a ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq $a) { } 1 4 5
elsif ($_ eq $b) { } 1 3 4
776 1 $_ = $b;
777 }
778 elsif ( $_ eq $b ) {
779 1 $_ = $a;
780 }
781 }
782 1 return;
783 }
784  
785 3 ▶sub move_up ( $self, $c ) {
Subroutine move_up: called CC=4 SCAR=14.1
Pod documented
786 3 ▶ unless ( $self->is_checked($c) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_checked($c)) 0 3 3
787 0 my $err_str = "swap: choice $c must be set";
788 0 Config::Model::Exception::WrongValue->throw(
789 error => $err_str,
790 object => $self
791 );
792 }
793  
794 # perform move in ordered list
795 3 my $list = $self->{ordered_data};
796 3 ▶ for ( my $i = 1 ; $i < @$list ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$list) 12 1 13
797 12 ▶ if ( $list->[$i] eq $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->[$i] eq $c) 2 10 12
798 2 $list->[$i] = $list->[ $i - 1 ];
799 2 $list->[ $i - 1 ] = $c;
800 2 last;
801 }
802 }
803 3 return;
804 }
805  
806 2 ▶sub move_down ( $self, $c ) {
Subroutine move_down: called CC=4 SCAR=14.1
Pod documented
807 2 ▶ unless ( $self->is_checked($c) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_checked($c)) 0 2 2
808 0 my $err_str = "swap: choice $c must be set";
809 0 Config::Model::Exception::WrongValue->throw(
810 error => $err_str,
811 object => $self
812 );
813 }
814  
815 # perform move in ordered list
816 2 my $list = $self->{ordered_data};
817 2 ▶ for ( my $i = 0 ; $i + 1 < @$list ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < @$list) 6 1 7
818 6 ▶ if ( $list->[$i] eq $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list->[$i] eq $c) 1 5 6
819 1 $list->[$i] = $list->[ $i + 1 ];
820 1 $list->[ $i + 1 ] = $c;
821 1 last;
822 }
823 }
824 2 return;
825 }
826  
827 # dummy to match Value call
828 2 ▶sub warning_msg {
Subroutine warning_msg: called CC=1 SCAR=0.0
Pod undocumented
829 2 return '';
830 }
831  
832 19 1;
833  
834 # ABSTRACT: Handle check list element
835  
836 __END__
« blib/lib/Config/Model/Role/Grab.pm ↑ Summary blib/lib/Config/Model/Warper.pm »