The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test2::Harness::Log::CoverageAggregator - Module for aggregating coverage data from a stream of events.

DESCRIPTION

This module takes a stream of events and produces aggregated coverage data.

SYNOPSIS

    use Test2::Harness::Log::CoverageAggregator;

    my $agg = Test2::Harness::Log::CoverageAggregator->new();

    while (my $e = $log->next_event) {
        $agg->process_event($e);
    }

    my $coverage = $agg->coverage;

    use Test2::Harness::Util::JSON qw/encode_json/;
    open(my $fh, '>', "coverage.json") or die "$!";
    print $fh encode_json($coverage);
    close($fh);

METHODS

$agg->process_event($event)

Process the event, aggregating any coverage info it may contain.

$metrics = $agg->build_metrics()
$metrics = $agg->build_metrics(exclude_private => $BOOL)

Will build metrics, and include them in the output from $agg->coverage() next time it is called.

The exclude_private option, when set to true, will exclude any method that beings with an underscore from the coverage metrics and untested sub list.

Metrics:

    {
        files => {total => 20, tested => 18},
        subs  => {total => 80, tested => 70},
    }
$hashref = $agg->coverage()

Produce a hashref of all aggregated coverage data:

    {
        files => {
        'test_file_a.t' => [
            'lib/MyModule1.pm',
            'lib/MyModule2.pm',
            ...,
        ],
        'test_file_b.t' => [
            'share/css/foo.css',
            'lib/AnotherModule.pm',
            ...
        ],
        ...,
        },
        testmeta => {
            'test_file_a.t' => {...},
        },

        # If you called ->build_metrics this will also be present
        metrics => {
            files => {total => 20, tested => 18},
            subs  => {total => 80, tested => 70},
        },

        # If you called ->build_metrics this will also be present
        untested => {
            files => ['lib/untested.pm', ...],
            subs => {
                'lib/untested.pm' => [ 'foo', 'bar', ... ],
                ...,
            },
        },
    }

SOURCE

The source code repository for Test2-Harness can be found at http://github.com/Test-More/Test2-Harness/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2020 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/