Perl POD for scripts and tests (not modules)

Is there a way to measure POD coverage for scripts (e.g. *.pl )?

I can measure the documentation coverage for packages using Pod::Coverage and Test::Pod::Coverage , but I can not measure it for scripts because Pod::Coverage and the underlying Devel::Symdump use require to check the contents of the package. which failed due to a missing .pm file.

Is there any way around this?

(I must have the POD documentation in the .pl files, so moving everything to the module and documenting it is not a good solution for me. Wherever I could do this, it was already done.)

+6
source share
2 answers

Pod :: Coverage loads (executes) the module so that it can create subtitles and the like. You would have to prevent your .pl from working properly somehow.

 #!/usr/bin/perl ... main(@ARGV) if !$ENV{NO_RUN}; 1; # For do() 

But once you have done this, it is easy, because you specify Pod :: Coverage, which package to check ( package ) and which file to check ( pod_from ).

 #!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; use Pod::Coverage qw( ); { package the_script; local $ENV{NO_RUN} = 1; do "script.pl" or die $@ ; } my $pc = Pod::Coverage->new( package => 'the_script', pod_from => 'script.pl', ); # P::C expects "require the_script;" to succeed. $INC{"the_script.pm"} = 1; my $coverage = $pc->coverage(); die $pc->why_unrated() if !defined($coverage); ok($coverage) or diag("Not covered: ".join(', ', $pc->naked())); 1; 

Tested.

+4
source

Make your program modular. This is what ikegami does , but it forces you to set an environment variable.

 run(@ARGV) unless caller; 

Once your program is truly a module with default behavior, you can use modules on it.

+4
source

Source: https://habr.com/ru/post/926214/


All Articles