App-Test-Generator
view release on metacpan or search on metacpan
lib/Devel/App/Test/Generator/LCSAJ/Runtime.pm view on Meta::CPAN
# --------------------------------------------------
sub DB::DB {
my (undef, $file, $line) = caller(0);
return unless defined $file && defined $line;
# Resolve symlinks and relative components to a stable absolute path
my $abs = abs_path($file) // $file;
my $norm = _normalize($abs);
# Never record hits inside this module itself â suffix match is used
# so it works regardless of CWD or install prefix
return if $norm =~ m{(?:^|/)Devel/App/Test/Generator/LCSAJ/Runtime\.pm$};
# If a target list was provided, skip files not in it
if(%TARGET) {
return unless $TARGET{$norm};
}
$HITS{$norm}{$line}++;
}
# --------------------------------------------------
# _write_results
#
# Purpose: Serialise %HITS to a per-process JSON
# file in the output directory.
#
# Entry: None. Reads %HITS and $OUT_DIR.
#
# Exit: Returns nothing. Writes a JSON file.
# Returns immediately if %HITS is empty.
#
# Side effects: Creates $OUT_DIR if absent.
# Writes cover_html/lcsaj_hits/hits_PID.json
#
# Notes: Called from END so it runs even when
# prove exits non-zero â mutation tests
# are expected to fail. PID is included
# in the filename so parallel test runs
# produce separate files without collision.
# --------------------------------------------------
sub _write_results {
return unless %HITS;
# Include PID in filename to support parallel test runs
my $out_file = "$OUT_DIR/hits_$$.json";
make_path($OUT_DIR) unless -d $OUT_DIR;
open my $fh, '>', $out_file or croak "Cannot write $out_file: $!";
print $fh encode_json(\%HITS);
close $fh;
}
1;
__END__
=head1 OUTPUT FORMAT
C<cover_html/lcsaj_hits/hits_PID.json> is a JSON object of the form:
{
"lib/Foo/Bar.pm": { "12": 3, "15": 1, ... },
...
}
Keys are lib-relative paths (C<lib/...>); values are objects mapping line
numbers (as strings) to hit counts. One file is written per process so
parallel test runs produce separate files.
=head1 NOTES ON FILE PLACEMENT
The C<-d:App::Test::Generator::LCSAJ::Runtime> flag causes Perl to load
C<Devel::App::Test::Generator::LCSAJ::Runtime>, which it finds at:
lib/Devel/App/Test/Generator/LCSAJ/Runtime.pm
Ensure this path is on C<@INC> (C<-Mblib> or C<-Ilib> in PERL5OPT).
=head1 SEE ALSO
L<Devel::Cover>, L<App::Test::Generator>
=head1 AUTHOR
Nigel Horne, C<< <njh at nigelhorne.com> >>
Portions of this module's initial design and documentation were created
with the assistance of AI.
=head1 LICENCE AND COPYRIGHT
Copyright 2025-2026 Nigel Horne.
Usage is subject to the terms of GPL2.
If you use it,
please let me know.
=cut
( run in 0.406 second using v1.01-cache-2.11-cpan-13bb782fe5a )