1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
use strict;
use warnings;
package Pod::Coverage::TrustPod;
$Pod::Coverage::TrustPod::VERSION = '0.100005';
use base 'Pod::Coverage::CountParents';
# ABSTRACT: allow a module's pod to contain Pod::Coverage hints
use Pod::Find qw(pod_where);
use Pod::Eventual::Simple;
#pod =head1 DESCRIPTION
#pod
#pod This is a Pod::Coverage subclass (actually, a subclass of
#pod Pod::Coverage::CountParents) that allows the POD itself to declare certain
#pod symbol names trusted.
#pod
#pod Here is a sample Perl module:
#pod
#pod package Foo::Bar;
#pod
#pod =head1 NAME
#pod
#pod Foo::Bar - a bar at which fooes like to drink
#pod
#pod =head1 METHODS
#pod
#pod =head2 fee
#pod
#pod returns the bar tab
#pod
#pod =cut
#pod
#pod sub fee { ... }
#pod
#pod =head2 fie
#pod
#pod scoffs at bar tab
#pod
#pod =cut
#pod
#pod sub fie { ... }
#pod
#pod sub foo { ... }
#pod
#pod =begin Pod::Coverage
#pod
#pod foo
#pod
#pod =end Pod::Coverage
#pod
#pod =cut
#pod
#pod This file would report full coverage, because any non-empty lines inside a
#pod block of POD targeted to Pod::Coverage are treated as C<trustme> patterns.
#pod Leading and trailing whitespace is stripped and the remainder is treated as a
#pod regular expression anchored at both ends.
#pod
#pod Remember, anywhere you could use C<=begin> and C<=end> as above, you could
#pod instead write:
#pod
#pod =for Pod::Coverage foo
#pod
#pod In some cases, you may wish to make the entire file trusted. The special
#pod pattern C<*EVERYTHING*> may be provided to do just this.
#pod
#pod Keep in mind that Pod::Coverage::TrustPod sets up exceptions using the "trust"
#pod mechanism rather than the "privacy" mechanism in Pod::Coverage. This is
#pod unlikely ever to matter to you, but it's true.
#pod
#pod =cut
sub __get_pod_trust {
my ($self, $package, $collect) = @_;
my @parents;
{
no strict 'refs';
@parents = @{"$package\::ISA"};
}
return $collect unless my $file = pod_where( { -inc => 1 }, $package );
my $output = Pod::Eventual::Simple->read_file($file);
my @hunks = grep {;
no warnings 'uninitialized';
((($_->{command} eq 'begin' and $_->{content} =~ /^Pod::Coverage\b/)
...
($_->{command} eq 'end' and $_->{content} =~ /^Pod::Coverage\b/))
and $_->{type} =~ m{\Averbatim|text\z})
or
$_->{command} eq 'for' and $_->{content} =~ s/^Pod::Coverage\b//
} @$output;
my @trusted;
for my $hunk (@hunks) {
my $line = defined $hunk->{start_line} ? $hunk->{start_link} : '?';
my @patterns = grep { s/^\s+//; s/\s+$//; /\S/ }
split /\s/m, $hunk->{content};
PATTERN: for my $pattern (@patterns) {
my $qr;
if ($pattern eq q{*EVERYTHING*}) {
$collect->{$pattern} = qr{.?};
next PATTERN;
}
my $ok = eval { $qr = qr{\A$pattern\z}; 1 };
Carp::croak("can't compile Pod::Coverage::TrustPod regex /$pattern/ at $file, line $line")
unless $ok;
$collect->{$pattern} = $qr;
}
}
$self->__get_pod_trust($_, $collect) for @parents;
return $collect;
}
sub _trustme_check {
my ($self, $sym) = @_;
my $from_pod = $self->{_trust_from_pod} ||= $self->__get_pod_trust(
$self->{package},
{}
);
return 1 if $self->SUPER::_trustme_check($sym);
return 1 if grep { $sym =~ $_ } values %$from_pod;
return;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Pod::Coverage::TrustPod - allow a module's pod to contain Pod::Coverage hints
=head1 VERSION
version 0.100005
=head1 DESCRIPTION
This is a Pod::Coverage subclass (actually, a subclass of
Pod::Coverage::CountParents) that allows the POD itself to declare certain
symbol names trusted.
Here is a sample Perl module:
package Foo::Bar;
=head1 NAME
Foo::Bar - a bar at which fooes like to drink
=head1 METHODS
=head2 fee
returns the bar tab
=cut
sub fee { ... }
=head2 fie
scoffs at bar tab
=cut
sub fie { ... }
sub foo { ... }
=begin Pod::Coverage
foo
=end Pod::Coverage
=cut
This file would report full coverage, because any non-empty lines inside a
block of POD targeted to Pod::Coverage are treated as C<trustme> patterns.
Leading and trailing whitespace is stripped and the remainder is treated as a
regular expression anchored at both ends.
Remember, anywhere you could use C<=begin> and C<=end> as above, you could
instead write:
=for Pod::Coverage foo
In some cases, you may wish to make the entire file trusted. The special
pattern C<*EVERYTHING*> may be provided to do just this.
Keep in mind that Pod::Coverage::TrustPod sets up exceptions using the "trust"
mechanism rather than the "privacy" mechanism in Pod::Coverage. This is
unlikely ever to matter to you, but it's true.
=head1 AUTHOR
Ricardo SIGNES <rjbs@cpan.org>
=head1 CONTRIBUTOR
=for stopwords Andreas Marienborg
Andreas Marienborg <andreas.marienborg@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|