bin/wdlint

filter: Statementstmt 98.3% 120 / 122 Branchbran 83.3% 30 / 36 Conditioncond 60.4% 26 / 43 MC/DCmcdc 21.7% 5 / 23 Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 82.0% 196 / 239 CC 42 SCAR 21.4
CC
42
Cov
88%
collect_perl_ar
14.3
main
10.5
collect_subst_perl_ar
9.4
CRAP 8.5
« bin/wdcompile ↑ Summary blib/lib/WebDyne/Request/Fake.pm »
1 #!/usr/bin/env perl
2 #
3 # This file is part of WebDyne.
4 #
5 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
6 #
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 #
10 # Full license text is available at:
11 #
12 # <http://dev.perl.org/licenses/>
13 #
14  
15  
16 #
17 # Dump the compiled version of WebDyne HTML scripts, as stored in the cache dir
18 #
19 8 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Use the base module
24 #
25 8 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 8 ▶use WebDyne::Compile;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30 # External modules
31 #
32 8 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 8 ▶use Capture::Tiny qw(capture);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 8 ▶use FindBin qw($Script);
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 # Version Info, must be all one line for MakeMaker, CPAN.
38 #
39 8 $VERSION='3.029';
40  
41  
42 # Run main
43 #
44 8 ▶exit ${&main(\@ARGV) || die errdump()};
Condition50%1/2
&main(\@ARGV) || die(errdump())
l!l
80
MC/DC0%0/1
&main(\@ARGV) || die(errdump())
&main(\@ARGV)
Truth table50%1/2
A
A= &main(\@ARGV)
Aresult
11
00
45  
46 #============================================================================
47  
48  
49 8 ▶sub main {
Subroutine main: called CC=10 SCAR=23.6
50  
51  
52 # Get argv array ref
53 #
54 8 my $argv_ar=shift();
55  
56  
57 # Get srce file
58 #
59 8 ▶ my $srce_pn=pop(@{$argv_ar}) ||
Condition33%1/3
pop @{$argv_ar;} || pod2usage("$main::Script: no source file specified !")
l!l&&r!l&&!r
800
MC/DC0%0/2
pop @{$argv_ar;} || pod2usage("$main::Script: no source file specified !")
pop @{$argv_ar;} pod2usage("$main::Script: no source file specified !")
Truth table33%1/3
A || B
A= pop @{$argv_ar;}B= pod2usage("$main::Script: no source file specified !")
ABresult
1X1
011
000
60 pod2usage("$Script: no source file specified !");
61  
62  
63 # Compile to first stage so WebDyne does the PSP parsing. Then run Perl
64 # syntax checks over the page code and each inline fragment.
65 #
66 8 ▶ my $perl_ar=perl_ar($srce_pn) ||
Condition50%1/2
perl_ar($srce_pn) || (return err())
l!l
80
MC/DC0%0/1
perl_ar($srce_pn) || (return err())
perl_ar($srce_pn)
Truth table50%1/2
A
A= perl_ar($srce_pn)
Aresult
11
00
67 return err();
68 8 my (@page_perl, @chunk_perl);
69 8 foreach my $perl_hr (@{$perl_ar}) {
70 8 ▶ push @{$perl_hr->{'wrap'} ? \@chunk_perl : \@page_perl}, $perl_hr;
Branch: 1 branch
BranchTrueFalseTotal
$perl_hr->{'wrap'} ? : 5 3 8
71 }
72  
73  
74 # Check page level code first, then each inline chunk separately so one
75 # broken chunk does not hide later ones.
76 #
77 8 my $exit=0;
78 8 my $page_exit=check_perl($srce_pn, $argv_ar, \@page_perl);
79 8 ▶ $exit ||= $page_exit;
Condition66%2/3
$exit ||= $page_exit
l!l&&r!l&&!r
017
MC/DC50%1/2
$exit ||= $page_exit
$exit $page_exit
Truth table66%2/3
A ||= B
A= $exitB= $page_exit
ABresult
1X1
011
000
80 8 foreach my $perl_hr (@chunk_perl) {
81 5 ▶ my $chunk_exit=check_perl($srce_pn, $argv_ar, ($page_exit ? [] : \@page_perl), $perl_hr);
Branch: 1 branch
BranchTrueFalseTotal
$page_exit ? : 0 5 5
82 5 ▶ $exit ||= $chunk_exit;
Condition66%2/3
$exit ||= $chunk_exit
l!l&&r!l&&!r
140
MC/DC0%0/2
$exit ||= $chunk_exit
$exit $chunk_exit
Truth table66%2/3
A ||= B
A= $exitB= $chunk_exit
ABresult
1X1
011
000
83 }
84 8 ▶ print "$srce_pn syntax OK\n" unless $exit;
Branch: 1 branch
BranchTrueFalseTotal
unless $exit 3 5 8
85
86  
87 # Done
88 #
89 8 return \$exit;
90  
91  
92 }
93  
94  
95 13 ▶sub check_perl {
Subroutine check_perl: called CC=4 SCAR=13.9
96  
97  
98 # Write a temp Perl file for a page or inline fragment and run perl -c
99 #
100 13 my ($srce_pn, $argv_ar, $page_perl_ar, $chunk_perl_hr)=@_;
101 13 my ($temp_fh, $temp_fn)=tempfile( UNLINK=> 0);
102 13 print $temp_fh '#!perl', $/;
103 13 print $temp_fh 'use strict;', $/;
104 13 print $temp_fh 'package WebDyne::Lint;', $/;
105 13 foreach my $perl_hr (@{$page_perl_ar}) {
106 3 print_perl($temp_fh, $srce_pn, $perl_hr);
107 }
108 13 ▶ if ($chunk_perl_hr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk_perl_hr) 5 8 13
109 5 print_perl($temp_fh, $srce_pn, $chunk_perl_hr, 1);
110 }
111 13 print $temp_fh '1;', $/;
112 13 $temp_fh->close();
113  
114  
115 # Run perl check
116 #
117 13 ▶ my ($stdout, $stderr, $exit)=capture{
Subroutine __ANON__: called CC=1 SCAR=0.0
118 13 system($^X, qw(-c -w), @{$argv_ar}, $temp_fn)
119 13 };
120 13 my $rc=$exit >> 8;
121 13 $stderr=~s/\Q$temp_fn\E/$srce_pn/gs;
122 13 ▶ $stderr=~s/^\Q$srce_pn\E syntax OK\r?\n//gm unless $rc;
Branch: 1 branch
BranchTrueFalseTotal
unless $rc 7 6 13
123 13 print $stderr;
124 13 unlink($temp_fn);
125  
126  
127 # Done
128 #
129 13 return $rc;
130  
131  
132 }
133  
134  
135 8 ▶sub print_perl {
Subroutine print_perl: called CC=4 SCAR=13.9
136  
137  
138 # Print one Perl fragment into the lint temp file
139 #
140 8 my ($temp_fh, $srce_pn, $perl_hr, $wrap)=@_;
141 8 my ($perl, $line_no)=@{$perl_hr}{qw(perl line_no)};
142 8 ▶ if ($wrap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrap) { } 5 3 8
143 5 print $temp_fh 'my $__wdlint_cr = sub {', $/;
144 5 print $temp_fh "#line ${line_no} \"$srce_pn\"", $/;
145 5 print $temp_fh $perl;
146 5 ▶ print $temp_fh $/ unless $perl=~/(?:\r?\n|\r)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $perl =~ /(?:\r?\n|\r)$/ 4 1 5
147 5 print $temp_fh '};', $/;
148 }
149 else {
150 3 print $temp_fh "#line ${line_no} \"$srce_pn\"", $/;
151 3 print $temp_fh $perl;
152 3 ▶ print $temp_fh $/ unless $perl=~/(?:\r?\n|\r)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $perl =~ /(?:\r?\n|\r)$/ 0 3 3
153 }
154  
155  
156 # Done
157 #
158 8 return \undef;
159  
160  
161 }
162  
163  
164 8 ▶sub perl_ar {
Subroutine perl_ar: called CC=8 SCAR=21.1
165  
166  
167 # Compile file and collect Perl code fragments
168 #
169 8 my $srce_pn=shift();
170 8 ▶ my $compile_or=WebDyne::Compile->new(filename => $srce_pn) ||
Condition50%1/2
'WebDyne::Compile'->new('filename', $srce_pn) || (return err())
l!l
80
MC/DC0%0/1
'WebDyne::Compile'->new('filename', $srce_pn) || (return err())
'WebDyne::Compile'->new('filename', $srce_pn)
Truth table50%1/2
A
A= 'WebDyne::Compile'->new('filename', $srce_pn)
Aresult
11
00
171 return err();
172 8 ▶ my $container_ar=$compile_or->compile({
Condition50%1/2
$compile_or->compile({'srce', $srce_pn, 'no_perl', 1, 'no_filter', 1, 'no_manifest', 1, 'stage0', 1}) || (return err())
l!l
80
MC/DC0%0/1
$compile_or->compile({'srce', $srce_pn, 'no_perl', 1, 'no_filter', 1, 'no_manifest', 1, 'stage0', 1}) || (return err())
$compile_or->compile({'srce', $srce_pn, 'no_perl', 1, 'no_filter', 1, 'no_manifest', 1, 'stage0', 1})
Truth table50%1/2
A
A= $compile_or->compile({'srce', $srce_pn, 'no_perl', 1, 'no_filter', 1, 'no_manifest', 1, 'stage0', 1})
Aresult
11
00
173  
174 srce => $srce_pn,
175 no_perl => 1,
176 no_filter => 1,
177 no_manifest => 1,
178 stage0 => 1
179  
180 }) || return err();
181  
182  
183 # Start with page level __PERL__ code
184 #
185 8 my @perl;
186 8 ▶ my $meta_hr=$container_ar->[0] || {};
Condition50%1/2
$container_ar->[0] || {}
l!l
80
MC/DC0%0/1
$container_ar->[0] || {}
$container_ar->[0]
Truth table50%1/2
A
A= $container_ar->[0]
Aresult
11
00
187 8 ▶ my $perl_ar=$meta_hr->{'perl'} || [];
Condition100%2/2
$meta_hr->{'perl'} || []
l!l
35
MC/DC100%1/1
$meta_hr->{'perl'} || []
$meta_hr->{'perl'}
Truth table100%2/2
A
A= $meta_hr->{'perl'}
Aresult
11
00
188 8 ▶ my $perl_debug_ar=$meta_hr->{'perl_debug'} || [];
Condition100%2/2
$meta_hr->{'perl_debug'} || []
l!l
35
MC/DC100%1/1
$meta_hr->{'perl_debug'} || []
$meta_hr->{'perl_debug'}
Truth table100%2/2
A
A= $meta_hr->{'perl_debug'}
Aresult
11
00
189 8 foreach my $ix (0..$#{$perl_ar}) {
190 3 my $perl_sr=$perl_ar->[$ix];
191 3 ▶ my $line_no=$perl_debug_ar->[$ix][0] || 1;
Condition50%1/2
$perl_debug_ar->[$ix][0] || 1
l!l
30
MC/DC0%0/1
$perl_debug_ar->[$ix][0] || 1
$perl_debug_ar->[$ix][0]
Truth table50%1/2
A
A= $perl_debug_ar->[$ix][0]
Aresult
11
00
192 3 push @perl, {perl => ${$perl_sr}, line_no => $line_no};
193 }
194  
195  
196 # Then inline Perl and substitutions from the compiled data tree
197 #
198 8 collect_perl_ar($container_ar->[1], \@perl);
199  
200  
201 # Done
202 #
203 8 return \@perl;
204  
205  
206 }
207  
208  
209 65 ▶sub collect_perl_ar {
Subroutine collect_perl_ar: called CC=14 SCAR=26.6
210  
211  
212 # Walk compiled data tree collecting inline Perl and substitution snippets
213 #
214 65 my ($data_xr, $perl_ar)=@_;
215 65 ▶ return if !ref($data_xr);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data_xr 0 65 65
216 65 ▶ return if ref($data_xr) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data_xr ne "ARRAY" 0 65 65
217  
218 65 my ($tag, $attr_hr, $child_ar, $line_no)=@{$data_xr}[
219 WEBDYNE_NODE_NAME_IX,
220 WEBDYNE_NODE_ATTR_IX,
221 WEBDYNE_NODE_CHLD_IX,
222 WEBDYNE_NODE_LINE_IX
223 ];
224  
225 65 ▶ if ($tag && $tag eq 'perl' && $attr_hr && $attr_hr->{'perl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag and $tag eq "perl" and $attr_hr and $attr_hr->{"perl"}) 3 62 65
Condition77%7/9
$tag and $tag eq "perl" and $attr_hr and $attr_hr->{"perl"}
!ll&&!rl&&r
6113
$tag and $tag eq "perl" and $attr_hr
!ll&&!rl&&r
6104
$tag and $tag eq "perl"
!ll&&!rl&&r
0614
MC/DC50%2/4
$tag and $tag eq "perl" and $attr_hr and $attr_hr->{"perl"}
$tag $tag eq "perl" $attr_hr $attr_hr->{"perl"}
Truth table60%3/5
A and B and C and D
A= $tagB= $tag eq "perl"C= $attr_hrD= $attr_hr->{"perl"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
226 3 ▶ push @{$perl_ar}, {perl => $attr_hr->{'perl'}, line_no => $line_no || 1, wrap => 1};
Condition50%1/2
$line_no || 1
l!l
30
MC/DC0%0/1
$line_no || 1
$line_no
Truth table50%1/2
A
A= $line_no
Aresult
11
00
227 }
228  
229 65 ▶ if ($attr_hr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hr) 30 35 65
230 30 foreach my $attr_name (sort keys %{$attr_hr}) {
231 41 ▶ next if $attr_name eq 'perl';
Branch: 1 branch
BranchTrueFalseTotal
if $attr_name eq "perl" 3 38 41
232 38 collect_subst_perl_ar($attr_hr->{$attr_name}, $line_no, $perl_ar, 1);
233 }
234 }
235  
236 65 ▶ if ($child_ar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child_ar) 46 19 65
237 46 foreach my $child_xr (@{$child_ar}) {
238 71 ▶ if (ref($child_xr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $child_xr) { } 57 14 71
239 57 collect_perl_ar($child_xr, $perl_ar);
240 }
241 else {
242 14 collect_subst_perl_ar($child_xr, $line_no, $perl_ar);
243 }
244 }
245 }
246  
247  
248 # Done
249 #
250 65 return \undef;
251  
252  
253 }
254  
255  
256 52 ▶sub collect_subst_perl_ar {
Subroutine collect_subst_perl_ar: called CC=7 SCAR=22.4
257  
258  
259 # Extract Perl snippets from WebDyne substitution strings
260 #
261 52 my ($text, $line_no, $perl_ar, $attr_fg)=@_;
262 52 ▶ return if ref($text);
Branch: 1 branch
BranchTrueFalseTotal
if ref $text 0 52 52
263  
264 52 ▶ if ($attr_fg && $text=~/^\s*([\@%!])\{(\1?)(.*)\2}\s*$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_fg and $text =~ /^\s*([\@%!])\{(\1?)(.*)\2}\s*$/s) { } 0 52 52
Condition66%2/3
$attr_fg and $text =~ /^\s*([\@%!])\{(\1?)(.*)\2}\s*$/s
!ll&&!rl&&r
14380
MC/DC0%0/2
$attr_fg and $text =~ /^\s*([\@%!])\{(\1?)(.*)\2}\s*$/s
$attr_fg $text =~ /^\s*([\@%!])\{(\1?)(.*)\2}\s*$/s
Truth table66%2/3
A and B
A= $attr_fgB= $text =~ /^\s*([\@%!])\{(\1?)(.*)\2}\s*$/s
ABresult
0X0
100
111
265 0 ▶ push @{$perl_ar}, {perl => $3, line_no => $line_no || 1, wrap => 1};
Condition0%0/2
$line_no || 1
l!l
00
MC/DC0%0/1
$line_no || 1
$line_no
Truth table0%0/2
A
A= $line_no
Aresult
11
00
266 }
267 else {
268 52 ▶ while ($text=~/(!)\{(\1?)(.*?)\2\}/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /(!)\{(\1?)(.*?)\2\}/g) 2 52 54
269 2 ▶ push @{$perl_ar}, {perl => $3, line_no => $line_no || 1, wrap => 1};
Condition50%1/2
$line_no || 1
l!l
20
MC/DC0%0/1
$line_no || 1
$line_no
Truth table50%1/2
A
A= $line_no
Aresult
11
00
270 }
271 }
272  
273  
274 # Done
275 #
276 52 return \undef;
277  
278  
279 }
280  
281 __END__
« bin/wdcompile ↑ Summary blib/lib/WebDyne/Request/Fake.pm »