I've just run into this same problem, but outside the context of XS.
It seems sensible for Pod::Coverage to detect the difference between
"can't compile the package" and "no public symbols defined."
Pod::Coverage already reports "can't find pod" if the package can't be
found at all, but all compilation errors are treated as "no public
symbols defined.
My recommendation is to have _get_syms return an arrayref on success, or
undef on failure. Then coverage() can set why_unrated appropriately.
Here are patches which implement this, as well as a simple test for it.
Thanks!
Alan Ferrency
*** lib/Pod/Coverage.pm.orig Fri Sep 18 15:43:13 2009
--- lib/Pod/Coverage.pm Fri Sep 18 15:53:57 2009
***************
*** 149,155 ****
my $pods = $self->_get_pods;
return unless $pods;
! my %symbols = map { $_ => 0 } $self->_get_syms($package);
print "tying shoelaces\n" if TRACE_ALL;
for my $pod (@$pods) {
--- 149,161 ----
my $pods = $self->_get_pods;
return unless $pods;
! my $syms = $self->_get_syms($package);
!
! unless ($syms) {
! $self->{why_unrated} = "package compilation failed: $@";
! return;
! }
! my %symbols = map { $_ => 0 } @$syms;
print "tying shoelaces\n" if TRACE_ALL;
for my $pod (@$pods) {
***************
*** 324,330 ****
push @symbols, $sym;
}
! return @symbols;
}
=item _get_pods
--- 330,337 ----
push @symbols, $sym;
}
!
! return \@symbols;
}
=item _get_pods
*** lib/Pod/Coverage/ExportOnly.pm.orig Fri Sep 18 15:54:38 2009
--- lib/Pod/Coverage/ExportOnly.pm Fri Sep 18 15:52:40 2009
***************
*** 12,18 ****
my %exports = map { $_ => 1 } @{$package.'::EXPORT'},
@{$package.'::EXPORT_OK'};
! return keys %exports;
}
1;
--- 12,18 ----
my %exports = map { $_ => 1 } @{$package.'::EXPORT'},
@{$package.'::EXPORT_OK'};
! return [keys %exports];
}
1;
*** t/02simple.t.orig Fri Sep 18 15:54:28 2009
--- t/02simple.t Fri Sep 18 15:59:28 2009
***************
*** 1,6 ****
#!/usr/bin/perl -w
use strict;
! use Test::More tests => 33;
use lib 't/lib';
BEGIN {
--- 1,6 ----
#!/usr/bin/perl -w
use strict;
! use Test::More tests => 36;
use lib 't/lib';
BEGIN {
***************
*** 82,84 ****
--- 82,90 ----
$obj = Pod::Coverage->new( package => 'Fully::Qualified' );
is( $obj->coverage, 1, "Fully::Qualified is covered" );
+
+ $obj = new Pod::Coverage package => "Simple9";
+ isa_ok( $obj, 'Pod::Coverage' );
+
+ is( $obj->coverage, undef, "can't deduce for Simple9" );
+ like( $obj->why_unrated, qr/^package compilation failed:/, 'why is
correct' );
*** t/lib/Simple8.pm.orig Fri Sep 18 15:57:36 2009
--- t/lib/Simple8.pm Fri Sep 18 15:56:58 2009
***************
*** 3,5 ****
--- 3,7 ----
=item docs
=cut
+
+ 1;
Finally, new file t/lib/Simple9.pm:
package Simple9;
=item doc
Doesn't return a true value
=cut