blib/lib/Datafile/Hash.pm

filter: Statementstmt 94.0% 189 / 201 Branchbran 88.6% 101 / 114 Conditioncond 85.1% 63 / 74 MC/DCmcdc 70.7% 29 / 41 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 89.1% 394 / 442 CC 102 SCAR 35.7
CC
102
Cov
91%
readhash
49.0
writehash
37.5
__ANON__
13.0
CRAP 35.4
↑ Summary
1 package Datafile::Hash;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 our @EXPORT_OK = qw(readhash writehash);
10 5 our $VERSION = '1.08';
11  
12 42 ▶sub _trim { $_[0] =~ s/^\s+|\s+$//gr if defined $_[0] && $_[1] }
Subroutine _trim: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] and $_[1] 42 0 42
Condition33%1/3
defined $_[0] and $_[1]
!ll&&!rl&&r
0042
MC/DC0%0/2
defined $_[0] and $_[1]
defined $_[0] $_[1]
Truth table33%1/3
A and B
A= defined $_[0]B= $_[1]
ABresult
0X0
100
111
13  
14 12 ▶sub readhash {
Subroutine readhash: called CC=48 SCAR=38.9
Pod documented
15 12 my ( $filename, $data, $opts ) = @_;
16 12 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
111
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
17  
18 12 ▶ my $delim = $opts->{delimiter} // '=';
Condition100%2/2
$opts->{"delimiter"} // "="
l!l
93
MC/DC100%1/1
$opts->{"delimiter"} // "="
$opts->{"delimiter"}
Truth table100%2/2
A
A= $opts->{"delimiter"}
Aresult
11
00
19 12 ▶ my $skip_empty = $opts->{skip_empty} // 1;
Condition100%2/2
$opts->{"skip_empty"} // 1
l!l
39
MC/DC100%1/1
$opts->{"skip_empty"} // 1
$opts->{"skip_empty"}
Truth table100%2/2
A
A= $opts->{"skip_empty"}
Aresult
11
00
20 12 ▶ my $skip_headers = $opts->{skip_headers} // 0;
Condition100%2/2
$opts->{"skip_headers"} // 0
l!l
39
MC/DC100%1/1
$opts->{"skip_headers"} // 0
$opts->{"skip_headers"}
Truth table100%2/2
A
A= $opts->{"skip_headers"}
Aresult
11
00
21 12 ▶ my $key_fields = $opts->{key_fields} // 1;
Condition100%2/2
$opts->{"key_fields"} // 1
l!l
48
MC/DC100%1/1
$opts->{"key_fields"} // 1
$opts->{"key_fields"}
Truth table100%2/2
A
A= $opts->{"key_fields"}
Aresult
11
00
22 12 ▶ my $comment_char = $opts->{comment_char} // '#';
Condition100%2/2
$opts->{"comment_char"} // "#"
l!l
48
MC/DC100%1/1
$opts->{"comment_char"} // "#"
$opts->{"comment_char"}
Truth table100%2/2
A
A= $opts->{"comment_char"}
Aresult
11
00
23 12 my $search = $opts->{search};
24 12 ▶ my $verbose = $opts->{verbose} // 0;
Condition100%2/2
$opts->{"verbose"} // 0
l!l
39
MC/DC100%1/1
$opts->{"verbose"} // 0
$opts->{"verbose"}
Truth table100%2/2
A
A= $opts->{"verbose"}
Aresult
11
00
25 12 ▶ my $group_mode = $opts->{group} // 2;
Condition100%2/2
$opts->{"group"} // 2
l!l
57
MC/DC100%1/1
$opts->{"group"} // 2
$opts->{"group"}
Truth table100%2/2
A
A= $opts->{"group"}
Aresult
11
00
26 12 my $ini_mode = 0;
27 12 ▶ $ini_mode = 1 if $delim eq '=';
Branch: 1 branch
BranchTrueFalseTotal
if $delim eq "=" 4 8 12
28 12 ▶ $ini_mode = 1 if $delim eq ':';
Branch: 1 branch
BranchTrueFalseTotal
if $delim eq ":" 6 6 12
29  
30 12 my @messages = ();
31 12 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 3 9 12
32 3 push @messages, "# readhash: delimiter='$delim', key_fields=$key_fields\n";
33 push @messages,
34 3 "# opts: " . join( ", ", map { "$_=$opts->{$_}" } sort keys %$opts ) . "\n";
35 }
36  
37 12 my @compiled_patterns = ();
38 12 ▶ if ( defined $search && ( ref $search || length $search ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $search and ref $search || length $search) 3 9 12
Condition66%4/6
defined $search and ref $search || length $search
!ll&&!rl&&r
903
ref $search or length $search
l!l&&r!l&&!r
120
MC/DC33%1/3
defined $search and ref $search || length $search
defined $search ref $search length $search
Truth table75%3/4
A and B or C
A= defined $searchB= ref $searchC= length $search
ABCresult
0XX0
1000
11X1
1011
39 3 ▶ my @raw = ref $search eq 'ARRAY' ? @$search : ($search);
Branch: 1 branch
BranchTrueFalseTotal
ref $search eq 'ARRAY' ? : 1 2 3
40 3 for my $pat (@raw) {
41 6 ▶ next unless defined $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pat 1 5 6
42 5 ▶ my $regex = ref $pat eq 'Regexp' ? $pat : qr/\Q$pat\E/i;
Branch: 1 branch
BranchTrueFalseTotal
ref $pat eq 'Regexp' ? : 0 5 5
43 5 push @compiled_patterns, $regex;
44 }
45 }
46 12 ▶ return (-1, [ "datafile::hash::readhash: second argument (\$data) must be a HASH reference"])
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 2 10 12
47 unless ref $data eq 'HASH';
48  
49 10 my $fh;
50 10 ▶ unless (open($fh, '<:encoding(UTF-8)', $filename)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, "<:encoding(UTF-8)", $filename) 2 8 10
51 2 return ( 0, ["WARNING: cannot open '$filename': $!"] );
52 }
53 8 %$data = ();
54  
55 8 my $entry_count = 0;
56 8 my $current_path = [];
57 8 my %structured = ();
58 8 my %groups_seen = ();
59  
60 8 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 60 8 68
61 60 ▶ next if $line =~ /^\s*\Q$comment_char\E/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*\Q$comment_char\E/u 9 51 60
62 51 ▶ if ( $skip_headers > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_headers > 0) 3 48 51
63 3 $skip_headers--;
64 3 next;
65 }
66 48 $line =~ s/[\r\n\s]+$//;
67 48 ▶ next if $skip_empty && $line eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $skip_empty and $line eq "" 4 44 48
Condition100%3/3
$skip_empty and $line eq ""
!ll&&!rl&&r
15294
MC/DC100%2/2
$skip_empty and $line eq ""
$skip_empty $line eq ""
Truth table100%3/3
A and B
A= $skip_emptyB= $line eq ""
ABresult
0X0
100
111
68  
69 44 ▶ if (@compiled_patterns) {
Branch: 1 branch
BranchTrueFalseTotal
if (@compiled_patterns) 8 36 44
70 8 my $all_matched = 1;
71 8 for my $regex (@compiled_patterns) {
72 8 ▶ $all_matched = 0 unless $line =~ $regex;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /$regex/u 8 0 8
73 8 ▶ last unless $all_matched;
Branch: 1 branch
BranchTrueFalseTotal
unless $all_matched 8 0 8
74 }
75 8 ▶ next unless $all_matched;
Branch: 1 branch
BranchTrueFalseTotal
unless $all_matched 8 0 8
76 }
77  
78 36 ▶ if ( $line =~ /^\[\s*(.+?)\s*\]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\[\s*(.+?)\s*\]$/u) 8 28 36
79 8 my $section = _trim( $1, 1 );
80 8 @$current_path = split /\./, $section;
81  
82 8 my $path = '';
83 8 for my $part (@$current_path) {
84 9 ▶ $path = $path ? "$path.$part" : $part;
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 1 8 9
85 9 $groups_seen{$path}++;
86 }
87 8 ▶ push @messages, "- entering section [$section]\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 2 6 8
88 8 next;
89 }
90  
91 28 ▶ unless ($ini_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ini_mode) { } 26 2 28
92 2 my @fields = split /\Q${delim}\E/, $line, -1;
93 2 ▶ next if @fields < $key_fields + 1;
Branch: 1 branch
BranchTrueFalseTotal
if @fields < $key_fields + 1 2 0 2
94  
95 0 my $key = join $delim, @fields[ 0 .. $key_fields - 1 ];
96 0 my $value = join $delim, @fields[ $key_fields .. $#fields ];
97 0 $data->{$key} = $value;
98 }
99 else {
100 26 ▶ if ( $key_fields > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_fields > 1) 1 25 26
101 1 push @messages,
102 "- warning: ignoring key_fields = $key_fields in INI mode\n";
103 1 $key_fields = 1;
104 }
105 26 my @fields = split /\Q$delim\E/, $line, 2;
106 26 ▶ next if @fields < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @fields < 2 9 17 26
107 17 my $key = join $delim, map { _trim( $_, 1 ) } @fields[ 0 .. $key_fields - 1 ];
108 my $value = join $delim,
109 17 map { _trim( $_, 1 ) } @fields[ $key_fields .. $#fields ];
110  
111 17 ▶ if ( $delim eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delim eq "=") 17 0 17
112 17 $value =~ s/^"(.*)"$/$1/;
113 17 $value =~ s/\\"/"/g;
114 }
115 17 my $ref = \%structured;
116 17 ▶ $ref = $data if ( $group_mode == 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $group_mode == 2 12 5 17
117 17 ▶ $ref = ( $ref->{$_} //= {} ) for @$current_path;
Condition100%2/2
$ref->{$_} //= {}
l!l
86
MC/DC100%1/1
$ref->{$_} //= {}
$ref->{$_}
Truth table100%2/2
A
A= $ref->{$_}
Aresult
11
00
118 17 $ref->{$key} = $value;
119 }
120 17 $entry_count++;
121 }
122 8 close $fh;
123  
124 8 ▶ if ( $ini_mode && $group_mode != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ini_mode and $group_mode != 2) 3 5 8
Condition100%3/3
$ini_mode and $group_mode != 2
!ll&&!rl&&r
233
MC/DC100%2/2
$ini_mode and $group_mode != 2
$ini_mode $group_mode != 2
Truth table100%3/3
A and B
A= $ini_modeB= $group_mode != 2
ABresult
0X0
100
111
125 3 my $flatten;
126 3 ▶ $flatten = sub {
Subroutine __ANON__: called CC=6 SCAR=18.8
127 3 my ( $hash, $prefix ) = @_;
128 3 for my $k ( sort keys %$hash ) {
129 5 my $v = $hash->{$k};
130 5 ▶ my $full =
Branch: 1 branch
BranchTrueFalseTotal
$group_mode == 1 && $prefix ne '' ? : 0 5 5
Condition66%2/3
$group_mode == 1 and $prefix ne ""
!ll&&!rl&&r
320
MC/DC0%0/2
$group_mode == 1 and $prefix ne ""
$group_mode == 1 $prefix ne ""
Truth table66%2/3
A and B
A= $group_mode == 1B= $prefix ne ""
ABresult
0X0
100
111
131 ( $group_mode == 1 && $prefix ne '' ) ? "$prefix.$k" : $k;
132 5 ▶ if ( ref $v eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'HASH') { } 0 5 5
133 0 $flatten->( $v, $full );
134 }
135 else {
136 5 ▶ $data->{ $group_mode == 0 ? $k : $full } = $v;
Branch: 1 branch
BranchTrueFalseTotal
$group_mode == 0 ? : 3 2 5
137 }
138 }
139 3 };
140 3 $flatten->( \%structured, '' );
141 }
142  
143 8 ▶ if ( $verbose && $ini_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose and $ini_mode) 2 6 8
Condition100%3/3
$verbose and $ini_mode
!ll&&!rl&&r
512
MC/DC100%2/2
$verbose and $ini_mode
$verbose $ini_mode
Truth table100%3/3
A and B
A= $verboseB= $ini_mode
ABresult
0X0
100
111
144 2 push @messages, "- groups: " . join( ',', sort keys %groups_seen ) . "\n";
145 }
146 8 ▶ push @messages, "- $entry_count data records read from $filename\n"
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 3 5 8
147 if $verbose;
148  
149 8 return ( $entry_count, \@messages, \%groups_seen );
150 }
151  
152 13 ▶sub writehash {
Subroutine writehash: called CC=36 SCAR=36.2
Pod documented
153 13 my ( $filename, $hash, $opts ) = @_;
154 13 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
121
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
155  
156 13 ▶ my $delim = $opts->{delimiter} // '=';
Condition100%2/2
$opts->{"delimiter"} // "="
l!l
85
MC/DC100%1/1
$opts->{"delimiter"} // "="
$opts->{"delimiter"}
Truth table100%2/2
A
A= $opts->{"delimiter"}
Aresult
11
00
157 13 ▶ my $comment_char = $opts->{comment_char} // '#';
Condition100%2/2
$opts->{"comment_char"} // "#"
l!l
211
MC/DC100%1/1
$opts->{"comment_char"} // "#"
$opts->{"comment_char"}
Truth table100%2/2
A
A= $opts->{"comment_char"}
Aresult
11
00
158 13 ▶ my $prot = $opts->{prot} // 0660;
Condition100%2/2
$opts->{"prot"} // 432
l!l
67
MC/DC100%1/1
$opts->{"prot"} // 432
$opts->{"prot"}
Truth table100%2/2
A
A= $opts->{"prot"}
Aresult
11
00
159 13 ▶ my $backup = $opts->{backup} // 0;
Condition100%2/2
$opts->{"backup"} // 0
l!l
76
MC/DC100%1/1
$opts->{"backup"} // 0
$opts->{"backup"}
Truth table100%2/2
A
A= $opts->{"backup"}
Aresult
11
00
160 13 ▶ my $verbose = $opts->{verbose} // 0;
Condition100%2/2
$opts->{"verbose"} // 0
l!l
58
MC/DC100%1/1
$opts->{"verbose"} // 0
$opts->{"verbose"}
Truth table100%2/2
A
A= $opts->{"verbose"}
Aresult
11
00
161 13 my $ini_mode = 0;
162 13 ▶ $ini_mode = 1 if $delim eq '=';
Branch: 1 branch
BranchTrueFalseTotal
if $delim eq "=" 6 7 13
163 13 ▶ $ini_mode = 1 if $delim eq ':';
Branch: 1 branch
BranchTrueFalseTotal
if $delim eq ":" 2 11 13
164  
165 13 ▶ unless ( $hash && ref $hash eq 'HASH' && keys %$hash ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash and ref $hash eq "HASH" and keys %$hash) 3 10 13
Condition66%4/6
$hash and ref $hash eq "HASH" and keys %$hash
!ll&&!rl&&r
3010
$hash and ref $hash eq "HASH"
!ll&&!rl&&r
3010
MC/DC33%1/3
$hash and ref $hash eq "HASH" and keys %$hash
$hash ref $hash eq "HASH" keys %$hash
Truth table50%2/4
A and B and C
A= $hashB= ref $hash eq "HASH"C= keys %$hash
ABCresult
0XX0
10X0
1100
1111
166 3 ▶ unlink($filename) if -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
if -f $filename 2 1 3
167 3 return(0, ["datafile::hash::writehash: second argument (\$data) must be a HASH reference"] );
168 }
169  
170 10 my $tmp = "$filename.tmp";
171 10 my @messages = ();
172 10 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 5 5 10
173 5 push @messages, "# writehash: delimiter='$delim'\n";
174 push @messages,
175 5 "# opts: " . join( ", ", map { "$_=$opts->{$_}" } sort keys %$opts ) . "\n";
176 }
177  
178 10 my $fh;
179 10 ▶ unless (open( $fh, '>:encoding(UTF-8):crlf', $tmp)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, ">:encoding(UTF-8):crlf", $tmp) 1 9 10
180 1 return ( 0, ["ERROR: cannot open '$tmp' for writing: $!"] );
181 }
182  
183 9 ▶ if ( my $comment = $opts->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comment = $opts->{"comment"}) 3 6 9
184 3 ▶ my @lines = ref $comment eq 'ARRAY' ? @$comment : split /\n/, $comment;
Branch: 1 branch
BranchTrueFalseTotal
ref $comment eq 'ARRAY' ? : 1 2 3
185 3 print $fh "$comment_char $_\n" for @lines;
186 3 ▶ if ($verbose) { push @messages, "> $comment_char $_\n" for @lines; }
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 1 2 3
187 }
188  
189 9 my $entry_count = 0;
190  
191 9 ▶ unless ($ini_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ini_mode) { } 7 2 9
192 2 for my $k ( keys %$hash ) {
193 6 my $v = $hash->{$k};
194 6 print $fh "$k$delim$v\n";
195 6 $entry_count++;
196 }
197 }
198 else {
199 7 my $first_section = 1;
200 7 my %data = %$hash;
201 7 my $has_real_nested = grep { ref $data{$_} eq 'HASH' } keys %data;
202  
203 7 ▶ if ( !$has_real_nested && grep /\./, keys %data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_real_nested and grep /\./u, keys %data) 0 7 7
Condition66%2/3
not $has_real_nested and grep /\./u, keys %data
!ll&&!rl&&r
430
MC/DC0%0/2
not $has_real_nested and grep /\./u, keys %data
not $has_real_nested grep /\./u, keys %data
Truth table66%2/3
not(A) and B
A= not $has_real_nestedB= grep /\./u, keys %data
ABresult
0X0
100
111
204 0 my %nested;
205 0 ▶ while ( my ( $k, $v ) = each %data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %data) 0 0 0
206 0 my @p = split /\./, $k;
207 0 my $r = \%nested;
208 0 ▶ $r = ( $r->{$_} //= {} ) for @p[ 0 .. $#p - 1 ];
Condition0%0/2
$r->{$_} //= {}
l!l
00
MC/DC0%0/1
$r->{$_} //= {}
$r->{$_}
Truth table0%0/2
A
A= $r->{$_}
Aresult
11
00
209 0 $r->{ $p[-1] } = $v;
210 }
211 0 %data = %nested;
212 0 $has_real_nested = 1;
213 }
214  
215 7 my %global_data;
216 7 for my $k ( keys %data ) {
217 20 ▶ next if ref $data{$k} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data{$k} eq "HASH" 11 9 20
218 9 $global_data{$k} = delete $data{$k};
219 }
220 7 my $write_section;
221 15 ▶ $write_section = sub {
Subroutine __ANON__: called CC=13 SCAR=25.7
222 15 my ( $cur, $path ) = @_;
223 15 ▶ my $name = @$path ? join( '.', @$path ) : '';
Branch: 1 branch
BranchTrueFalseTotal
@$path ? : 12 3 15
224  
225 15 ▶ print $fh "\n" unless ($first_section);
Branch: 1 branch
BranchTrueFalseTotal
unless $first_section 8 7 15
226 15 $first_section = 0;
227 15 ▶ if ( $name ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne "") 12 3 15
228 12 print $fh "[$name]\n";
229 12 ▶ push @messages, "> [$name]\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 3 9 12
230 }
231  
232 15 my $maxsize = 0;
233 15 for my $k ( sort grep { !ref $cur->{$_} } keys %$cur ) {
234 35 ▶ $maxsize = length($k) if length($k) > $maxsize;
Branch: 1 branch
BranchTrueFalseTotal
if length $k > $maxsize 20 15 35
235 }
236 15 for my $k ( sort grep { !ref $cur->{$_} } keys %$cur ) {
237 35 my $v = $cur->{$k};
238 35 ▶ my $needs_quoting =
Condition83%5/6
$v =~ /[#"'\r\n]/u || $v =~ /^\s+|\s+$/u || $v eq ''
l!l&&r!l&&!r
3230
$v =~ /[#"'\r\n]/u or $v =~ /^\s+|\s+$/u
l!l&&r!l&&!r
3032
MC/DC66%2/3
$v =~ /[#"'\r\n]/u || $v =~ /^\s+|\s+$/u || $v eq ''
$v =~ /[#"'\r\n]/u $v =~ /^\s+|\s+$/u $v eq ''
Truth table75%3/4
A or B || C
A= $v =~ /[#"'\r\n]/uB= $v =~ /^\s+|\s+$/uC= $v eq ''
ABCresult
1XX1
01X1
0011
0000
239 ( $v =~ /[#"'\r\n]/ || $v =~ /^\s+|\s+$/ || $v eq '' );
240 35 ▶ if ( $delim eq '=' && $needs_quoting ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delim eq "=" and $needs_quoting) 5 30 35
Condition100%3/3
$delim eq "=" and $needs_quoting
!ll&&!rl&&r
3275
MC/DC100%2/2
$delim eq "=" and $needs_quoting
$delim eq "=" $needs_quoting
Truth table100%3/3
A and B
A= $delim eq "="B= $needs_quoting
ABresult
0X0
100
111
241 5 $v =~ s/"/\\"/g;
242 5 $v = qq("$v");
243 }
244 35 my $line = sprintf "%-*s %s %s", $maxsize, $k, $delim, $v;
245 35 print $fh "$line\n";
246 35 $entry_count++;
247 }
248  
249 15 for my $sub ( sort grep { ref $cur->{$_} eq 'HASH' } keys %$cur ) {
250 1 $write_section->( $cur->{$sub}, [ @$path, $sub ] );
251 }
252 7 };
253  
254 7 ▶ if ( keys %global_data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %global_data) 3 4 7
255 3 $write_section->( \%global_data, [] );
256 }
257 7 for my $top ( sort keys %data ) {
258 11 $write_section->( $data{$top}, [$top] );
259 }
260 }
261 9 ▶ print $fh "#EOF\n" if $comment_char eq '#';
Branch: 1 branch
BranchTrueFalseTotal
if $comment_char eq "#" 8 1 9
262 9 close $fh;
263  
264 9 ▶ if ( $backup && -f $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($backup and -f $filename) 2 7 9
Condition100%3/3
$backup and -f $filename
!ll&&!rl&&r
612
MC/DC100%2/2
$backup and -f $filename
$backup -f $filename
Truth table100%3/3
A and B
A= $backupB= -f $filename
ABresult
0X0
100
111
265 2 rename( $filename, $filename . '.bak' );
266 }
267 9 ▶ rename( $tmp, $filename )
Branch: 1 branch
BranchTrueFalseTotal
rename $tmp, $filename or return 0, ["ERROR: failed to rename '${tmp}' to '${filename}': $!"] 9 0 9
268 or return ( 0, ["ERROR: failed to rename '$tmp' to '$filename': $!"] );
269 9 chmod $prot, $filename;
270  
271 9 ▶ push @messages, "- $entry_count entries written to $filename\n"
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 5 4 9
272 if $verbose;
273 9 return ( $entry_count, \@messages );
274 }
275  
276 5 1;
277  
278 __END__
↑ Summary