Test coverage using Devel::Cover

cover --test

Once we know that our tests are passing we could check which lines are exercised in the code during the test execution. For this we can use Devel::Cover by Paul Johnson. First we need to run the tests again now instrumenting with Devel::Cover. This will be much slower than the regular execution but in the end we will get a text report and we will be able to build a nice HTML report with drill down about all the code we ran.

All tests successful.
Files=11, Tests=2078, 50 wallclock secs

use strict;
use warnings;

system('cover -delete');

my $perl = $^X; # the current perl
my $make = ($^O =~ /MSWin/i ? 'dmake' : 'make');

$ENV{DEVEL_COVER_OPTIONS} = "-ignore,perl5lib";

if (-e 'Makefile.PL') {
    system("$perl Makefile.PL");

    if (-d 't/') {
        $ENV{HARNESS_PERL_SWITCHES} = "-MDevel::Cover";
    } else {
        $ENV{PERL5OPT} = "-MDevel::Cover";
    system("$make test");
} elsif (-e "Build.PL") { # Build.PL exists
    system($perl, "Build.PL");
    system($perl, "build", "test");
} else {
    die "Unable to locate 'Makefile.PL' or 'Build.PL'.\n";

system('cover -report html');

CPAN Cover