1

I am new to Perl and I am trying to generate a coverage report for a Perl script I had. I followed the steps mentioned here to install Devel-Cover https://code.activestate.com/ppm/Devel-Cover/ and ran

perl -MDevel::Cover script

I get some coverage info and that message

    Pod coverage is unavailable.  Please install Pod::Coverage from CPAN.

Then running command cover to generate the report I get cover: Command not found. Tring to run cpan install Pod::Coverage as stated by the output but it fails. I am not sure what I am missing here. I tried using Devel::Coverage too using

 perl -d:Coverage script

But I got that output

Can't locate Devel/Coverage.pm in @INC (you may need to install the Devel::Coverage module) (@INC contains: /spiratech/tools/perllib /home/mmaher/.cache/activestate/02540130/lib/perl5/site_perl/5.32.0/x86_64-linux /home/mmaher/.cache/activestate/02540130/lib/perl5/site_perl/5.32.0 /home/mmaher/.cache/activestate/02540130/lib/perl5/5.32.0/x86_64-linux /home/mmaher/.cache/activestate/02540130/lib/perl5/5.32.0).
BEGIN failed--compilation aborted.
%!s(<nil>)

and I couldn't find any instructions on how to install it. I am using Perl v5.32.0

Merolla
  • 315
  • 2
  • 10
  • Which version of Windows (I assume you are in Windows since you mentioned Active State) are you using? How did you install perl itself? – Håkon Hægland May 20 '21 at 08:06
  • I am using a Centos 7 machine. – Merolla May 20 '21 at 08:08
  • Ok I didn't realize that you could use ActivePerl on Linux. Anyway, how did you install `perl` itself and how did you install `Devel::Cover` ? – Håkon Hægland May 20 '21 at 08:09
  • In the tutorial I was following for installation it didn't say it's working on Windows only and I found an ActiveState version for Linux which I installed. Am I missing something? – Merolla May 20 '21 at 08:15
  • Ok! I'll then have to test ActivePerl on Linux first. I come back to you later. – Håkon Hægland May 20 '21 at 08:27
  • 1
    Hi @Merolla, I have tested now on Ubuntu 21.04, and it works for me. Before I downloaded the ActivePerl build, I added (Add packages) the `Devel-Cover` package, then I downloaded the `.tar.gz` build, extracted it. And then run `sh install.sh` and installed into my home directory at `/home/hakon/activeperl/5.28`. I added `/home/hakon/activeperl/5.28/site/bin:/home/hakon/activeperl/5.28/bin` to my `PATH` variable, when I now type `which cover` it shows that the command `cover` is located in `/home/hakon/activeperl/5.28/bin/cover`. Further I can install `Pod::Coverage` by running... – Håkon Hægland May 20 '21 at 10:13
  • ... `cpan Pod::Coverage` – Håkon Hægland May 20 '21 at 10:14
  • I reinstalled ActivePerl using the steps you stated and added it to the path, but I didn't find neither the command cover nor ppm to run ppm install Devel-Cover in the new installation. – Merolla May 20 '21 at 13:41
  • 1
    *"to run ppm install Devel-Cover in the new installation"* You do not need to install Devel::Cover if you added the package before downloading. Anyway, can you try `cpan` instead of `ppm` to install the package (provided you did not add the package before downloading ActivePerl) ? Try run `cpan Devel::Cover` from the command prompt. – Håkon Hægland May 20 '21 at 18:12
  • Also: What is the output of `perl --version` ? And `which perl` ? – Håkon Hægland May 20 '21 at 18:14
  • I ran `cpan Devel::Cover` using the new installation but running `perl -MDevel::Cover script` kept failing. I tried using Perl from the old installation of ActivePerl I had and running the script and cover worked just fine from that installation. I am not sure which step exactly fixed the issue. Thanks a lot for your help, much appreciated. – Merolla May 20 '21 at 19:20

1 Answers1

3

Zeroth, ActiveState's PPM is old stuff. They have a new State Tool to handle all of that. Note that this is for using their Perl packages. If you aren't using ActiveState's perl, don't use their instructions.

First, you only need Pod::Coverage if you want to check that all of your public subroutines are documented. It's an optional feature.

Second, there's no install command to cpan. Just list the modules that you want or use the command line options. With no options, the -i (for install) is assumed:

$ cpan Pod::Coverage
$ cpan -i Pod::Coverage

Third, the -d switch for debugging assumes that you are loading a module under the Devel namespace. That's why -d:Coverage looks for Devel::Coverage, which it then cannot find.

To load any module that you like, you can use the -M switch. This takes the entire module name:

$ perl -MPod::Coverage

Lastly, once you install Devel::Cover, look where you installed cover and ensure that that directory is in your PATH.

brian d foy
  • 129,424
  • 31
  • 207
  • 592