TOON/Decoder.pm

filter: Statementstmt 78.4% 171 / 218 Branchbran 69.4% 82 / 118 Conditioncond 48.8% 22 / 45 MC/DCmcdc 24.1% 7 / 29 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 69.1% 292 / 422 CC 77 SCAR 36.6
CC
77
Cov
72%
_decode_root
81.2
_decode_array_value
44.4
_decode_object
15.8
CRAP 39.0
↑ Summary TOON/Encoder.pm »
1 package Data::TOON::Decoder;
2 10 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 47 ▶sub new {
Subroutine new: called CC=3 SCAR=12.0
Pod undocumented
7 47 my ($class, %opts) = @_;
8 return bless {
9 strict => $opts{strict} // 1,
10 lines => [],
11 pos => 0,
12 47 ▶ max_depth => $opts{max_depth} // 100, # Prevent DoS from deep nesting
Condition50%2/4
$opts{"strict"} // 1
l!l
047
$opts{"max_depth"} // 100
l!l
047
MC/DC0%0/1
$opts{"strict"} // 1
$opts{"strict"}
MC/DC0%0/1
$opts{"max_depth"} // 100
$opts{"max_depth"}
Truth table50%1/2
A
A= $opts{"strict"}
Aresult
11
00
Truth table50%1/2
A
A= $opts{"max_depth"}
Aresult
11
00
13 current_depth => 0,
14 }, $class;
15 }
16  
17 47 ▶sub decode {
Subroutine decode: called CC=3 SCAR=11.6
Pod undocumented
18 47 my ($self, $toon_text) = @_;
19
20 # Split into lines and remove trailing newlines
21 47 my @lines = split /\r?\n/, $toon_text;
22 47 ▶ pop @lines if @lines && $lines[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @lines and $lines[-1] eq "" 0 47 47
Condition33%1/3
@lines and $lines[-1] eq ""
!ll&&!rl&&r
0470
MC/DC0%0/2
@lines and $lines[-1] eq ""
@lines $lines[-1] eq ""
Truth table33%1/3
A and B
A= @linesB= $lines[-1] eq ""
ABresult
0X0
100
111
23
24 47 $self->{lines} = \@lines;
25 47 $self->{pos} = 0;
26
27 # Determine root form and decode
28 47 return $self->_decode_root();
29 }
30  
31 47 ▶sub _decode_root {
Subroutine _decode_root: called CC=20 SCAR=44.0
32 47 my ($self) = @_;
33
34 # Initialize position
35 47 $self->{pos} = 0;
36
37 # Find first non-empty line at depth 0
38 47 my @non_empty = ();
39 47 foreach my $line (@{$self->{lines}}) {
40 234 ▶ next if !defined $line || $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $line or $line =~ /^\s*$/u 0 234 234
Condition33%1/3
not defined $line or $line =~ /^\s*$/u
l!l&&r!l&&!r
00234
MC/DC0%0/2
not defined $line or $line =~ /^\s*$/u
not defined $line $line =~ /^\s*$/u
Truth table33%1/3
not(A) or B
A= not defined $lineB= $line =~ /^\s*$/u
ABresult
1X1
011
000
41 234 ▶ next if $self->_get_depth($line) != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_get_depth($line) != 0 181 53 234
42 53 push @non_empty, $line;
43 }
44
45 # Empty document → empty object
46 47 ▶ return {} if !@non_empty;
Branch: 1 branch
BranchTrueFalseTotal
unless @non_empty 0 47 47
47
48 47 my $first = $non_empty[0];
49
50 # Check if first line is a root array header: [N], [N|], [N\t]
51 47 ▶ if ($first =~ /^\s*\[(\d+)([\t|]?)?\]\s*:\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first =~ /^\s*\[(\d+)([\t|]?)?\]\s*:\s*(.*)$/u) 3 44 47
52 # Root array header
53 3 my $count = $1;
54 3 ▶ my $delimiter = $2 ? $2 : ',';
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 1 2 3
55 3 my $rest = $3;
56
57 # Inline values
58 3 ▶ if ($rest) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest) 3 0 3
59 3 my @values = split /\Q$delimiter\E/, $rest;
60 3 return [map { $self->_parse_primitive($_) } @values];
61 }
62
63 # Or read list items below
64 0 $self->{pos} = 0;
65 0 my @items;
66 0 ▶ while ($self->{pos} < @{$self->{lines}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pos"} < @{$self->{"lines"};}) 0 0 0
67 0 my $line = $self->{lines}->[$self->{pos}];
68
69 0 ▶ if (!$line || $line =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line or $line =~ /^\s*$/u) 0 0 0
Condition0%0/3
not $line or $line =~ /^\s*$/u
l!l&&r!l&&!r
000
MC/DC0%0/2
not $line or $line =~ /^\s*$/u
not $line $line =~ /^\s*$/u
Truth table0%0/3
not(A) or B
A= not $lineB= $line =~ /^\s*$/u
ABresult
1X1
011
000
70 0 $self->{pos}++;
71 0 next;
72 }
73
74 0 my $depth = $self->_get_depth($line);
75 0 ▶ if ($depth == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($depth == 0) { } 0 0 0
elsif ($depth > 0) { } 0 0 0
76 # Still at root - check if it's the header
77 0 ▶ if ($line =~ /^\[/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\[/u) 0 0 0
78 0 $self->{pos}++;
79 0 next; # Skip header
80 }
81 } elsif ($depth > 0) {
82 0 my $trimmed = $line;
83 0 $trimmed =~ s/^\s+//;
84 0 ▶ if ($trimmed =~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed =~ /^-/u) 0 0 0
85 # List item
86 0 $self->{pos}++;
87 0 $trimmed =~ s/^-\s+//;
88 0 push @items, $self->_parse_primitive($trimmed);
89 0 next;
90 }
91 } else {
92 0 last;
93 }
94 0 $self->{pos}++;
95 }
96 0 ▶ return \@items if @items;
Branch: 1 branch
BranchTrueFalseTotal
if @items 0 0 0
97 0 return [];
98 }
99
100 # Check if first non-empty line is an array header with key (has [N]{...}: pattern)
101 44 ▶ if ($first =~ /^\w+\[/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first =~ /^\w+\[/u) 14 30 44
102 # Object with array field - use object mode
103 14 return $self->_decode_object(0);
104 }
105
106 # Single line and it's a primitive (no colon = not key-value)
107 30 ▶ if (@non_empty == 1 && $first !~ /:/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@non_empty == 1 and not $first =~ /:/u) 10 20 30
Condition100%3/3
@non_empty == 1 and not $first =~ /:/u
!ll&&!rl&&r
31710
MC/DC100%2/2
@non_empty == 1 and not $first =~ /:/u
@non_empty == 1 not $first =~ /:/u
Truth table100%3/3
A and not(B)
A= @non_empty == 1B= not $first =~ /:/u
ABresult
0X0
100
111
108 10 return $self->_parse_primitive($first);
109 }
110
111 # Otherwise, decode as object with depth 0
112 20 return $self->_decode_object(0);
113 }
114  
115 140 ▶sub _decode_object {
Subroutine _decode_object: called CC=13 SCAR=27.6
116 140 my ($self, $target_depth) = @_;
117 140 ▶ $target_depth //= 0;
Condition50%1/2
$target_depth //= 0
l!l
1400
MC/DC0%0/1
$target_depth //= 0
$target_depth
Truth table50%1/2
A
A= $target_depth
Aresult
11
00
118
119 # Check max depth to prevent DoS
120 140 ▶ if ($target_depth > $self->{max_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_depth > $self->{"max_depth"}) 1 139 140
121 1 die "Maximum nesting depth exceeded (max: $self->{max_depth})\n";
122 }
123
124 139 my $obj = {};
125
126 139 ▶ while ($self->{pos} < @{$self->{lines}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pos"} < @{$self->{"lines"};}) 149 38 187
127 149 my $line = $self->{lines}->[$self->{pos}];
128
129 # Skip empty lines
130 149 ▶ if (!$line || $line =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line or $line =~ /^\s*$/u) 0 149 149
Condition33%1/3
not $line or $line =~ /^\s*$/u
l!l&&r!l&&!r
00149
MC/DC0%0/2
not $line or $line =~ /^\s*$/u
not $line $line =~ /^\s*$/u
Truth table33%1/3
not(A) or B
A= not $lineB= $line =~ /^\s*$/u
ABresult
1X1
011
000
131 0 $self->{pos}++;
132 0 next;
133 }
134
135 149 my $depth = $self->_get_depth($line);
136
137 # If depth is less than or equal to target, we're done with this object
138 149 ▶ if ($depth < $target_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth < $target_depth) 0 149 149
139 0 last;
140 }
141
142 # If depth is greater than target (but not target+1), skip (shouldn't happen in well-formed TOON)
143 149 ▶ if ($depth > $target_depth + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth > $target_depth + 1) 0 149 149
144 0 $self->{pos}++;
145 0 next;
146 }
147
148 # If depth is greater than target, it's a child of a nested key
149 149 ▶ if ($depth > $target_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth > $target_depth) 0 149 149
150 0 last;
151 }
152
153 149 $self->{pos}++;
154
155 # Parse key-value line
156 149 my $trimmed = $line;
157 149 $trimmed =~ s/^\s+//;
158
159 # Match patterns like:
160 # key: value
161 # key[N]: ...
162 # key[N]{fields}: ...
163 # key: (empty - nested object)
164 149 ▶ if ($trimmed =~ /^(\w+)(\[[^\]]*\])?(\{[^}]*\})?\s*:\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed =~ /^(\w+)(\[[^\]]*\])?(\{[^}]*\})?\s*:\s*(.*)$/u) 147 2 149
165 147 my ($key, $bracket, $fields, $rest) = ($1, $2, $3, $4);
166
167 # If there's a bracket segment, it's an array
168 147 ▶ if ($bracket) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bracket) { } 13 134 147
elsif (not $rest or $rest =~ /^\s*$/u) { } 106 28 134
169 13 $obj->{$key} = $self->_decode_array_value($bracket, $fields, $rest);
170 ▶ } elsif (!$rest || $rest =~ /^\s*$/) {
Condition66%2/3
not $rest or $rest =~ /^\s*$/u
l!l&&r!l&&!r
106028
MC/DC50%1/2
not $rest or $rest =~ /^\s*$/u
not $rest $rest =~ /^\s*$/u
Truth table66%2/3
not(A) or B
A= not $restB= $rest =~ /^\s*$/u
ABresult
1X1
011
000
171 # Empty value after colon = nested object
172 106 $obj->{$key} = $self->_decode_object($target_depth + 1);
173 } else {
174 # Primitive value
175 28 $obj->{$key} = $self->_parse_primitive($rest);
176 }
177 }
178 }
179
180 38 return $obj;
181 }
182  
183 13 ▶sub _decode_array_value {
Subroutine _decode_array_value: called CC=31 SCAR=37.9
184 13 my ($self, $bracket_part, $fields_part, $rest) = @_;
185
186 # Parse bracket part: [N] or [N\t] or [N|]
187 13 my $delimiter = ','; # default
188 13 ▶ if ($bracket_part =~ /^\[(\d+)([\t|])?\]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bracket_part =~ /^\[(\d+)([\t|])?\]/u) 12 1 13
189 12 my $count = $1;
190 12 ▶ if (defined $2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2) 7 5 12
191 7 $delimiter = $2;
192 }
193
194 12 ▶ if ($fields_part) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields_part) { } 7 5 12
195 # Tabular format: extract field names and parse rows
196 7 my $fields_str = $fields_part;
197 7 $fields_str =~ s/^{|}$//g;
198 7 my @fields = split /\Q$delimiter\E/, $fields_str;
199
200 7 my @rows;
201 7 ▶ while ($self->{pos} < @{$self->{lines}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pos"} < @{$self->{"lines"};}) 14 7 21
202 14 my $line = $self->{lines}->[$self->{pos}];
203
204 14 ▶ if (!$line || $line =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line or $line =~ /^\s*$/u) 0 14 14
Condition33%1/3
not $line or $line =~ /^\s*$/u
l!l&&r!l&&!r
0014
MC/DC0%0/2
not $line or $line =~ /^\s*$/u
not $line $line =~ /^\s*$/u
Truth table33%1/3
not(A) or B
A= not $lineB= $line =~ /^\s*$/u
ABresult
1X1
011
000
205 0 $self->{pos}++;
206 0 next;
207 }
208
209 14 my $depth = $self->_get_depth($line);
210 14 ▶ if ($depth <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth <= 0) 0 14 14
211 0 last;
212 }
213
214 # Check for list items (- prefix)
215 14 my $trimmed = $line;
216 14 $trimmed =~ s/^\s+//;
217 14 ▶ if ($trimmed =~ /^-\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed =~ /^-\s/u) 0 14 14
218 0 last; # List format starts here
219 }
220
221 14 $self->{pos}++;
222
223 14 my @values = split /\Q$delimiter\E/, $trimmed;
224 14 my $obj = {};
225 14 ▶ for (my $i = 0; $i < @fields && $i < @values; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @fields and $i < @values) 28 14 42
Condition100%3/3
$i < @fields and $i < @values
!ll&&!rl&&r
12228
MC/DC100%2/2
$i < @fields and $i < @values
$i < @fields $i < @values
Truth table100%3/3
A and B
A= $i < @fieldsB= $i < @values
ABresult
0X0
100
111
226 28 $obj->{$fields[$i]} = $self->_parse_primitive($values[$i]);
227 }
228 14 push @rows, $obj;
229 }
230 7 return \@rows;
231 } else {
232 # Check for list format (items starting with -)
233 # Peek ahead to see if next line (at depth+1) starts with "-"
234 5 my $has_list_format = 0;
235 5 my $peek_pos = $self->{pos};
236
237 5 ▶ while ($peek_pos < @{$self->{lines}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peek_pos < @{$self->{"lines"};}) 3 2 5
238 3 my $peek_line = $self->{lines}->[$peek_pos];
239
240 3 ▶ if (!$peek_line || $peek_line =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $peek_line or $peek_line =~ /^\s*$/u) 0 3 3
Condition33%1/3
not $peek_line or $peek_line =~ /^\s*$/u
l!l&&r!l&&!r
003
MC/DC0%0/2
not $peek_line or $peek_line =~ /^\s*$/u
not $peek_line $peek_line =~ /^\s*$/u
Truth table33%1/3
not(A) or B
A= not $peek_lineB= $peek_line =~ /^\s*$/u
ABresult
1X1
011
000
241 0 $peek_pos++;
242 0 next;
243 }
244
245 3 my $peek_depth = $self->_get_depth($peek_line);
246 3 ▶ if ($peek_depth <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peek_depth <= 0) 0 3 3
247 0 last;
248 }
249
250 3 my $peek_trimmed = $peek_line;
251 3 $peek_trimmed =~ s/^\s+//;
252
253 3 ▶ if ($peek_trimmed =~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peek_trimmed =~ /^-/u) 3 0 3
254 3 $has_list_format = 1;
255 3 last;
256 }
257
258 # If it's not empty and doesn't start with -, it's inline or not list format
259 0 last;
260 }
261
262 5 ▶ if ($has_list_format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_list_format) { } 3 2 5
263 # Parse list format items (rest of the implementation)
264 3 my @items;
265 3 ▶ while ($self->{pos} < @{$self->{lines}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pos"} < @{$self->{"lines"};}) 7 3 10
266 7 my $line = $self->{lines}->[$self->{pos}];
267
268 7 ▶ if (!$line || $line =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line or $line =~ /^\s*$/u) 0 7 7
Condition33%1/3
not $line or $line =~ /^\s*$/u
l!l&&r!l&&!r
007
MC/DC0%0/2
not $line or $line =~ /^\s*$/u
not $line $line =~ /^\s*$/u
Truth table33%1/3
not(A) or B
A= not $lineB= $line =~ /^\s*$/u
ABresult
1X1
011
000
269 0 $self->{pos}++;
270 0 next;
271 }
272
273 7 my $depth = $self->_get_depth($line);
274 7 ▶ if ($depth <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth <= 0) 0 7 7
275 0 last;
276 }
277
278 7 my $trimmed = $line;
279 7 $trimmed =~ s/^\s+//;
280
281 7 ▶ if ($trimmed =~ /^-\s(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed =~ /^-\s(.*)$/u) { } 7 0 7
282 7 $self->{pos}++;
283 7 my $item_content = $1;
284
285 # Parse first field or value
286 7 ▶ if ($item_content =~ /^(\w+):\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item_content =~ /^(\w+):\s*(.*)$/u) { } 4 3 7
287 # Object item: first field on hyphen line
288 4 my ($first_key, $first_value) = ($1, $2);
289 4 my $item = {};
290
291 4 ▶ if ($first_value =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_value =~ /^\s*$/u) { } 0 4 4
292 # Nested object - parse remaining fields at depth+2
293 0 $item->{$first_key} = $self->_decode_object($depth + 2);
294 } else {
295 # Primitive value
296 4 $item->{$first_key} = $self->_parse_primitive($first_value);
297
298 # Parse remaining fields at depth+1
299 4 ▶ while ($self->{pos} < @{$self->{lines}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pos"} < @{$self->{"lines"};}) 4 2 6
300 4 my $next_line = $self->{lines}->[$self->{pos}];
301
302 4 ▶ if (!$next_line || $next_line =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $next_line or $next_line =~ /^\s*$/u) 0 4 4
Condition33%1/3
not $next_line or $next_line =~ /^\s*$/u
l!l&&r!l&&!r
004
MC/DC0%0/2
not $next_line or $next_line =~ /^\s*$/u
not $next_line $next_line =~ /^\s*$/u
Truth table33%1/3
not(A) or B
A= not $next_lineB= $next_line =~ /^\s*$/u
ABresult
1X1
011
000
303 0 $self->{pos}++;
304 0 next;
305 }
306
307 4 my $next_depth = $self->_get_depth($next_line);
308 4 ▶ if ($next_depth < $depth + 1 || $next_depth > $depth + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_depth < $depth + 1 or $next_depth > $depth + 1) 2 2 4
Condition66%2/3
$next_depth < $depth + 1 or $next_depth > $depth + 1
l!l&&r!l&&!r
202
MC/DC50%1/2
$next_depth < $depth + 1 or $next_depth > $depth + 1
$next_depth < $depth + 1 $next_depth > $depth + 1
Truth table66%2/3
A or B
A= $next_depth < $depth + 1B= $next_depth > $depth + 1
ABresult
1X1
011
000
309 2 last;
310 }
311
312 2 my $next_trimmed = $next_line;
313 2 $next_trimmed =~ s/^\s+//;
314
315 2 ▶ if ($next_trimmed =~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_trimmed =~ /^-/u) 0 2 2
316 # Next list item
317 0 last;
318 }
319
320 2 ▶ if ($next_trimmed =~ /^(\w+):\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_trimmed =~ /^(\w+):\s*(.*)$/u) { } 2 0 2
321 2 $self->{pos}++;
322 2 $item->{$1} = $self->_parse_primitive($2);
323 } else {
324 0 last;
325 }
326 }
327 }
328
329 4 push @items, $item;
330 } else {
331 # Primitive item
332 3 push @items, $self->_parse_primitive($item_content);
333 }
334 } else {
335 0 last;
336 }
337 }
338 3 return \@items;
339 } else {
340 # Inline primitive array format: parse inline values with correct delimiter
341 2 my @values = split /\Q$delimiter\E/, $rest;
342 2 my @result = map { $self->_parse_primitive($_) } @values;
343 2 return \@result;
344 }
345 }
346 }
347
348 1 return [];
349 }
350 90 ▶sub _parse_primitive {
Subroutine _parse_primitive: called CC=11 SCAR=24.0
351 90 my ($self, $value) = @_;
352
353 90 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 90 90
354
355 90 $value =~ s/^\s+|\s+$//g;
356
357 # Handle quoted strings
358 90 ▶ if ($value =~ /^"(.*)"$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^"(.*)"$/u) 13 77 90
359 13 my $str = $1;
360 # Unescape
361 13 $str =~ s/\\"/"/g;
362 13 $str =~ s/\\\\/\\/g;
363 13 $str =~ s/\\n/\n/g;
364 13 $str =~ s/\\r/\r/g;
365 13 $str =~ s/\\t/\t/g;
366 13 return $str;
367 }
368
369 77 ▶ return undef if $value eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "null" 1 76 77
370 76 ▶ return 1 if $value eq 'true';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "true" 2 74 76
371 74 ▶ return 0 if $value eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "false" 1 73 74
372
373 # Number parsing with canonical form
374 73 ▶ if ($value =~ /^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/u) 30 43 73
375 # Reject leading zeros (except 0 itself and 0.x)
376 30 ▶ if ($value =~ /^[+-]?0\d/ && $value !~ /^[+-]?0\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^[+-]?0\d/u and not $value =~ /^[+-]?0\./u) 1 29 30
Condition66%2/3
$value =~ /^[+-]?0\d/u and not $value =~ /^[+-]?0\./u
!ll&&!rl&&r
2901
MC/DC50%1/2
$value =~ /^[+-]?0\d/u and not $value =~ /^[+-]?0\./u
$value =~ /^[+-]?0\d/u not $value =~ /^[+-]?0\./u
Truth table66%2/3
A and not(B)
A= $value =~ /^[+-]?0\d/uB= not $value =~ /^[+-]?0\./u
ABresult
0X0
100
111
377 # Leading zero - treat as string
378 1 return $value;
379 }
380
381 # Parse and normalize
382 29 my $num = 0 + $value;
383
384 # Normalize: -0 → 0, remove trailing zeros
385 29 ▶ if ($num == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num == 0) 2 27 29
386 2 return 0;
387 }
388
389 # Return normalized number
390 27 ▶ if ($num != int($num)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num != int $num) 2 25 27
391 # Float - remove trailing zeros
392 2 my $str = sprintf("%.15g", $num);
393 2 return 0 + $str;
394 }
395
396 25 return $num;
397 }
398
399 43 return $value;
400 }
401  
402 411 ▶sub _get_depth {
Subroutine _get_depth: called CC=2 SCAR=6.9
403 411 my ($self, $line) = @_;
404 411 ▶ return 0 unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 1 410 411
405 410 my $spaces = length($line) - length($line =~ s/^ +//r);
406 410 return int($spaces / 2);
407 }
408  
409 10 1;
↑ Summary TOON/Encoder.pm »