| 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::Dumper 2.169; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 59 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 59 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 59 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 59 | ▶ | use Config::Model::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 59 | ▶ | use Config::Model::ObjTreeScanner; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 59 | ▶ | use Config::Model::Value; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 59 | ▶ | use feature qw/postderef signatures/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 59 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 154 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 154 | return bless {}, shift; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 5457 | ▶ | sub quote (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 5457 | return _quote( qr/[\s~'"#*]/, @args ); # " | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 12600 | ▶ | sub id_quote (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id_quote: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 12600 | return _quote( qr/[\s~'"@*<>.=#]/, @args ); # " )) | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 18057 | ▶ | sub _quote ($re, @res) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 18057 | foreach my $r (@res) { | |||||||||||||||||||||||||||||||||||||||||
| 37 | 18096 | ▶ | if ( defined $r and ( $r =~ /$re/ or $r eq '' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $r and $r =~ /$re/ || $r eq ""
$r =~ /$re/ or $r eq ""
MC/DC100%3/3
defined $r and $r =~ /$re/ || $r eq ""
defined $r
$r =~ /$re/
$r eq ""
Truth table100%4/4
A and B or C
A= defined $rB= $r =~ /$re/C= $r eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 343 | $r =~ s/"/\\"/g; # escape present quotes | |||||||||||||||||||||||||||||||||||||||||
| 39 | 343 | $r = '"' . $r . '"'; # add my quotes | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 18057 | ▶ | return wantarray ? @res : $res[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 6810 | ▶ | sub note_quote (@res) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
note_quote: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 6810 | foreach my $r (@res) { | |||||||||||||||||||||||||||||||||||||||||
| 47 | 6810 | ▶ | if ( defined $r and $r and ($r =~ /(\s|"|\*)/) ) { # " ))) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $r and $r and $r =~ /(\s|"|\*)/
defined $r and $r
MC/DC66%2/3
defined $r and $r and $r =~ /(\s|"|\*)/
defined $r
$r
$r =~ /(\s|"|\*)/
Truth table75%3/4
A and B and C
A= defined $rB= $rC= $r =~ /(\s|"|\*)/
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 174 | $r =~ s/"/\\"/g; # escape present quotes | |||||||||||||||||||||||||||||||||||||||||
| 49 | 174 | $r = '"' . $r . '"'; # add my quotes | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 6810 | ▶ | return wantarray ? @res : $res[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 154 | ▶ | sub dump_tree ($self, %args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_tree: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 154 | ▶ | my $full = delete $args{full_dump} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'full_dump'} || 0
MC/DC0%0/1
delete $args{'full_dump'} || 0
delete $args{'full_dump'}
Truth table50%1/2
A
A= delete $args{'full_dump'}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 154 | ▶ | my $skip_aw = delete $args{skip_auto_write} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'skip_auto_write'} || ''
MC/DC100%1/1
delete $args{'skip_auto_write'} || ''
delete $args{'skip_auto_write'}
Truth table100%2/2
A
A= delete $args{'skip_auto_write'}
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 154 | ▶ | my $auto_v = delete $args{auto_vivify} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'auto_vivify'} || 0
MC/DC100%1/1
delete $args{'auto_vivify'} || 0
delete $args{'auto_vivify'}
Truth table100%2/2
A
A= delete $args{'auto_vivify'}
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 154 | ▶ | my $mode = delete $args{mode} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'mode'} || ''
MC/DC100%1/1
delete $args{'mode'} || ''
delete $args{'mode'}
Truth table100%2/2
A
A= delete $args{'mode'}
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 154 | ▶ | if ($full) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | carp "dump_tree: full_dump parameter is deprecated, please use mode => 'user'"; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 154 | ▶ | my $check = delete $args{check} || 'yes'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'check'} || 'yes'
MC/DC100%1/1
delete $args{'check'} || 'yes'
delete $args{'check'}
Truth table100%2/2
A
A= delete $args{'check'}
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 154 | ▶ | if ( $check !~ /yes|no|skip/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | croak "dump_tree: unexpected 'check' value: $check"; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # mode parameter is slightly different from fetch's mode | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 154 | ▶ | my $fetch_mode = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | $full ? 'user' | ||||||||||||||||||||||||||||||||||||||||||
| 73 | : $mode eq 'full' ? 'user' | ||||||||||||||||||||||||||||||||||||||||||
| 74 | : $mode ? $mode | ||||||||||||||||||||||||||||||||||||||||||
| 75 | : 'custom'; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 154 | ▶ | if ( my $err = Config::Model::Value->is_bad_mode($fetch_mode) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | croak "dump_tree: $err"; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | my $node = delete $args{node} | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 154 | ▶ | || croak "dump_tree: missing 'node' parameter"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'node'} || croak(q[dump_tree: missing 'node' parameter])
MC/DC0%0/1
delete $args{'node'} || croak(q[dump_tree: missing 'node' parameter])
delete $args{'node'}
Truth table50%1/2
A
A= delete $args{'node'}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 6592 | ▶ | my $compute_pad = sub ($obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 6592 | my $depth = 0; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 6592 | ▶ | while ( defined $obj->parent ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 9590 | $depth++; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 9590 | $obj = $obj->parent; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 6592 | return ' ' x $depth; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 154 | }; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 5418 | ▶ | my $leaf_cb = sub ($scanner, $data_r, $node, $element, $index, $value_obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | # get value or only customized value | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 5418 | my $value = quote( $value_obj->fetch( mode => $fetch_mode, check => $check ) ); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 5415 | $index = id_quote($index); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 5415 | $element = id_quote($element); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 5415 | my $pad = $compute_pad->($node); | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 5415 | ▶ | my $name = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | defined $index | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ? "$element:$index" | ||||||||||||||||||||||||||||||||||||||||||
| 104 | : $element; | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # add annotation for obj contained in hash or list | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 5415 | my $note = note_quote( $value_obj->annotation ); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 5415 | ▶ | $$data_r .= "\n" . $pad . $name if defined $value or $note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value or $note
MC/DC100%2/2
defined $value or $note
defined $value
$note
Truth table100%3/3
A or B
A= defined $valueB= $note
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 5415 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 1297 | $value =~ s/\\n/\\\\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 1297 | $$data_r .= '=' . $value; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 5415 | ▶ | $$data_r .= '#' . $note if $note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 5415 | return; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 154 | }; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 42 | ▶ | my $check_list_cb = sub ($scanner, $data_r, $node, $element, $index, $value_obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | # get value or only customized value | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 42 | my $value = $value_obj->fetch( mode => $fetch_mode, check => $check ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 42 | my $qvalue = quote($value); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 42 | $element = id_quote($element); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 42 | $index = id_quote($index); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 42 | my $pad = $compute_pad->($node); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 42 | ▶ | my $name = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | defined $index | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ? "$element:$index" | ||||||||||||||||||||||||||||||||||||||||||
| 128 | : $element; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # add annotation for obj contained in hash or list | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 42 | my $note = note_quote( $value_obj->annotation ); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 42 | ▶ | $$data_r .= "\n" . $pad . $name if $value or $note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value or $note
MC/DC50%1/2
$value or $note
$value
$note
Truth table66%2/3
A or B
A= $valueB= $note
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 42 | ▶ | $$data_r .= '=' . $qvalue if $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 42 | ▶ | $$data_r .= '#' . $note if $note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 42 | return; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 154 | }; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 290 | ▶ | my $list_element_cb = sub ($scanner, $data_r, $node, $element, @keys) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 290 | my $pad = $compute_pad->($node); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 290 | my $list_obj = $node->fetch_element($element); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 290 | my $q_element = id_quote($element); | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # add annotation for list element | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 290 | my $list_note = note_quote( $list_obj->annotation ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 290 | ▶ | $$data_r .= "\n$pad$q_element#$list_note" if $list_note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 290 | ▶ | if ( $list_obj->cargo_type =~ 'node' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 34 | foreach my $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||
| 149 | 36 | $scanner->scan_list( $data_r, $node, $element, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # write value comments | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 256 | foreach my $idx ( $list_obj->fetch_all_indexes ) { | |||||||||||||||||||||||||||||||||||||||||
| 155 | 310 | my $note = $list_obj->fetch_with_id($idx)->annotation; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 310 | ▶ | $$data_r .= "\n$pad$q_element:$idx#" . note_quote($note) if $note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | # skip undef values | ||||||||||||||||||||||||||||||||||||||||||
| 160 | my @val = id_quote( | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 256 | grep { defined $_ } | |||||||||||||||||||||||||||||||||||||||||
| 162 | $list_obj->fetch_all_values(mode => $fetch_mode, check => $check) | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 256 | ▶ | $$data_r .= "\n$pad$q_element:=" . join( ',', @val ) if @val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 290 | return; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 154 | }; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 188 | ▶ | my $hash_element_cb = sub ($scanner, $data_r, $node, $element, @keys) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 188 | my $pad = $compute_pad->($node); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 188 | my $hash_obj = $node->fetch_element($element); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 188 | my $q_element = id_quote($element); | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # add annotation for list or hash element | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 188 | my $note = note_quote( $hash_obj->annotation ); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 188 | ▶ | $$data_r .= "\n$pad$q_element#$note" if $note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # resume exploration | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 188 | map { $scanner->scan_hash( $data_r, $node, $element, $_ ); } @keys; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 187 | return; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 154 | }; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | # called for nodes contained in nodes (not root). | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # This node can be held by a plain element or a hash element or a list element | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 657 | ▶ | my $node_element_cb = sub ($scanner, $data_r, $node, $element, $key, $contained_node) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 657 | my $type = $node->element_type($element); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 657 | ▶ | return if $skip_aw and $contained_node->is_auto_write_for_type($skip_aw); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$skip_aw and $contained_node->is_auto_write_for_type($skip_aw)
MC/DC0%0/2
$skip_aw and $contained_node->is_auto_write_for_type($skip_aw)
$skip_aw
$contained_node->is_auto_write_for_type($skip_aw)
Truth table66%2/3
A and B
A= $skip_awB= $contained_node->is_auto_write_for_type($skip_aw)
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 657 | my $pad = $compute_pad->($node); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 657 | my $elt = $node->fetch_element($element); | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | # load string can feature only one comment per element_type | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # ie foo#comment foo:bar#comment foo:bar=val#comment are fine | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # but foo#comment:bar if not valid -> foo#commaent foo:bar | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 657 | my $q_element = id_quote($element); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 657 | my $head = "\n$pad$q_element"; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 657 | my $node_note = note_quote( $contained_node->annotation ); | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 657 | ▶ | if ( $type eq 'list' or $type eq 'hash' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "list" or $type eq "hash"
MC/DC100%2/2
$type eq "list" or $type eq "hash"
$type eq "list"
$type eq "hash"
Truth table100%3/3
A or B
A= $type eq "list"B= $type eq "hash"
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 295 | $head .= ':' . id_quote($key); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 295 | ▶ | $head .= '#' . $node_note if $node_note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 295 | my $sub_data = ''; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 295 | $scanner->scan_node( \$sub_data, $contained_node ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 294 | $$data_r .= $head . $sub_data . ' -'; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 362 | ▶ | $head .= '#' . $node_note if $node_note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 362 | my $sub_data = ''; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 362 | $scanner->scan_node( \$sub_data, $contained_node ); | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | # skip simple nodes that do not bring data | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 362 | ▶ | $$data_r .= $head . $sub_data . ' -' if $sub_data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 656 | return; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 154 | }; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 154 | my @scan_args = ( | |||||||||||||||||||||||||||||||||||||||||
| 220 | auto_vivify => $auto_v, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | list_element_cb => $list_element_cb, | ||||||||||||||||||||||||||||||||||||||||||
| 222 | hash_element_cb => $hash_element_cb, | ||||||||||||||||||||||||||||||||||||||||||
| 223 | leaf_cb => $leaf_cb, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | node_element_cb => $node_element_cb, | ||||||||||||||||||||||||||||||||||||||||||
| 225 | check_list_element_cb => $check_list_cb, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | check => $check, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 154 | my @left = keys %args; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 154 | ▶ | croak "Dumper: unknown parameter:@left" if @left; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | # perform the scan | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 154 | my $view_scanner = Config::Model::ObjTreeScanner->new(@scan_args); | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 154 | my $ret = ''; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 154 | my $root_note = note_quote( $node->annotation ); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 154 | ▶ | $ret .= "\n#$root_note" if $root_note; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 154 | $view_scanner->scan_node( \$ret, $node ); | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 151 | substr( $ret, 0, 1, '' ); # remove leading \n | |||||||||||||||||||||||||||||||||||||||||
| 241 | 151 | ▶ | $ret .= ' -' if $ret; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 151 | return $ret . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 59 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | # ABSTRACT: Serialize data of config tree | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | __END__ | ||||||||||||||||||||||||||||||||||||||||||