Search code examples
perlcode-coverage

How to setup perl to always run code coverage


I'd like to setup my project to always run the scripts through perl's Devel::Cover module. I've tried replacing the perl binary with something like this

#!/bin/sh
exec /usr/local/bin/original-perl -MDevel::Cover $@

with no success. I'd like to avoid modifying the #! for every script on my system (not the end of the world, I'd just like to figure out a more global solution).

Any thoughts on how to turn on Devel::Cover globally?

Edit: Not trying to run this in production, just trying some experiments to figure out how to split up a tightly coupled codebase. Having some automated way to see what source files are needed for a given subsystem (at least as a start) would be helpful


Solution

  • You can set the environment variable PERL5OPT to always load -MDevel::Cover.

    export PERL5OPT="-MDevel::Cover"
    

    See perlrun for an explanation of this.


    But as Michael Carman said, why would you do this? It will have significant performance costs and might not be useful if you don't run tests.