| 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::Iterator 2.169; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 59 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 59 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 59 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 59 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 59 | ▶ | use Config::Model::ObjTreeScanner; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 59 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 59 | ▶ | use Config::Model::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 59 | ▶ | use feature qw/postderef signatures/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 59 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 59 | my $logger = get_logger("Iterator"); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub new ($type, %args){ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 29 | call_back_on_important => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | forward => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | status => 'standard', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | foreach my $p (qw/root/) { | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | $self->{$p} = delete $args{$p} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | or croak "Iterator->new: Missing $p parameter"; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | foreach my $p (qw/call_back_on_important call_back_on_warning status/) { | |||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | $self->{$p} = delete $args{$p} if defined $args{$p}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | bless $self, $type; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my %cb_hash; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # mandatory call-back parameters | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | foreach my $item (qw/leaf_cb hash_element_cb/) { | |||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | $cb_hash{$item} = delete $args{$item} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | or croak "Iterator->new: Missing $item parameter"; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # handle optional list_element_cb parameter | ||||||||||||||||||||||||||||||||||||||||||
| 54 | $cb_hash{list_element_cb} = delete $args{list_element_cb} | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | || $cb_hash{hash_element_cb}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'list_element_cb'} || $cb_hash{'hash_element_cb'}
MC/DC0%0/2
delete $args{'list_element_cb'} || $cb_hash{'hash_element_cb'}
delete $args{'list_element_cb'}
$cb_hash{'hash_element_cb'}
Truth table33%1/3
A || B
A= delete $args{'list_element_cb'}B= $cb_hash{'hash_element_cb'}
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | # optional call-back parameter | ||||||||||||||||||||||||||||||||||||||||||
| 58 | $cb_hash{check_list_element_cb} = | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | delete $args{check_list_element_cb} || $cb_hash{leaf_cb}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'check_list_element_cb'} || $cb_hash{'leaf_cb'}
MC/DC0%0/2
delete $args{'check_list_element_cb'} || $cb_hash{'leaf_cb'}
delete $args{'check_list_element_cb'}
$cb_hash{'leaf_cb'}
Truth table33%1/3
A || B
A= delete $args{'check_list_element_cb'}B= $cb_hash{'leaf_cb'}
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # optional call-back parameters | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | foreach my $p ( | |||||||||||||||||||||||||||||||||||||||||
| 63 | qw/enum_value reference_value | ||||||||||||||||||||||||||||||||||||||||||
| 64 | integer_value number_value | ||||||||||||||||||||||||||||||||||||||||||
| 65 | boolean_value string_value uniline_value/ | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | my $item = $p . '_cb'; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 7 | ▶ | $cb_hash{$item} = delete $args{$item} || $cb_hash{leaf_cb}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
delete $args{$item} || $cb_hash{'leaf_cb'}
MC/DC0%0/2
delete $args{$item} || $cb_hash{'leaf_cb'}
delete $args{$item}
$cb_hash{'leaf_cb'}
Truth table66%2/3
A || B
A= delete $args{$item}B= $cb_hash{'leaf_cb'}
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | $self->{dispatch_cb} = \%cb_hash; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if (%args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | die "Iterator->new: unexpected parameters: ", join( ' ', keys %args ), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # user call-back are *not* passed to ObjTreeScanner. They will be | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # called indirectly through wizard-helper own call-backs | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | $self->{scanner} = Config::Model::ObjTreeScanner->new( | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | ▶ | hash_element_cb => sub { $self->hash_element_cb(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | list_element_cb => sub { $self->hash_element_cb(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 36 | ▶ | node_content_cb => sub { $self->node_content_cb(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 175 | ▶ | leaf_cb => sub { $self->leaf_cb(@_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $self->{bail_out} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $self->{scanner}->scan_node( undef, $self->{root} ); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | sub bail_out { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bail_out: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | $self->{bail_out} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # internal. This call-back is passed to ObjTreeScanner. It will call | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # scan_element in an order which depends on $self->{forward}. | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 36 | ▶ | sub node_content_cb { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node_content_cb: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 36 | my ( $self, $scanner, $data_r, $node, @element ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 36 | $logger->info( "node_content_cb called on '", $node->name, "' element: @element" ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 36 | my $element; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 36 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # @element from ObjTreeScanner is not used as user actions may | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # change the element list due to warping | ||||||||||||||||||||||||||||||||||||||||||
| 116 | $element = $node->next_element( | ||||||||||||||||||||||||||||||||||||||||||
| 117 | name => $element, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | status => $self->{status}, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 232 | reverse => 1 - $self->{forward} ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 232 | ▶ | last unless defined $element; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 197 | $logger->info( "node_content_cb calls scan_element ", "on element $element" ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 197 | $self->{scanner}->scan_element( $data_r, $node, $element ); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 197 | ▶ | return if $self->{bail_out}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 35 | return; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | # internal. Used to find which user call-back to use for a given | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # element type. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 195 | ▶ | sub get_cb { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_cb: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 195 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 195 | my $elt_type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 195 | ▶ | return $self->{dispatch_cb}{ $elt_type . '_cb' } | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'dispatch_cb'}{$elt_type . '_cb'} || croak("wizard get_cb: unexpected type $elt_type")
MC/DC0%0/1
$self->{'dispatch_cb'}{$elt_type . '_cb'} || croak("wizard get_cb: unexpected type $elt_type")
$self->{'dispatch_cb'}{$elt_type . '_cb'}
Truth table50%1/2
A
A= $self->{'dispatch_cb'}{$elt_type . '_cb'}
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | || croak "wizard get_cb: unexpected type $elt_type"; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | # internal. This call-back is passed to ObjTreeScanner. It will call | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # scan_hash in an order which depends on $self->{forward}. it will | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # also check if the hash (or list) element is flagged as 'important' | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # and call user's hash or list call-back if needed | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 20 | ▶ | sub hash_element_cb ( $self, $scanner, $data_r, $node, $element, @raw_keys ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash_element_cb: called CC=15 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 20 | my @keys = sort @raw_keys; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 20 | my $level = $node->get_element_property( element => $element, property => 'level' ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 20 | $logger->info( "hash_element_cb (element $element) called on '", | |||||||||||||||||||||||||||||||||||||||||
| 150 | $node->location, "' level $level, keys: '@keys'" ); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | # get the call-back to use | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 20 | my $cb = $self->get_cb( $node->element_type($element) . '_element' ); | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | # use the same algorithm for check_important and | ||||||||||||||||||||||||||||||||||||||||||
| 156 | # scan_element pseudo elements | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 20 | ▶ | my $i = $self->{forward} == 1 ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 20 | ▶ | while ( $i >= 0 and $i < 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i >= 0 and $i < 2
MC/DC100%2/2
$i >= 0 and $i < 2
$i >= 0
$i < 2
Truth table100%3/3
A and B
A= $i >= 0B= $i < 2
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 41 | ▶ | if ( $self->{call_back_on_important} and $i == 0 and $level eq 'important' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->{"call_back_on_important"} and $i == 0 and $level eq "important"
$self->{"call_back_on_important"} and $i == 0
MC/DC66%2/3
$self->{"call_back_on_important"} and $i == 0 and $level eq "important"
$self->{"call_back_on_important"}
$i == 0
$level eq "important"
Truth table75%3/4
A and B and C
A= $self->{"call_back_on_important"}B= $i == 0C= $level eq "important"
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | $cb->( $self, $data_r, $node, $element, @keys ); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | ▶ | return if $self->{bail_out}; # may be modified in callback | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | # recompute keys as they may have been modified during call-back | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | @keys = $self->{scanner}->get_keys( $node, $element ); | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 41 | ▶ | if ( $self->{call_back_on_warning} and $i == 0 and $node->fetch_element($element)->has_warning ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"call_back_on_warning"} and $i == 0 and $node->fetch_element($element)->has_warning
$self->{"call_back_on_warning"} and $i == 0
MC/DC0%0/3
$self->{"call_back_on_warning"} and $i == 0 and $node->fetch_element($element)->has_warning
$self->{"call_back_on_warning"}
$i == 0
$node->fetch_element($element)->has_warning
Truth table50%2/4
A and B and C
A= $self->{"call_back_on_warning"}B= $i == 0C= $node->fetch_element($element)->has_warning
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $logger->info("hash_element_cb found elt with warning: '", $node->name, "' element $element"); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $cb->( $self, $data_r, $node, $element, @keys ); | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 41 | ▶ | if ( $i == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 21 | ▶ | my $j = $self->{forward} == 1 ? 0 : $#keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 21 | ▶ | while ( $j >= 0 and $j < @keys ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$j >= 0 and $j < @keys
MC/DC100%2/2
$j >= 0 and $j < @keys
$j >= 0
$j < @keys
Truth table100%3/3
A and B
A= $j >= 0B= $j < @keys
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 33 | my $k = $keys[$j]; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 33 | $logger->info( "hash_element_cb (element $element) calls ", "scan_hash on key $k" ); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 33 | $self->{scanner}->scan_hash( $data_r, $node, $element, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 33 | $j += $self->{forward}; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 41 | $i += $self->{forward}; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # internal. This call-back is passed to ObjTreeScanner. It will also | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # check if the leaf element is flagged as 'important' or if the leaf | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # element contains an error (mostly undefined mandatory values) and | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # call user's call-back if needed | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 175 | ▶ | sub leaf_cb { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leaf_cb: called CC=14 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 175 | my ( $self, $scanner, $data_r, $node, $element, $index, $value_obj ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 175 | ▶ | $logger->info( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | "leaf_cb called on '", | ||||||||||||||||||||||||||||||||||||||||||
| 196 | $node->name, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | "' element '$element'", | ||||||||||||||||||||||||||||||||||||||||||
| 198 | defined $index ? ", index $index" : '' | ||||||||||||||||||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 175 | my $elt_type = $node->element_type($element); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 175 | ▶ | my $key = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | $elt_type eq 'check_list' | ||||||||||||||||||||||||||||||||||||||||||
| 204 | ? 'check_list_element' | ||||||||||||||||||||||||||||||||||||||||||
| 205 | : $value_obj->value_type . '_value'; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 175 | my $user_leaf_cb = $self->get_cb($key); | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 175 | my $level = $node->get_element_property( element => $element, property => 'level' ); | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 175 | ▶ | if ( $self->{call_back_on_important} and $level eq 'important' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"call_back_on_important"} and $level eq "important"
MC/DC50%1/2
$self->{"call_back_on_important"} and $level eq "important"
$self->{"call_back_on_important"}
$level eq "important"
Truth table66%2/3
A and B
A= $self->{"call_back_on_important"}B= $level eq "important"
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 19 | ▶ | $logger->info( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | "leaf_cb found important elt: '", | ||||||||||||||||||||||||||||||||||||||||||
| 214 | $node->name, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | "' element $element", | ||||||||||||||||||||||||||||||||||||||||||
| 216 | defined $index ? ", index $index" : '' | ||||||||||||||||||||||||||||||||||||||||||
| 217 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 19 | $user_leaf_cb->( $self, $data_r, $node, $element, $index, $value_obj ); | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 175 | ▶ | if ( $self->{call_back_on_warning} and $value_obj->warning_msg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"call_back_on_warning"} and $value_obj->warning_msg
MC/DC50%1/2
$self->{"call_back_on_warning"} and $value_obj->warning_msg
$self->{"call_back_on_warning"}
$value_obj->warning_msg
Truth table66%2/3
A and B
A= $self->{"call_back_on_warning"}B= $value_obj->warning_msg
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | $logger->info( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | "leaf_cb found elt with warning: '", | ||||||||||||||||||||||||||||||||||||||||||
| 224 | $node->name, | ||||||||||||||||||||||||||||||||||||||||||
| 225 | "' element $element", | ||||||||||||||||||||||||||||||||||||||||||
| 226 | defined $index ? ", index $index" : '' | ||||||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | $user_leaf_cb->( $self, $data_r, $node, $element, $index, $value_obj ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # now need to check for errors... | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 175 | my $result; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 175 | eval { $result = $value_obj->fetch(); }; | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 175 | my $e = $@; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 175 | ▶ | if ( ref $e and $e->isa('Config::Model::Exception::User') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
ref $e and $e->isa("Config::Model::Exception::User")
MC/DC50%1/2
ref $e and $e->isa("Config::Model::Exception::User")
ref $e
$e->isa("Config::Model::Exception::User")
Truth table66%2/3
A and B
A= ref $eB= $e->isa("Config::Model::Exception::User")
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | # ignore errors that has just been catched and call user call-back | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | ▶ | $logger->info( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | "leaf_cb oopsed on '", | ||||||||||||||||||||||||||||||||||||||||||
| 241 | $node->name, | ||||||||||||||||||||||||||||||||||||||||||
| 242 | "' element $element", | ||||||||||||||||||||||||||||||||||||||||||
| 243 | defined $index ? ", index $index" : '' | ||||||||||||||||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | $user_leaf_cb->( $self, $data_r, $node, $element, $index, $value_obj, $e->error ); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | elsif ( ref $e ) { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $e->rethrow; | |||||||||||||||||||||||||||||||||||||||||
| 249 | # does not return ... | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | elsif ($e) { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | die "Iterator failed on value object: $e"; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 175 | return; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | sub go_forward { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
go_forward: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | $logger->info("Going forward") if $self->{forward} == -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | $self->{forward} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | ▶ | sub go_backward { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
go_backward: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | $logger->info("Going backward") if $self->{forward} == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | $self->{forward} = -1; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 59 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | # ABSTRACT: Iterates forward or backward a configuration tree | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | __END__ | ||||||||||||||||||||||||||||||||||||||||||