lib/Yote/YapiServer/YapiDef.pm

filter: Statementstmt 92.3% 242 / 262 Branchbran 79.0% 87 / 110 Conditioncond 63.9% 39 / 61 MC/DCmcdc 41.6% 15 / 36 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 15 totaltotal 79.8% 400 / 501 CC 82 SCAR 22.9
CC
82
Cov
85%
brace_delta
17.5
parse_block_content
12.7
parse_code_block
10.4
CRAP 9.8
« lib/Yote/YapiServer/App/Base.pm ↑ Summary lib/Yote/YapiServer/Site.pm »
1 package Yote::YapiServer::YapiDef;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #======================================================================
7 # Public API
8 #======================================================================
9  
10 # Parse a .ydef file and return an arrayref of definition hashrefs,
11 # each matching the structure that YAML::LoadFile would produce.
12 sub parse_file {
13 4 ▶ my ($filename) = @_;
Subroutine parse_file: called CC=2 SCAR=7.0
Pod undocumented
14 4 ▶ open my $fh, '<', $filename or die "Cannot open $filename: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die "Cannot open ${filename}: $!\n" 0 4 4
15 4 my $text = do { local $/; <$fh> };
16 4 close $fh;
17 4 return parse_string($text, $filename);
18 }
19  
20 sub parse_string {
21 9 ▶ my ($text, $source) = @_;
Subroutine parse_string: called CC=10 SCAR=23.0
Pod undocumented
22 9 ▶ $source //= '<string>';
Condition100%2/2
$source //= "<string>"
l!l
45
MC/DC100%1/1
$source //= "<string>"
$source
Truth table100%2/2
A
A= $source
Aresult
11
00
23  
24 9 my @lines = split /\n/, $text;
25 9 my $pos = 0;
26 9 my @defs;
27 my $current_app; # when inside an app block, nested objects attach here
28  
29 9 ▶ while ($pos <= $#lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $#lines) 22 9 31
30 22 my $line = $lines[$pos];
31  
32 # Skip blank lines and comments
33 22 ▶ if ($line =~ /^\s*$/ || $line =~ /^\s*#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/ or $line =~ /^\s*#/) 7 15 22
Condition100%3/3
$line =~ /^\s*$/ or $line =~ /^\s*#/
l!l&&r!l&&!r
6115
MC/DC100%2/2
$line =~ /^\s*$/ or $line =~ /^\s*#/
$line =~ /^\s*$/ $line =~ /^\s*#/
Truth table100%3/3
A or B
A= $line =~ /^\s*$/B= $line =~ /^\s*#/
ABresult
1X1
011
000
34 7 $pos++;
35 7 next;
36 }
37  
38 # app PACKAGE {
39 15 ▶ if ($line =~ /^\s*app\s+(\S+)\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*app\s+(\S+)\s*\{/) 6 9 15
40 6 my $pkg = $1;
41 6 my ($block, $new_pos) = parse_block(\@lines, $pos + 1);
42 6 my $def = process_app_block($block, $pkg);
43 6 push @defs, $def;
44 6 $current_app = $def;
45 6 $pos = $new_pos;
46 6 next;
47 }
48  
49 # object NAME { ... } — standalone or after app
50 9 ▶ if ($line =~ /^\s*object\s+(\S+)\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*object\s+(\S+)\s*\{/) 7 2 9
51 7 my $name = $1;
52 7 my ($block, $new_pos) = parse_block(\@lines, $pos + 1);
53 7 ▶ if ($current_app && $name !~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_app and not $name =~ /::/) { } 6 1 7
Condition66%2/3
$current_app and not $name =~ /::/
!ll&&!rl&&r
106
MC/DC50%1/2
$current_app and not $name =~ /::/
$current_app not $name =~ /::/
Truth table66%2/3
A and not(B)
A= $current_appB= not $name =~ /::/
ABresult
0X0
100
111
54 # Nested object — attach to the current app
55 6 my $obj_def = process_object_block($block);
56 6 $current_app->{objects}{$name} = $obj_def;
57 } else {
58 # Standalone object
59 1 my $def = process_object_block($block);
60 1 $def->{type} = 'object';
61 1 $def->{package} = $name;
62 1 push @defs, $def;
63 }
64 7 $pos = $new_pos;
65 7 next;
66 }
67  
68 # server PACKAGE {
69 2 ▶ if ($line =~ /^\s*server\s+(\S+)\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*server\s+(\S+)\s*\{/) 2 0 2
70 2 my $pkg = $1;
71 2 my ($block, $new_pos) = parse_block(\@lines, $pos + 1);
72 2 my $def = process_server_block($block, $pkg);
73 2 push @defs, $def;
74 2 $current_app = undef;
75 2 $pos = $new_pos;
76 2 next;
77 }
78  
79 # Anything else at top level is unexpected
80 0 die "Parse error in $source at line " . ($pos + 1) . ": unexpected '$line'\n";
81 }
82  
83 9 return \@defs;
84 }
85  
86 #======================================================================
87 # Block parsing — read lines until matching closing brace
88 #======================================================================
89  
90 # Returns (arrayref of lines inside the block, next position after closing brace)
91 sub parse_block {
92 47 ▶ my ($lines, $pos) = @_;
Subroutine parse_block: called CC=5 SCAR=16.3
Pod undocumented
93 47 my @block;
94 47 my $depth = 1;
95  
96 47 ▶ while ($pos <= $#$lines && $depth > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $lines->$#* and $depth > 0) 1026 0 1026
Condition33%1/3
$pos <= $lines->$#* and $depth > 0
!ll&&!rl&&r
001026
MC/DC0%0/2
$pos <= $lines->$#* and $depth > 0
$pos <= $lines->$#* $depth > 0
Truth table33%1/3
A and B
A= $pos <= $lines->$#*B= $depth > 0
ABresult
0X0
100
111
97 1026 my $line = $lines->[$pos];
98 1026 my $delta = brace_delta($line);
99 1026 $depth += $delta;
100  
101 1026 ▶ if ($depth <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth <= 0) 47 979 1026
102 # The closing brace line — capture any content before the }
103 47 my $before = $line;
104 47 $before =~ s/\}\s*$//;
105 47 ▶ push @block, $before if $before =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $before =~ /\S/ 0 47 47
106 47 $pos++;
107 47 last;
108 }
109  
110 979 push @block, $line;
111 979 $pos++;
112 }
113  
114 47 return (\@block, $pos);
115 }
116  
117 # Count net brace depth change on a line, skipping braces in strings and comments
118 sub brace_delta {
119 1708 ▶ my ($line) = @_;
Subroutine brace_delta: called CC=17 SCAR=28.6
Pod undocumented
120 1708 my $delta = 0;
121 1708 my ($in_sq, $in_dq) = (0, 0);
122  
123 1708 for my $i (0 .. length($line) - 1) {
124 42618 my $ch = substr($line, $i, 1);
125 42618 ▶ my $prev = $i > 0 ? substr($line, $i - 1, 1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 41184 1434 42618
126  
127 # Comment — stop counting (but $# is Perl's array-last-index, not a comment)
128 42618 ▶ last if $ch eq '#' && !$in_sq && !$in_dq && $prev ne '$';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "#" and not $in_sq and not $in_dq and $prev ne "\$" 95 42523 42618
Condition77%7/9
$ch eq "#" and not $in_sq and not $in_dq and $prev ne "\$"
!ll&&!rl&&r
424992495
$ch eq "#" and not $in_sq and not $in_dq
!ll&&!rl&&r
424990119
$ch eq "#" and not $in_sq
!ll&&!rl&&r
424990119
MC/DC50%2/4
$ch eq "#" and not $in_sq and not $in_dq and $prev ne "\$"
$ch eq "#" not $in_sq not $in_dq $prev ne "\$"
Truth table60%3/5
A and not(B) and not(C) and D
A= $ch eq "#"B= not $in_sqC= not $in_dqD= $prev ne "\$"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
129  
130 42523 ▶ if ($ch eq "'" && !$in_dq && $prev ne '\\') { $in_sq = !$in_sq }
Branch: 3 branches
BranchTrueFalseTotal
if ($ch eq q['] and not $in_dq and $prev ne '\\') { } 60 42463 42523
elsif ($ch eq '"' and not $in_sq and $prev ne '\\') { } 224 42239 42463
elsif (not $in_sq || $in_dq) { } 38635 3604 42239
Condition66%4/6
$ch eq "'" and not $in_dq and $prev ne "\\"
!ll&&!rl&&r
42463060
$ch eq "'" and not $in_dq
!ll&&!rl&&r
42463060
MC/DC33%1/3
$ch eq "'" and not $in_dq and $prev ne "\\"
$ch eq "'" not $in_dq $prev ne "\\"
Truth table50%2/4
A and not(B) and C
A= $ch eq "'"B= not $in_dqC= $prev ne "\\"
ABCresult
0XX0
10X0
1100
1111
131 224 ▶ elsif ($ch eq '"' && !$in_sq && $prev ne '\\') { $in_dq = !$in_dq }
Condition66%4/6
$ch eq "\"" and not $in_sq and $prev ne "\\"
!ll&&!rl&&r
422390224
$ch eq "\"" and not $in_sq
!ll&&!rl&&r
422390224
MC/DC33%1/3
$ch eq "\"" and not $in_sq and $prev ne "\\"
$ch eq "\"" not $in_sq $prev ne "\\"
Truth table50%2/4
A and not(B) and C
A= $ch eq "\""B= not $in_sqC= $prev ne "\\"
ABCresult
0XX0
10X0
1100
1111
132 ▶ elsif (!$in_sq && !$in_dq) {
Condition100%3/3
$in_sq || $in_dq
l!l&&r!l&&!r
786281838635
MC/DC100%2/2
$in_sq || $in_dq
$in_sq $in_dq
Truth table100%3/3
A || B
A= $in_sqB= $in_dq
ABresult
1X1
011
000
133 38635 ▶ $delta++ if $ch eq '{';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "{" 338 38297 38635
134 38635 ▶ $delta-- if $ch eq '}';
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "}" 385 38250 38635
135 }
136 }
137  
138 1708 return $delta;
139 }
140  
141 #======================================================================
142 # Process top-level block types
143 #======================================================================
144  
145 sub process_app_block {
146 6 ▶ my ($block_lines, $pkg) = @_;
Subroutine process_app_block: called CC=1 SCAR=0.0
Pod undocumented
147 6 my $def = {
148 type => 'app',
149 package => $pkg,
150 };
151 6 parse_block_content($block_lines, $def);
152 6 return $def;
153 }
154  
155 sub process_object_block {
156 7 ▶ my ($block_lines) = @_;
Subroutine process_object_block: called CC=1 SCAR=0.0
Pod undocumented
157 7 my $def = {};
158 7 parse_block_content($block_lines, $def);
159 7 return $def;
160 }
161  
162 sub process_server_block {
163 2 ▶ my ($block_lines, $pkg) = @_;
Subroutine process_server_block: called CC=1 SCAR=0.0
Pod undocumented
164 2 my $def = {
165 type => 'server',
166 package => $pkg,
167 };
168 2 parse_server_content($block_lines, $def);
169 2 return $def;
170 }
171  
172 #======================================================================
173 # Parse block content (app or object interior)
174 #======================================================================
175  
176 sub parse_block_content {
177 13 ▶ my ($lines, $def) = @_;
Subroutine parse_block_content: called CC=12 SCAR=25.5
Pod undocumented
178 13 my $pos = 0;
179  
180 13 ▶ while ($pos <= $#$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $lines->$#*) 95 13 108
181 95 my $line = $lines->[$pos];
182  
183 # Skip blank lines and comments
184 95 ▶ if ($line =~ /^\s*$/ || $line =~ /^\s*#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/ or $line =~ /^\s*#/) 43 52 95
Condition100%3/3
$line =~ /^\s*$/ or $line =~ /^\s*#/
l!l&&r!l&&!r
42152
MC/DC100%2/2
$line =~ /^\s*$/ or $line =~ /^\s*#/
$line =~ /^\s*$/ $line =~ /^\s*#/
Truth table100%3/3
A or B
A= $line =~ /^\s*$/B= $line =~ /^\s*#/
ABresult
1X1
011
000
185 43 $pos++;
186 43 next;
187 }
188  
189 # cols { ... }
190 52 ▶ if ($line =~ /^\s*cols\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*cols\s*\{/) 11 41 52
191 11 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
192 11 $def->{cols} = parse_key_value_lines($inner);
193 11 $pos = $new_pos;
194 11 next;
195 }
196  
197 # field_access { ... }
198 41 ▶ if ($line =~ /^\s*field_access\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*field_access\s*\{/) 10 31 41
199 10 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
200 10 $def->{field_access} = parse_key_value_lines($inner);
201 10 $pos = $new_pos;
202 10 next;
203 }
204  
205 # values { ... } → public_vars
206 31 ▶ if ($line =~ /^\s*values\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*values\s*\{/) 4 27 31
207 4 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
208 4 $def->{public_vars} = parse_values_block($inner);
209 4 $pos = $new_pos;
210 4 next;
211 }
212  
213 # vars { ... }
214 27 ▶ if ($line =~ /^\s*vars\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*vars\s*\{/) 3 24 27
215 3 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
216 3 $def->{vars} = parse_values_block($inner);
217 3 $pos = $new_pos;
218 3 next;
219 }
220  
221 # uses { ... }
222 24 ▶ if ($line =~ /^\s*uses\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*uses\s*\{/) 0 24 24
223 0 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
224 0 $def->{uses} = parse_uses_block($inner);
225 0 $pos = $new_pos;
226 0 next;
227 }
228  
229 # method ACCESS NAME { CODE }
230 24 ▶ if ($line =~ /^\s*method\s+(\S+)\s+(\w+)\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*method\s+(\S+)\s+(\w+)\s*\{/) 20 4 24
231 20 my ($access_str, $name) = ($1, $2);
232 20 my ($code_lines, $new_pos) = parse_code_block($lines, $pos);
233 20 my $code = join("\n", @$code_lines);
234  
235 20 my $access = parse_access($access_str);
236  
237 20 $def->{methods}{$name} = {
238 access => $access,
239 code => $code,
240 };
241 20 $pos = $new_pos;
242 20 next;
243 }
244  
245 # sub NAME { CODE }
246 4 ▶ if ($line =~ /^\s*sub\s+(\w+)\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*sub\s+(\w+)\s*\{/) 4 0 4
247 4 my $name = $1;
248 4 my ($code_lines, $new_pos) = parse_code_block($lines, $pos);
249 4 my $code = join("\n", @$code_lines);
250 4 $def->{subs}{$name} = $code;
251 4 $pos = $new_pos;
252 4 next;
253 }
254  
255 # base PACKAGE (single line, no braces)
256 0 ▶ if ($line =~ /^\s*base\s+(\S+)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*base\s+(\S+)\s*$/) 0 0 0
257 0 $def->{base} = $1;
258 0 $pos++;
259 0 next;
260 }
261  
262 # Fallthrough — skip unrecognized content
263 0 $pos++;
264 }
265 }
266  
267 #======================================================================
268 # Parse server content
269 #======================================================================
270  
271 sub parse_server_content {
272 2 ▶ my ($lines, $def) = @_;
Subroutine parse_server_content: called CC=8 SCAR=21.3
Pod undocumented
273 2 my $pos = 0;
274  
275 2 ▶ while ($pos <= $#$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $lines->$#*) 10 2 12
276 10 my $line = $lines->[$pos];
277  
278 10 ▶ if ($line =~ /^\s*$/ || $line =~ /^\s*#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/ or $line =~ /^\s*#/) 4 6 10
Condition66%2/3
$line =~ /^\s*$/ or $line =~ /^\s*#/
l!l&&r!l&&!r
406
MC/DC50%1/2
$line =~ /^\s*$/ or $line =~ /^\s*#/
$line =~ /^\s*$/ $line =~ /^\s*#/
Truth table66%2/3
A or B
A= $line =~ /^\s*$/B= $line =~ /^\s*#/
ABresult
1X1
011
000
279 4 $pos++;
280 4 next;
281 }
282  
283 # cols { ... }
284 6 ▶ if ($line =~ /^\s*cols\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*cols\s*\{/) 0 6 6
285 0 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
286 0 $def->{cols} = parse_key_value_lines($inner);
287 0 $pos = $new_pos;
288 0 next;
289 }
290  
291 # apps { ... }
292 6 ▶ if ($line =~ /^\s*apps\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*apps\s*\{/) 2 4 6
293 2 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
294 2 $def->{apps} = parse_key_value_lines($inner);
295 2 $pos = $new_pos;
296 2 next;
297 }
298  
299 # uses { ... }
300 4 ▶ if ($line =~ /^\s*uses\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*uses\s*\{/) 2 2 4
301 2 my ($inner, $new_pos) = parse_block($lines, $pos + 1);
302 2 $def->{uses} = parse_uses_block($inner);
303 2 $pos = $new_pos;
304 2 next;
305 }
306  
307 # base PACKAGE
308 2 ▶ if ($line =~ /^\s*base\s+(\S+)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*base\s+(\S+)\s*$/) 2 0 2
309 2 $def->{base} = $1;
310 2 $pos++;
311 2 next;
312 }
313  
314 0 $pos++;
315 }
316 }
317  
318 #======================================================================
319 # Parse inner block formats
320 #======================================================================
321  
322 # Simple key-value: "key rest_of_line"
323 sub parse_key_value_lines {
324 23 ▶ my ($lines) = @_;
Subroutine parse_key_value_lines: called CC=5 SCAR=16.2
Pod undocumented
325 23 my %kv;
326 23 for my $line (@$lines) {
327 68 ▶ next if $line =~ /^\s*$/ || $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ or $line =~ /^\s*#/ 1 67 68
Condition66%2/3
$line =~ /^\s*$/ or $line =~ /^\s*#/
l!l&&r!l&&!r
0167
MC/DC50%1/2
$line =~ /^\s*$/ or $line =~ /^\s*#/
$line =~ /^\s*$/ $line =~ /^\s*#/
Truth table66%2/3
A or B
A= $line =~ /^\s*$/B= $line =~ /^\s*#/
ABresult
1X1
011
000
328 67 ▶ if ($line =~ /^\s*(\S+)\s+(.+?)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(\S+)\s+(.+?)\s*$/) 67 0 67
329 67 $kv{$1} = $2;
330 }
331 }
332 23 return \%kv;
333 }
334  
335 # Values block: key value, with support for multi-line quoted strings
336 sub parse_values_block {
337 7 ▶ my ($lines) = @_;
Subroutine parse_values_block: called CC=9 SCAR=22.3
Pod undocumented
338 7 my %kv;
339 7 my $pos = 0;
340  
341 7 ▶ while ($pos <= $#$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $lines->$#*) 20 7 27
342 20 my $line = $lines->[$pos];
343  
344 20 ▶ if ($line =~ /^\s*$/ || $line =~ /^\s*#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/ or $line =~ /^\s*#/) 0 20 20
Condition33%1/3
$line =~ /^\s*$/ or $line =~ /^\s*#/
l!l&&r!l&&!r
0020
MC/DC0%0/2
$line =~ /^\s*$/ or $line =~ /^\s*#/
$line =~ /^\s*$/ $line =~ /^\s*#/
Truth table33%1/3
A or B
A= $line =~ /^\s*$/B= $line =~ /^\s*#/
ABresult
1X1
011
000
345 0 $pos++;
346 0 next;
347 }
348  
349 # key "multi-line value..."
350 20 ▶ if ($line =~ /^\s*(\S+)\s+"(.*?)"\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(\S+)\s+"(.*?)"\s*$/) 3 17 20
351 # Single-line quoted value (complete on one line)
352 3 $kv{$1} = $2;
353 3 $pos++;
354 3 next;
355 }
356  
357 17 ▶ if ($line =~ /^\s*(\S+)\s+"(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(\S+)\s+"(.*)$/) 1 16 17
358 # Multi-line quoted value — opening quote without closing
359 1 my $key = $1;
360 1 my $val = $2;
361 1 $pos++;
362 1 ▶ while ($pos <= $#$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $lines->$#*) 2 0 2
363 2 my $next = $lines->[$pos];
364 2 ▶ if ($next =~ /^(.*?)"\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next =~ /^(.*?)"\s*$/) { } 1 1 2
365 1 $val .= "\n" . $1;
366 1 $pos++;
367 1 last;
368 } else {
369 1 $val .= "\n" . $next;
370 1 $pos++;
371 }
372 }
373 1 $kv{$key} = $val;
374 1 next;
375 }
376  
377 # Unquoted: key rest_of_line
378 16 ▶ if ($line =~ /^\s*(\S+)\s+(.+?)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(\S+)\s+(.+?)\s*$/) 16 0 16
379 16 $kv{$1} = $2;
380 }
381  
382 16 $pos++;
383 }
384  
385 7 return \%kv;
386 }
387  
388 # Uses block: one module per line
389 sub parse_uses_block {
390 2 ▶ my ($lines) = @_;
Subroutine parse_uses_block: called CC=5 SCAR=17.2
Pod undocumented
391 2 my @mods;
392 2 for my $line (@$lines) {
393 2 ▶ next if $line =~ /^\s*$/ || $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ or $line =~ /^\s*#/ 0 2 2
Condition33%1/3
$line =~ /^\s*$/ or $line =~ /^\s*#/
l!l&&r!l&&!r
002
MC/DC0%0/2
$line =~ /^\s*$/ or $line =~ /^\s*#/
$line =~ /^\s*$/ $line =~ /^\s*#/
Truth table33%1/3
A or B
A= $line =~ /^\s*$/B= $line =~ /^\s*#/
ABresult
1X1
011
000
394 2 ▶ if ($line =~ /^\s*(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(\S+)/) 2 0 2
395 2 push @mods, $1;
396 }
397 }
398 2 return \@mods;
399 }
400  
401 #======================================================================
402 # Parse code blocks (method/sub bodies) with brace counting
403 #======================================================================
404  
405 # Given lines array and position of the opening line (e.g. "method public foo {"),
406 # return (code_lines_arrayref, next_position)
407 sub parse_code_block {
408 24 ▶ my ($lines, $start_pos) = @_;
Subroutine parse_code_block: called CC=8 SCAR=23.4
Pod undocumented
409  
410 24 my $opening_line = $lines->[$start_pos];
411 24 my @code;
412 24 my $depth = brace_delta($opening_line); # Usually +1 from the opening {
413  
414 # Capture any code on the opening line after the {
415 24 ▶ if ($opening_line =~ /\{\s*(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opening_line =~ /\{\s*(.+)$/) 0 24 24
416 0 my $rest = $1;
417 # Check if this rest doesn't just close the brace
418 0 ▶ if ($rest =~ /\S/ && $rest !~ /^\s*\}\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /\S/ and not $rest =~ /^\s*\}\s*$/) 0 0 0
Condition0%0/3
$rest =~ /\S/ and not $rest =~ /^\s*\}\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$rest =~ /\S/ and not $rest =~ /^\s*\}\s*$/
$rest =~ /\S/ not $rest =~ /^\s*\}\s*$/
Truth table0%0/3
A and not(B)
A= $rest =~ /\S/B= not $rest =~ /^\s*\}\s*$/
ABresult
0X0
100
111
419 0 push @code, $rest;
420 }
421 }
422  
423 24 my $pos = $start_pos + 1;
424  
425 24 ▶ while ($pos <= $#$lines && $depth > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $lines->$#* and $depth > 0) 658 0 658
Condition33%1/3
$pos <= $lines->$#* and $depth > 0
!ll&&!rl&&r
00658
MC/DC0%0/2
$pos <= $lines->$#* and $depth > 0
$pos <= $lines->$#* $depth > 0
Truth table33%1/3
A and B
A= $pos <= $lines->$#*B= $depth > 0
ABresult
0X0
100
111
426 658 my $line = $lines->[$pos];
427 658 my $delta = brace_delta($line);
428 658 $depth += $delta;
429  
430 658 ▶ if ($depth <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth <= 0) 24 634 658
431 # Closing brace line — capture content before the }
432 24 my $before = $line;
433 24 $before =~ s/\}\s*$//;
434 24 ▶ push @code, $before if $before =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $before =~ /\S/ 0 24 24
435 24 $pos++;
436 24 last;
437 }
438  
439 634 push @code, $line;
440 634 $pos++;
441 }
442  
443 # Strip common leading whitespace from code lines
444 24 my @trimmed = strip_indent(\@code);
445  
446 24 return (\@trimmed, $pos);
447 }
448  
449 # Remove common leading whitespace
450 sub strip_indent {
451 24 ▶ my ($lines) = @_;
Subroutine strip_indent: called CC=9 SCAR=22.2
Pod undocumented
452 24 ▶ return () unless @$lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @$lines 0 24 24
453  
454 # Find minimum indentation (ignoring blank lines)
455 24 my $min_indent;
456 24 for my $line (@$lines) {
457 634 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 114 520 634
458 520 my ($spaces) = $line =~ /^(\s*)/;
459 520 my $len = length($spaces);
460 520 ▶ $min_indent = $len if !defined $min_indent || $len < $min_indent;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $min_indent or $len < $min_indent 24 496 520
Condition66%2/3
not defined $min_indent or $len < $min_indent
l!l&&r!l&&!r
240496
MC/DC50%1/2
not defined $min_indent or $len < $min_indent
not defined $min_indent $len < $min_indent
Truth table66%2/3
not(A) or B
A= not defined $min_indentB= $len < $min_indent
ABresult
1X1
011
000
461 }
462 24 ▶ $min_indent //= 0;
Condition50%1/2
$min_indent //= 0
l!l
240
MC/DC0%0/1
$min_indent //= 0
$min_indent
Truth table50%1/2
A
A= $min_indent
Aresult
11
00
463  
464 return map {
465 24 my $l = $_;
466 634 ▶ if ($l =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\S/) 520 114 634
467 520 ▶ substr($l, 0, $min_indent) = '' if $min_indent > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $min_indent > 0 520 0 520
468 }
469 634 $l;
470 } @$lines;
471 }
472  
473 #======================================================================
474 # Parse access level string
475 #======================================================================
476  
477 sub parse_access {
478 20 ▶ my ($str) = @_;
Subroutine parse_access: called CC=3 SCAR=11.0
Pod undocumented
479 20 ▶ if ($str =~ /,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /,/) 1 19 20
480 # Compound: "auth,owner_only" → { auth => 1, owner_only => 1 }
481 1 my %access;
482 1 for my $part (split /,/, $str) {
483 2 $access{$part} = 1;
484 }
485 1 return \%access;
486 }
487 # Simple: "public", "auth", "admin_only"
488 19 return $str;
489 }
490  
491 1 1;
« lib/Yote/YapiServer/App/Base.pm ↑ Summary lib/Yote/YapiServer/Site.pm »