File Coverage

blib/lib/Pod/Coverage/TrustPod.pm
Criterion Covered Total %
statement 45 45 100.0
branch 10 10 100.0
condition 11 15 73.3
subroutine 9 9 100.0
pod n/a
total 75 79 94.9


line stmt bran cond sub pod time code
1 2     2   3697 use strict;
  2         4  
  2         76  
2 2     2   9 use warnings;
  2         4  
  2         115  
3             package Pod::Coverage::TrustPod;
4             {
5             $Pod::Coverage::TrustPod::VERSION = '0.100003';
6             }
7 2     2   10 use base 'Pod::Coverage::CountParents';
  2         5  
  2         203  
8             # ABSTRACT: allow a module's pod to contain Pod::Coverage hints
9              
10 2     2   10 use Pod::Find qw(pod_where);
  2         5  
  2         110  
11 2     2   1674 use Pod::Eventual::Simple;
  2         63631  
  2         125  
12              
13              
14             sub __get_pod_trust {
15 7     7   20 my ($self, $package, $collect) = @_;
16              
17 7         29 my @parents;
18             {
19 2     2   26 no strict 'refs';
  2         6  
  2         212  
  7         11  
20 7         12 @parents = @{"$package\::ISA"};
  7         33  
21             }
22              
23 7 100       3525 return $collect unless my $file = pod_where( { -inc => 1 }, $package );
24              
25 6         89 my $output = Pod::Eventual::Simple->read_file($file);
26              
27 6         13275 my @hunks = grep {;
28 2     2   12 no warnings 'uninitialized';
  2         3  
  2         1007  
29 62 100 66     689 ((($_->{command} eq 'begin' and $_->{content} =~ /^Pod::Coverage\b/)
      66        
      66        
      100        
30             ...
31             ($_->{command} eq 'end' and $_->{content} =~ /^Pod::Coverage\b/))
32             and $_->{type} =~ m{\Averbatim|text\z})
33             or
34             $_->{command} eq 'for' and $_->{content} =~ s/^Pod::Coverage\b//
35             } @$output;
36              
37 11         22 my @trusted =
38 11         20 grep { s/^\s+//; s/\s+$//; /\S/ }
  11         37  
  5         37  
39 6         17 map { split /\s/m, $_->{content} } @hunks;
40              
41 6         38 $collect->{$_} = 1 for @trusted;
42              
43 6         22 $self->__get_pod_trust($_, $collect) for @parents;
44              
45 6         82 return $collect;
46             }
47              
48             sub _trustme_check {
49 19     19   483042 my ($self, $sym) = @_;
50              
51 19   66     98 my $from_pod = $self->{_trust_from_pod} ||= $self->__get_pod_trust(
52             $self->{package},
53             {}
54             );
55              
56 19 100       83 return 1 if $from_pod->{'*EVERYTHING*'};
57 17 100       183 return 1 if $self->SUPER::_trustme_check($sym);
58 14 100       40 return 1 if grep { $sym =~ /\A$_\z/ } keys %$from_pod;
  14         336  
59 7         61 return;
60             }
61              
62             1;
63              
64             __END__
65              
66             =pod
67              
68             =head1 NAME
69              
70             Pod::Coverage::TrustPod - allow a module's pod to contain Pod::Coverage hints
71              
72             =head1 VERSION
73              
74             version 0.100003
75              
76             =head1 DESCRIPTION
77              
78             This is a Pod::Coverage subclass (actually, a subclass of
79             Pod::Coverage::CountParents) that allows the POD itself to declare certain
80             symbol names trusted.
81              
82             Here is a sample Perl module:
83              
84             package Foo::Bar;
85              
86             =head1 NAME
87              
88             Foo::Bar - a bar at which fooes like to drink
89              
90             =head1 METHODS
91              
92             =head2 fee
93              
94             returns the bar tab
95              
96             =cut
97              
98             sub fee { ... }
99              
100             =head2 fie
101              
102             scoffs at bar tab
103              
104             =cut
105              
106             sub fie { ... }
107              
108             sub foo { ... }
109              
110             =begin Pod::Coverage
111              
112             foo
113              
114             =end Pod::Coverage
115              
116             =cut
117              
118             This file would report full coverage, because any non-empty lines inside a
119             block of POD targeted to Pod::Coverage are treated as C<trustme> patterns.
120             Leading and trailing whitespace is stripped and the remainder is treated as a
121             regular expression anchored at both ends.
122              
123             Remember, anywhere you could use C<=begin> and C<=end> as above, you could
124             instead write:
125              
126             =for Pod::Coverage foo
127              
128             In some cases, you may wish to make the entire file trusted. The special
129             pattern C<*EVERYTHING*> may be provided to do just this.
130              
131             Keep in mind that Pod::Coverage::TrustPod sets up exceptions using the "trust"
132             mechanism rather than the "privacy" mechanism in Pod::Coverage. This is
133             unlikely ever to matter to you, but it's true.
134              
135             =head1 AUTHOR
136              
137             Ricardo SIGNES <rjbs@cpan.org>
138              
139             =head1 COPYRIGHT AND LICENSE
140              
141             This software is copyright (c) 2013 by Ricardo SIGNES.
142              
143             This is free software; you can redistribute it and/or modify it under
144             the same terms as the Perl 5 programming language system itself.
145              
146             =cut