Perl POD覆盖脚本和测试(不是模块)

bat*_*ery 6 perl code-coverage pod

有没有办法测量脚本的POD覆盖范围(例如*.pl)?

我可以使用和测量软件包的文档覆盖率,但是我无法测量它的脚本,因为检查软件包内容的基本用法是由于缺少文件而失败.Pod::CoverageTest::Pod::CoveragePod::CoverageDevel::Symdumprequire.pm

有办法解决这个问题吗?

(我必须在文件中包含POD文档.pl,因此将所有内容移动到模块中并将其记录在那里对我来说并不是一个好的解决方案.无论我在哪里,它都已经这样做了.)

ike*_*ami 4

Pod::Coverage 加载(执行)模块以让它创建子程序等。您必须以某种方式阻止您的 .pl 正常运行。

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

但是一旦您完成了此操作,就很容易了,因为您告诉 Pod::Coverage 要检查哪个包 ( package) 以及要检查哪个文件 ( 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;
Run Code Online (Sandbox Code Playgroud)

已测试。