lib/App/GHGen/PerlCustomizer.pm

filter: Statementstmt 100% 208 / 208 Branchbran 91.6% 22 / 24 Conditioncond 88.5% 31 / 35 MC/DCmcdc 80.0% 16 / 20 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 96.6% 289 / 299 CC 32 SCAR 26.0
CC
32
Cov
98%
generate_custom_perl_workflow
22.0
detect_perl_requirements
6.0
_get_perl_versions
4.0
CRAP 13.5
« bin/ghgen ↑ Summary lib/App/GHGen/Detector.pm »
1 package App::GHGen::PerlCustomizer;
2  
3 7 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 our @EXPORT_OK = qw(
12 detect_perl_requirements
13 generate_custom_perl_workflow
14 );
15  
16 7 our $VERSION = '0.12';
17  
18 7 Readonly my $DEFAULT_TIMEOUT_MINUTES => 60;
19  
20 =encoding utf-8
21  
22 =head1 NAME
23  
24 App::GHGen::PerlCustomizer - Customize Perl workflows based on project requirements
25  
26 =head1 SYNOPSIS
27  
28 use App::GHGen::PerlCustomizer qw(detect_perl_requirements);
29  
30 my $requirements = detect_perl_requirements();
31 # Returns: { min_version => '5.036', has_cpanfile => 1, ... }
32  
33 =head1 FUNCTIONS
34  
35 =head2 detect_perl_requirements()
36  
37 Detect Perl version requirements and dependency-file presence in the current directory.
38  
39 =head3 Purpose
40  
41 Inspect the current working directory for common Perl distribution files
42 (C<cpanfile>, C<Makefile.PL>, C<dist.ini>, C<Build.PL>) and extract the
43 minimum Perl version declared in any of them.
44  
45 =head3 Arguments
46  
47 None.
48  
49 =head3 Returns
50  
51 A hash reference with the following keys, all of which are always present:
52  
53 {
54 min_version => Str | undef, # e.g. '5.036'; undef when undetected
55 has_cpanfile => Bool,
56 has_makefile_pl => Bool,
57 has_dist_ini => Bool,
58 has_build_pl => Bool,
59 }
60  
61 =head3 Side Effects
62  
63 Reads files from the current working directory.
64  
65 =head3 Usage Example
66  
67 use App::GHGen::PerlCustomizer qw(detect_perl_requirements);
68 my $reqs = detect_perl_requirements();
69 say $reqs->{min_version} // 'not specified';
70  
71 =head3 API SPECIFICATION
72  
73 =head4 Input
74  
75 # No parameters.
76  
77 =head4 Output
78  
79 {
80 type => 'hashref',
81 keys => {
82 min_version => { type => 'scalar', optional => 1 },
83 has_cpanfile => { type => 'scalar' },
84 has_makefile_pl => { type => 'scalar' },
85 has_dist_ini => { type => 'scalar' },
86 has_build_pl => { type => 'scalar' },
87 },
88 }
89  
90 =head3 FORMAL SPECIFICATION
91  
92 detect_perl_requirements : → Requirements
93  
94 Requirements ≔ {
95 min_version: ℤ* ∪ { ⊥ },
96 has_cpanfile: 𝔹,
97 has_makefile_pl: 𝔹,
98 has_dist_ini: 𝔹,
99 has_build_pl: 𝔹,
100 }
101  
102 min_version ≔
103 cpanfile exists ∧ version parseable from cpanfile → version
104 Makefile.PL exists ∧ MIN_PERL_VERSION parseable → version
105 otherwise → ⊥
106  
107 =cut
108  
109 13 ▶sub detect_perl_requirements() {
Subroutine detect_perl_requirements: called CC=6 SCAR=17.9
Pod documented
110 13 my %reqs = (
111 min_version => undef,
112 has_cpanfile => 0,
113 has_makefile_pl => 0,
114 has_dist_ini => 0,
115 has_build_pl => 0,
116 );
117  
118 # Check for dependency files
119 13 $reqs{has_cpanfile} = path('cpanfile')->exists;
120 13 $reqs{has_makefile_pl} = path('Makefile.PL')->exists;
121 13 $reqs{has_dist_ini} = path('dist.ini')->exists;
122 13 $reqs{has_build_pl} = path('Build.PL')->exists;
123  
124 # Try to detect minimum Perl version
125 13 ▶ if ($reqs{has_cpanfile}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reqs{"has_cpanfile"}) 9 4 13
126 9 my $content = path('cpanfile')->slurp_utf8;
127 9 ▶ if ($content =~ /requires\s+['"]perl['"],?\s+['"]([0-9.]+)['"]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /requires\s+['"]perl['"],?\s+['"]([0-9.]+)['"]/u) 9 0 9
128 9 $reqs{min_version} = $1;
129 }
130 }
131  
132 13 ▶ if (!$reqs{min_version} && $reqs{has_makefile_pl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $reqs{"min_version"} and $reqs{"has_makefile_pl"}) 1 12 13
Condition100%3/3
not $reqs{"min_version"} and $reqs{"has_makefile_pl"}
!ll&&!rl&&r
931
MC/DC100%2/2
not $reqs{"min_version"} and $reqs{"has_makefile_pl"}
not $reqs{"min_version"} $reqs{"has_makefile_pl"}
Truth table100%3/3
not(A) and B
A= not $reqs{"min_version"}B= $reqs{"has_makefile_pl"}
ABresult
0X0
100
111
133 1 my $content = path('Makefile.PL')->slurp_utf8;
134 1 ▶ if ($content =~ /MIN_PERL_VERSION\s*=>\s*['"]([0-9.]+)['"]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /MIN_PERL_VERSION\s*=>\s*['"]([0-9.]+)['"]/u) 1 0 1
135 1 $reqs{min_version} = $1;
136 }
137 }
138  
139 13 return \%reqs;
140 }
141  
142 =head2 generate_custom_perl_workflow($options)
143  
144 Generate a customized Perl CI workflow and return it as a YAML string.
145  
146 B<Options:>
147  
148 =over 4
149  
150 =item C<perl_versions> (array ref)
151  
152 Explicit list of Perl versions to include in the test matrix, e.g.
153 C<['5.40', '5.38', '5.36']>. Takes precedence over C<min_perl_version>
154 and C<max_perl_version> when supplied.
155  
156 =item C<min_perl_version> (string, default C<'5.36'>)
157  
158 Lowest Perl version to include in the matrix when C<perl_versions> is not
159 given. Accepts both C<'5.036'> and C<'5.36'> notation.
160  
161 =item C<max_perl_version> (string, default C<'5.42'>)
162  
163 Highest Perl version to include in the default matrix when C<perl_versions>
164 is not given. The built-in version table currently spans C<5.22> through
165 C<5.44>; the default produces the matrix C<5.36, 5.38, 5.40, 5.42>.
166  
167 To test against B<Perl 5.44> (opt-in, not tested by default), pass
168 C<< max_perl_version => '5.44' >> or set C<perl_versions> explicitly:
169  
170 generate_custom_perl_workflow({ max_perl_version => '5.44' });
171 # matrix: 5.36, 5.38, 5.40, 5.42, 5.44
172  
173 generate_custom_perl_workflow({ perl_versions => ['5.42', '5.44'] });
174 # matrix: 5.42, 5.44
175  
176 =item C<os> (array ref)
177  
178 Operating systems for the build matrix.
179 Default: C<['ubuntu-latest', 'macos-latest', 'windows-latest']>.
180  
181 =item C<timeout> (integer, default C<60>)
182  
183 Value written to C<timeout-minutes> on every matrix job.
184  
185 =item C<enable_linter> (boolean, default C<1>)
186  
187 When true, inserts a B<"Lint and syntax check"> step after all dependency
188 installation steps and before the test run. The step runs on B<every>
189 matrix cell (all OS and Perl version combinations) so that compile-time
190 errors are caught across the full version range being tested.
191  
192 The step uses C<shell: perl {0}>, which works identically on Linux, macOS,
193 and Windows without any OS-specific branching. It searches C<lib/> and
194 C<bin/> (falling back to C<.> when neither exists), loads each C<.pm> file
195 via C<do $file> with a stub C<@INC> handler that silently satisfies any
196 missing C<use> statements, and exits non-zero if any file fails. Using
197 C<do $file> avoids spawning C<perl -c> subprocesses (which have
198 Windows command-line quoting issues) and avoids false failures caused by
199 missing CPAN dependencies. B<No additional CPAN modules are required.>
200  
201 =item C<enable_linter_unused> (boolean, default C<1>)
202  
203 When true, appends an unused-variable check to the B<end of the lint step>
204 (i.e. it runs before the test run, not after). The check installs
205 L<warnings::unused> from CPAN, then runs
206 C<PERL5OPT=-Mwarnings::unused prove -lr t/> so that variable lifetimes are
207 exercised at runtime (C<perl -c> is compile-only and cannot detect unused
208 variables). It is gated on C<RUNNER_OS == Linux> and marked
209 C<continue-on-error: true> because unused-variable warnings can be
210 legitimately noisy on some codebases.
211  
212 =item C<enable_critic> (boolean, default C<1>)
213  
214 When true, adds a Perl::Critic step on the latest matrix Perl version and
215 C<ubuntu-latest>.
216  
217 =item C<enable_coverage> (boolean, default C<1>)
218  
219 When true, adds a Devel::Cover test-coverage step on the latest matrix Perl
220 version and C<ubuntu-latest>.
221  
222 =item C<enable_perlimports> (boolean, default C<1>)
223  
224 When true, adds a B<"Check imports with perlimports"> step on the latest matrix
225 Perl version and C<ubuntu-latest>. The step installs L<App::perlimports> from
226 CPAN and runs C<perlimports --lint> across all C<.pm> files under C<lib/>. It
227 is marked C<continue-on-error: true> because import hygiene warnings are
228 advisory; they should not block a CI run in established codebases.
229  
230 =back
231  
232 B<Generated step order:>
233  
234 =over 4
235  
236 =item 1. C<actions/checkout>
237  
238 =item 2. Setup Perl via C<shogo82148/actions-setup-perl>
239  
240 =item 3. Cache CPAN modules via C<actions/cache>
241  
242 =item 4. Install cpanm and C<local::lib>
243  
244 =item 5. Install project dependencies
245  
246 =item 6. B<Lint and syntax check> — all matrix cells (when C<enable_linter> is true); the unused-variable check via C<PERL5OPT=-Mwarnings::unused> is embedded at the end of this step when C<enable_linter_unused> is true
247  
248 =item 7. Run tests
249  
250 =item 8. Run Perl::Critic — latest Perl + Ubuntu only (when C<enable_critic> is true)
251  
252 =item 9. B<Check imports with perlimports> — latest Perl + Ubuntu only (when C<enable_perlimports> is true)
253  
254 =item 10. Test coverage — latest Perl + Ubuntu only (when C<enable_coverage> is true)
255  
256 =item 11. Show cpanm build log on failure
257  
258 =back
259  
260 =head3 API SPECIFICATION
261  
262 =head4 Input
263  
264 {
265 opts => {
266 type => 'hashref',
267 default => {},
268 keys => {
269 perl_versions => { type => 'arrayref', optional => 1 },
270 min_perl_version => { type => 'scalar', default => '5.36' },
271 max_perl_version => { type => 'scalar', default => '5.42' },
272 os => { type => 'arrayref', optional => 1 },
273 timeout => { type => 'scalar', default => $DEFAULT_TIMEOUT_MINUTES },
274 enable_linter => { type => 'scalar', default => 1 },
275 enable_linter_unused => { type => 'scalar', default => 1 },
276 enable_critic => { type => 'scalar', default => 1 },
277 enable_coverage => { type => 'scalar', default => 1 },
278 enable_perlimports => { type => 'scalar', default => 1 },
279 },
280 },
281 }
282  
283 =head4 Output
284  
285 { type => 'scalar' } # multi-line YAML string starting with '---'
286  
287 =head3 FORMAL SPECIFICATION
288  
289 generate_custom_perl_workflow : Opts → YAML
290  
291 versions ≔ opts.perl_versions ?? range(min, max)
292 latest ≔ versions[|versions|−1]
293  
294 yaml contains "Lint and syntax check" step ↔ opts.enable_linter = 1
295 yaml contains "PERL5OPT=-Mwarnings::unused" ↔ opts.enable_linter_unused = 1
296 yaml contains "Run Perl::Critic" ↔ opts.enable_critic = 1
297 yaml contains "Test coverage" ↔ opts.enable_coverage = 1
298 yaml contains "Check imports with perlimports" ↔ opts.enable_perlimports = 1
299  
300 step ordering invariant:
301 pos(lint) < pos(unused) < pos(tests) < pos(critic) < pos(perlimports) < pos(coverage)
302  
303 =cut
304  
305 39 ▶sub generate_custom_perl_workflow($opts = {}) {
Subroutine generate_custom_perl_workflow: called CC=22 SCAR=30.9
Pod documented
306 39 ▶ my $min_version = $opts->{min_perl_version} // '5.36';
Condition100%2/2
$opts->{"min_perl_version"} // "5.36"
l!l
633
MC/DC100%1/1
$opts->{"min_perl_version"} // "5.36"
$opts->{"min_perl_version"}
Truth table100%2/2
A
A= $opts->{"min_perl_version"}
Aresult
11
00
307 39 ▶ my $max_version = $opts->{max_perl_version} // '5.42';
Condition100%2/2
$opts->{"max_perl_version"} // "5.42"
l!l
633
MC/DC100%1/1
$opts->{"max_perl_version"} // "5.42"
$opts->{"max_perl_version"}
Truth table100%2/2
A
A= $opts->{"max_perl_version"}
Aresult
11
00
308 39 ▶ my $timeout = $opts->{timeout} // $DEFAULT_TIMEOUT_MINUTES;
Condition66%2/3
$opts->{"timeout"} // $DEFAULT_TIMEOUT_MINUTES
l!l&&r!l&&!r
0336
MC/DC50%1/2
$opts->{"timeout"} // $DEFAULT_TIMEOUT_MINUTES
$opts->{"timeout"} $DEFAULT_TIMEOUT_MINUTES
Truth table66%2/3
A // B
A= $opts->{"timeout"}B= $DEFAULT_TIMEOUT_MINUTES
ABresult
1X1
011
000
309 39 ▶ my @os = @{$opts->{os} // ['ubuntu-latest', 'macos-latest', 'windows-latest']};
Condition100%2/2
$opts->{"os"} // ["ubuntu-latest", "macos-latest", "windows-latest"]
l!l
732
MC/DC100%1/1
$opts->{"os"} // ["ubuntu-latest", "macos-latest", "windows-latest"]
$opts->{"os"}
Truth table100%2/2
A
A= $opts->{"os"}
Aresult
11
00
310 39 ▶ my $enable_linter = $opts->{enable_linter} // 1;
Condition100%2/2
$opts->{"enable_linter"} // 1
l!l
1128
MC/DC100%1/1
$opts->{"enable_linter"} // 1
$opts->{"enable_linter"}
Truth table100%2/2
A
A= $opts->{"enable_linter"}
Aresult
11
00
311 39 ▶ my $enable_linter_unused = $opts->{enable_linter_unused} // 1;
Condition100%2/2
$opts->{"enable_linter_unused"} // 1
l!l
1227
MC/DC100%1/1
$opts->{"enable_linter_unused"} // 1
$opts->{"enable_linter_unused"}
Truth table100%2/2
A
A= $opts->{"enable_linter_unused"}
Aresult
11
00
312 39 ▶ my $enable_critic = $opts->{enable_critic} // 1;
Condition100%2/2
$opts->{"enable_critic"} // 1
l!l
1722
MC/DC100%1/1
$opts->{"enable_critic"} // 1
$opts->{"enable_critic"}
Truth table100%2/2
A
A= $opts->{"enable_critic"}
Aresult
11
00
313 39 ▶ my $enable_coverage = $opts->{enable_coverage} // 1;
Condition100%2/2
$opts->{"enable_coverage"} // 1
l!l
1623
MC/DC100%1/1
$opts->{"enable_coverage"} // 1
$opts->{"enable_coverage"}
Truth table100%2/2
A
A= $opts->{"enable_coverage"}
Aresult
11
00
314 39 ▶ my $enable_perlimports = $opts->{enable_perlimports} // 1;
Condition100%2/2
$opts->{"enable_perlimports"} // 1
l!l
930
MC/DC100%1/1
$opts->{"enable_perlimports"} // 1
$opts->{"enable_perlimports"}
Truth table100%2/2
A
A= $opts->{"enable_perlimports"}
Aresult
11
00
315  
316 # Generate Perl version list - use explicit list if provided, otherwise min/max
317 39 my @perl_versions;
318 39 ▶ if ($opts->{perl_versions} && @{$opts->{perl_versions}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'perl_versions'} and @{$opts->{'perl_versions'};}) { } 2 37 39
Condition66%2/3
$opts->{"perl_versions"} and @{$opts->{"perl_versions"};}
!ll&&!rl&&r
3702
MC/DC50%1/2
$opts->{"perl_versions"} and @{$opts->{"perl_versions"};}
$opts->{"perl_versions"} @{$opts->{"perl_versions"};}
Truth table66%2/3
A and B
A= $opts->{"perl_versions"}B= @{$opts->{"perl_versions"};}
ABresult
0X0
100
111
319 2 @perl_versions = @{$opts->{perl_versions}};
320 } else {
321 37 @perl_versions = _get_perl_versions($min_version, $max_version);
322 }
323  
324 39 my $yaml = "---\n";
325 39 $yaml .= '# Created by ' . __PACKAGE__ . "\n";
326  
327 39 $yaml .= "name: Perl CI\n\n";
328 39 $yaml .= "\"on\":\n";
329 39 $yaml .= " push:\n";
330 39 $yaml .= " branches:\n";
331 39 $yaml .= " - main\n";
332 39 $yaml .= " - master\n";
333 39 $yaml .= " pull_request:\n";
334 39 $yaml .= " branches:\n";
335 39 $yaml .= " - main\n";
336 39 $yaml .= " - master\n\n";
337  
338 39 $yaml .= "concurrency:\n";
339 39 $yaml .= " group: \${{ github.workflow }}-\${{ github.ref }}\n";
340 39 $yaml .= " cancel-in-progress: true\n\n";
341  
342 39 $yaml .= "permissions:\n";
343 39 $yaml .= " contents: read\n\n";
344  
345 39 $yaml .= "jobs:\n";
346 39 $yaml .= " test:\n";
347 39 $yaml .= " runs-on: \${{ matrix.os }}\n";
348 39 $yaml .= " timeout-minutes: $timeout\n";
349 39 $yaml .= " strategy:\n";
350 39 $yaml .= " fail-fast: false\n";
351 39 $yaml .= " matrix:\n";
352 39 $yaml .= " os:\n";
353 39 for my $os (@os) {
354 113 $yaml .= " - $os\n";
355 }
356 39 $yaml .= " perl:\n";
357 39 for my $version (@perl_versions) {
358 146 $yaml .= " - \"$version\"\n";
359 }
360 # shogo82148/build-perl perl-5.40.4-thr-win32-x64.zip ships a perl.exe and a
361 # libperl540.a from two different builds. Any XS module compiled against that
362 # libperl540.a (key 0x12c00080) mismatches the running perl.exe (needs
363 # 0x12d00080). Even Win32::Process (a core Windows XS module bundled in the
364 # zip) fails to load, so no XS-using test can pass on this combination.
365 # Exclude until the upstream distribution is fixed.
366 39 ▶ if ((grep { $_ eq '5.40' } @perl_versions) && (grep { $_ eq 'windows-latest' } @os)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "5.40";} @perl_versions and grep {$_ eq "windows-latest";} @os) 35 4 39
Condition100%3/3
grep {$_ eq "5.40";} @perl_versions and grep {$_ eq "windows-latest";} @os
!ll&&!rl&&r
2235
MC/DC100%2/2
grep {$_ eq "5.40";} @perl_versions and grep {$_ eq "windows-latest";} @os
grep {$_ eq "5.40";} @perl_versions grep {$_ eq "windows-latest";} @os
Truth table100%3/3
A and B
A= grep {$_ eq "5.40";} @perl_versionsB= grep {$_ eq "windows-latest";} @os
ABresult
0X0
100
111
367 35 $yaml .= " exclude:\n";
368 35 $yaml .= " - os: windows-latest\n";
369 35 $yaml .= " perl: \"5.40\"\n";
370 }
371 39 $yaml .= " name: Perl \${{ matrix.perl }} on \${{ matrix.os }}\n";
372 39 $yaml .= " env:\n";
373 39 $yaml .= " AUTOMATED_TESTING: 1\n";
374 39 $yaml .= " NO_NETWORK_TESTING: 1\n";
375 39 $yaml .= " NONINTERACTIVE_TESTING: 1\n";
376 39 $yaml .= " steps:\n";
377 39 $yaml .= " - uses: actions/checkout\@v7\n\n";
378  
379 39 $yaml .= " - name: Setup Perl\n";
380 39 $yaml .= " id: setup-perl\n";
381 39 $yaml .= " uses: shogo82148/actions-setup-perl\@v1.44.2\n";
382 39 $yaml .= " with:\n";
383 39 $yaml .= " perl-version: \${{ matrix.perl }}\n\n";
384  
385 # Hash the actual Perl binary files so the cache key changes whenever the
386 # binary changes, even across silent Strawberry Perl re-releases that keep the
387 # same $Config{version} string but change the DLL ABI and handshake key.
388 # On Windows we hash both perl.exe and the Perl runtime DLL (e.g. perl540.dll)
389 # because perl.exe is a thin stub — only the DLL contains the real runtime.
390 # shell: perl {0} runs identically on Linux, macOS, and Windows.
391 39 $yaml .= " - name: Get exact Perl binary version for cache key\n";
392 39 $yaml .= " id: perl-version\n";
393 39 $yaml .= " shell: perl {0}\n";
394 39 $yaml .= " run: |\n";
395 39 $yaml .= <<'VERSION_STEP';
396 use Config;
397 my @paths = ($^X);
398 if ($^O eq 'MSWin32' && $Config{libperl}) {
399 (my $dir = $^X) =~ s{[\\/][^\\/]+$}{};
400 my $dll = "$dir/$Config{libperl}";
401 push @paths, $dll if -f $dll;
402 }
403 my $sum = 0;
404 for my $path (@paths) {
405 open(my $fh, '<:raw', $path) or next;
406 $sum += unpack('%32C*', $_) while read $fh, $_, 65536;
407 }
408 open(my $out, '>>', $ENV{GITHUB_OUTPUT}) or die $!;
409 print $out "version=$Config{version}-$Config{archname}-$sum\n";
410  
411 VERSION_STEP
412  
413 39 $yaml .= " - name: Cache CPAN modules\n";
414 39 $yaml .= " uses: actions/cache\@v6\n";
415 39 $yaml .= " with:\n";
416 39 $yaml .= " path: ~/perl5\n";
417 39 $yaml .= " key: \${{ runner.os }}-perl-\${{ steps.perl-version.outputs.version }}-\${{ hashFiles('cpanfile') }}\n";
418 39 $yaml .= " restore-keys: |\n";
419 39 $yaml .= " \${{ runner.os }}-perl-\${{ steps.perl-version.outputs.version }}-\n\n";
420  
421 39 $yaml .= " - name: Install cpanm and local::lib\n";
422 39 $yaml .= " if: runner.os != 'Windows'\n";
423 39 $yaml .= " run: cpanm --notest --local-lib=~/perl5 local::lib\n\n";
424  
425 39 $yaml .= " - name: Install cpanm and local::lib (Windows)\n";
426 39 $yaml .= " if: runner.os == 'Windows'\n";
427 39 $yaml .= " run: cpanm --notest App::cpanminus local::lib\n\n";
428  
429 # TODO: should be configurable
430 39 $yaml .= " - name: Install DB_File, needed for a lot of CPAN modules\n";
431 39 $yaml .= " if: runner.os == 'Linux'\n";
432 39 $yaml .= " run: |\n";
433 39 $yaml .= " sudo apt update\n";
434 39 $yaml .= " sudo apt install libdb-dev libperl-dev\n";
435  
436 39 $yaml .= " - name: Install dependencies\n";
437 39 $yaml .= " if: runner.os != 'Windows'\n";
438 39 $yaml .= " shell: bash\n";
439 39 $yaml .= " run: |\n";
440 39 $yaml .= " eval \$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\n";
441 # Add the --verbose to stop the no activity timeout in GitHub actions whene there are a lot of prequisites
442 # TODO: should be configurable
443 39 $yaml .= " cpanm --notest --installdeps --verbose .\n\n";
444  
445 39 $yaml .= " - name: Install dependencies (Windows)\n";
446 39 $yaml .= " if: runner.os == 'Windows'\n";
447 39 $yaml .= " shell: cmd\n";
448 39 $yaml .= " run: |\n";
449 39 $yaml .= " \@echo off\n";
450 39 $yaml .= " set \"PATH=%USERPROFILE%\\perl5\\bin;%PATH%\"\n";
451 39 $yaml .= " set \"PERL5LIB=%USERPROFILE%\\perl5\\lib\\perl5\"\n";
452 39 $yaml .= " cpanm --notest --installdeps --verbose .\n\n";
453  
454 # The shogo82148 Perl distributions bundle pre-compiled XS modules (e.g.
455 # YAML::XS) in the Perl zip. cpanm sees them as "already installed" and
456 # skips recompilation, leaving a DLL that may have the wrong handshake key.
457 # Force-reinstall YAML::XS into site/lib (which precedes the bundled lib in
458 # @INC) to ensure a freshly compiled copy is always used.
459 # NOTE: this step cannot rescue a fundamentally broken distribution where
460 # libperl540.a and perl.exe themselves are from different builds (as in the
461 # shogo82148 perl-5.40.4-thr-win32-x64.zip build) — that case is handled
462 # by the matrix exclusion above.
463 39 $yaml .= " - name: Reinstall YAML::XS against current Perl (Windows)\n";
464 39 $yaml .= " if: runner.os == 'Windows'\n";
465 39 $yaml .= " shell: cmd\n";
466 39 $yaml .= " run: cpanm --notest --reinstall YAML::XS\n\n";
467  
468 39 ▶ if ($enable_linter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable_linter) 34 5 39
469 34 $yaml .= " - name: Lint and syntax check\n";
470 34 $yaml .= " shell: perl {0}\n";
471 34 $yaml .= " run: |\n";
472 34 $yaml .= <<'LINT_STEP';
473 use strict;
474 use warnings;
475 use File::Find;
476 use lib 'lib';
477 my @failed;
478 push @INC, sub { open my $h, '<', \qq{1;\n}; $h };
479 my @dirs = grep { -d } qw(lib bin);
480 @dirs = ('.') unless @dirs;
481 find({ wanted => sub {
482 return unless -f && /\.pm$/;
483 my $file = $File::Find::name;
484 do $file;
485 if ($@) {
486 warn "Syntax check failed: $file\n";
487 push @failed, $file;
488 }
489 }, no_chdir => 1 }, @dirs);
490  
491 LINT_STEP
492  
493 34 ▶ if ($enable_linter_unused) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable_linter_unused) 31 3 34
494 31 $yaml .= <<'UNUSED_CODE';
495 if (($ENV{RUNNER_OS} // '') eq 'Linux') {
496 system('cpanm --notest --quiet warnings::unused 2>/dev/null');
497 system('PERL5OPT=-Mwarnings::unused prove -lr t/ 2>&1 | grep -i unused && true || echo "warnings::unused: no unused variables detected"');
498 }
499  
500 UNUSED_CODE
501 }
502  
503 34 $yaml .= " exit(\@failed ? 1 : 0);\n\n";
504 }
505  
506 39 $yaml .= " - name: Run tests\n";
507 39 $yaml .= " if: runner.os != 'Windows'\n";
508 39 $yaml .= " shell: bash\n";
509 39 $yaml .= " run: |\n";
510 39 $yaml .= " eval \$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\n";
511 39 $yaml .= " prove -lr t/\n\n";
512  
513 39 $yaml .= " - name: Run tests (Windows)\n";
514 39 $yaml .= " if: runner.os == 'Windows'\n";
515 39 $yaml .= " shell: cmd\n";
516 39 $yaml .= " run: |\n";
517 39 $yaml .= " \@echo off\n";
518 39 $yaml .= " set \"PATH=%USERPROFILE%\\perl5\\bin;%PATH%\"\n";
519 39 $yaml .= " set \"PERL5LIB=%USERPROFILE%\\perl5\\lib\\perl5\"\n";
520 39 $yaml .= " prove -lr t/\n\n";
521  
522 39 ▶ if ($enable_critic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable_critic) 32 7 39
523 32 my $latest = $perl_versions[-1];
524 32 $yaml .= " - name: Run Perl::Critic\n";
525 32 $yaml .= " if: matrix.perl == '$latest' && matrix.os == 'ubuntu-latest'\n";
526 32 $yaml .= " continue-on-error: true\n";
527 32 $yaml .= " run: |\n";
528 32 $yaml .= " eval \$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\n";
529 32 $yaml .= " cpanm --notest Perl::Critic\n";
530 32 $yaml .= " perlcritic --severity 3 lib/ || true\n";
531 32 $yaml .= " shell: bash\n\n";
532 }
533  
534 39 ▶ if ($enable_perlimports) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable_perlimports) 35 4 39
535 35 my $latest = $perl_versions[-1];
536 35 $yaml .= " - name: Check imports with perlimports\n";
537 35 $yaml .= " if: matrix.perl == '$latest' && matrix.os == 'ubuntu-latest'\n";
538 35 $yaml .= " continue-on-error: true\n";
539 35 $yaml .= " run: |\n";
540 35 $yaml .= " eval \$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\n";
541 35 $yaml .= " cpanm --notest App::perlimports\n";
542 35 $yaml .= " find lib -name '*.pm' | xargs perlimports --lint\n";
543 35 $yaml .= " shell: bash\n\n";
544 }
545  
546 39 ▶ if ($enable_coverage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable_coverage) 32 7 39
547 32 my $latest = $perl_versions[-1];
548 32 $yaml .= " - name: Test coverage\n";
549 32 $yaml .= " if: matrix.perl == '$latest' && matrix.os == 'ubuntu-latest'\n";
550 32 $yaml .= " run: |\n";
551 32 $yaml .= " eval \$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\n";
552 32 $yaml .= " cpanm --notest Devel::Cover\n";
553 32 $yaml .= " cover -delete\n";
554 32 $yaml .= " HARNESS_PERL_SWITCHES=-MDevel::Cover prove -lr t/\n";
555 32 $yaml .= " cover\n";
556 32 $yaml .= " shell: bash\n";
557 }
558  
559 39 $yaml .= <<'YAML';
560  
561 - name: Show cpanm build log on failure (Windows)
562 if: runner.os == 'Windows' && failure()
563 shell: pwsh
564 run: Get-Content "$env:USERPROFILE\.cpanm\work\*\build.log" -Tail 100
565  
566 - name: Show cpanm build log on failure (non-Windows)
567 if: runner.os != 'Windows' && failure()
568 run: tail -100 "$HOME/.cpanm/work/*/build.log"
569 YAML
570  
571 39 return $yaml;
572 }
573  
574 41 ▶sub _get_perl_versions($min, $max) {
Subroutine _get_perl_versions: called CC=4 SCAR=13.9
575 # All available Perl versions in descending order.
576 # 5.44 is listed so projects can opt in via max_perl_version => '5.44',
577 # but it is not included in the default matrix (max defaults to 5.42).
578 41 my @all_versions = qw(5.44 5.42 5.40 5.38 5.36 5.34 5.32 5.30 5.28 5.26 5.24 5.22);
579  
580 # Normalize version strings for comparison
581 41 my $min_normalized = _normalize_version($min);
582 41 my $max_normalized = _normalize_version($max);
583  
584 41 my @selected;
585 41 for my $version (@all_versions) {
586 492 my $v_normalized = _normalize_version($version);
587 492 ▶ if ($v_normalized >= $min_normalized && $v_normalized <= $max_normalized) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v_normalized >= $min_normalized and $v_normalized <= $max_normalized) 149 343 492
Condition100%3/3
$v_normalized >= $min_normalized and $v_normalized <= $max_normalized
!ll&&!rl&&r
29350149
MC/DC100%2/2
$v_normalized >= $min_normalized and $v_normalized <= $max_normalized
$v_normalized >= $min_normalized $v_normalized <= $max_normalized
Truth table100%3/3
A and B
A= $v_normalized >= $min_normalizedB= $v_normalized <= $max_normalized
ABresult
0X0
100
111
588 149 push @selected, $version;
589 }
590 }
591  
592 41 return reverse @selected; # Return in ascending order
593 }
594  
595 580 ▶sub _normalize_version($version) {
Subroutine _normalize_version: called CC=3 SCAR=11.7
596 # Convert "5.036" or "5.36" to comparable number
597 580 $version =~ s/^v?//;
598 580 my @parts = split /\./, $version;
599 580 ▶ return sprintf('%d.%03d', $parts[0] // 5, $parts[1] // 0);
Condition50%2/4
$parts[0] // 5
l!l
5800
$parts[1] // 0
l!l
5800
MC/DC0%0/1
$parts[0] // 5
$parts[0]
MC/DC0%0/1
$parts[1] // 0
$parts[1]
Truth table50%1/2
A
A= $parts[0]
Aresult
11
00
Truth table50%1/2
A
A= $parts[1]
Aresult
11
00
600 }
601  
602 =head1 LIMITATIONS
603  
604 =head2 Windows + Perl 5.40 excluded from the generated matrix
605  
606 The shogo82148 C<perl-5.40.4-thr-win32-x64.zip> distribution ships a
607 C<perl.exe> and a C<libperl540.a> from two different builds. Any XS module
608 compiled against that C<libperl540.a> receives handshake key
609 C<0x12c00080>, but C<perl.exe> needs C<0x12d00080>. Even
610 C<Win32::Process> — a core Windows XS module bundled in the zip and loaded
611 transitively by C<IPC::System::Simple> — fails to load with this mismatch,
612 so no XS-using test can pass on this combination.
613  
614 Recompiling XS modules (e.g. via C<cpanm --reinstall YAML::XS>) does not
615 help: the compilation itself links against the broken C<libperl540.a> and
616 inherits the wrong key.
617  
618 The generated workflow therefore includes a C<matrix.exclude> entry for
619 C<{os: windows-latest, perl: '5.40'}>. This entry is only emitted when
620 both C<windows-latest> and C<5.40> are present in the matrix, so workflows
621 that restrict their OS or Perl lists are unaffected.
622  
623 Remove the exclusion once the upstream shogo82148/build-perl distribution
624 is fixed and the C<perl.exe> and C<libperl540.a> in the 5.40.x zip are
625 built from the same source tree.
626  
627 See L<https://github.com/shogo82148/actions-setup-perl/issues/2310> for further information.
628  
629 =head1 AUTHOR
630  
631 Nigel Horne E<lt>njh@nigelhorne.comE<gt>
632  
633 L<https://github.com/nigelhorne>
634  
635 =head1 LICENSE
636  
637 Usage is subject to the GPL2 licence terms.
638 If you use it,
639 please let me know.
640  
641 =cut
642  
643 7 1;
« bin/ghgen ↑ Summary lib/App/GHGen/Detector.pm »