lib/Pod/Coverage/More.pm

filter: Statementstmt 96.3% 313 / 325 Branchbran 83.3% 130 / 156 Conditioncond 77.7% 77 / 99 MC/DCmcdc 51.8% 28 / 54 Subroutinesub 100% 53 / 53 Podpod 100% 10 / 10 totaltotal 87.6% 611 / 697 CC 140 SCAR 21.6
CC
140
Cov
90%
_check_returns
20.3
_type_failures
18.4
_check_argument_types
13.0
CRAP 8.7
« blib/lib/Pod/Coverage/More/Generator.pm ↑ Summary lib/Pod/Coverage/More/Analyzer/Perl5_44.pm »
1 # ABSTRACT: Make sure your POD covers more ground than just subroutines
2 # PODNAME: Pod::Coverage::More
3  
4 package Pod::Coverage::More 0.003;
5  
6 13 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use warnings FATAL => q{all};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use re q{/xsaa};
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 13 ▶use List::Util qw{all any none};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Module::Runtime qw{module_notional_filename require_module};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use mro;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use Pod::Find qw(pod_where);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use Types::Standard qw{Any ArrayRef CodeRef GlobRef HashRef ScalarRef Str};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 13 ▶use parent 'Pod::Coverage::TrustPod';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 13 ▶use Pod::Coverage::More::Analyzer;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 ▶use Pod::Coverage::More::Documentation;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # Set to print what the parse and the coverage found, for debugging.
23 13 our $TRACE_ALL = 0;
24  
25  
26 13 our @CHECKS = qw{arguments argument_types returns termination examples};
27  
28 # The fraction of the public subs that the POD documents, as L<Pod::Coverage> rates it,
29 # from the headings that L<Pod::Coverage::More::Documentation> reads.
30 # Nothing when the package has no POD or no public subs, and C<why_unrated> says why.
31 # @returns Num from 0 to 1
32 # @example my $rating = $pc->coverage;
33 15 ▶sub coverage {
Subroutine coverage: called CC=11 SCAR=25.2
Pod documented
34 15 my $self = shift;
35  
36 15 my $package = $self->{package};
37 15 my $doc = $self->_documentation;
38 15 _trace_dump($doc);
39 15 ▶ return unless $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc 1 14 15
40  
41 14 my %symbols = map { $_ => 0 } $self->_get_syms($package);
42  
43 14 ▶ if ( !%symbols && $self->{why_unrated} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %symbols and $self->{"why_unrated"}) 0 14 14
Condition33%1/3
not %symbols and $self->{"why_unrated"}
!ll&&!rl&&r
1400
MC/DC0%0/2
not %symbols and $self->{"why_unrated"}
not %symbols $self->{"why_unrated"}
Truth table33%1/3
not(A) and B
A= not %symbolsB= $self->{"why_unrated"}
ABresult
0X0
100
111
44  
45 # _get_syms failed violently
46 0 return;
47 }
48  
49 14 ▶ print "tying shoelaces\n" if $TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Coverage::More::TRACE_ALL 0 14 14
50 14 foreach my $documentation ( $self->_documentations ) {
51 15 foreach my $pod ( $documentation->identifiers ) {
52 107 ▶ $symbols{$pod} = 1 if exists $symbols{$pod};
Branch: 1 branch
BranchTrueFalseTotal
if exists $symbols{$pod} 107 0 107
53 }
54 }
55 14 foreach my $sym ( keys %symbols ) {
56 111 ▶ $symbols{$sym} = 1 if $self->_trustme_check($sym);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_trustme_check($sym) 2 109 111
57 }
58  
59 # stash the results for later
60 14 $self->{symbols} = \%symbols;
61 14 _trace_dump($self);
62  
63 14 my $symbols = scalar keys %symbols;
64 14 my $documented = scalar grep { $_ } values %symbols;
65 14 ▶ unless ($symbols) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($symbols) 0 14 14
66 0 $self->{why_unrated} = "no public symbols defined";
67 0 return;
68 }
69 14 return $documented / $symbols;
70 }
71  
72  
73 # The failures of each check, for each public sub that has a section in the POD:
74 # a HASHREF from the name of the sub to a HASHREF with C<section>, the section that C<section_for> returns, and C<failures>,
75 # a HASHREF from the name of each check in THE CHECKS to an ARRAYREF of the messages of its failures, empty when it passes.
76 # The report is made once. Nothing when there is no POD to rate, and C<why_unrated> says why.
77 # @returns HashRef the report
78 # @example my $failures = $pc->coverage_report->{resize}{failures}{examples};
79 22 ▶sub coverage_report {
Subroutine coverage_report: called CC=7 SCAR=19.5
Pod documented
80 22 my $self = shift;
81 22 ▶ return $self->{report} if $self->{report};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"report"} 4 18 22
82 18 ▶ return if !$self->_documentation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_documentation 1 17 18
83 17 my $analysis = $self->analysis;
84  
85 17 my %report;
86 17 foreach my $name ( sort $self->_get_syms( $self->{package} ) ) {
87 199 ▶ my $section = $self->section_for($name) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $section = $self->section_for($name) or next 198 1 199
88 198 ▶ my $rec = $analysis->{$name} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $rec = $analysis->{$name} or next 198 0 198
89 198 my %failures;
90 198 foreach my $check (@CHECKS) {
91 990 my $method = "_check_$check";
92 990 $failures{$check} = [ $self->$method( $name, $section, $rec ) ];
93 }
94 198 $report{$name} = { section => $section, failures => \%failures };
95 }
96 17 return $self->{report} = \%report;
97 }
98  
99 # The result of the B<arguments> check over every sub: a HASHREF with C<status>, true when it passes,
100 # and C<message>, the messages of its failures, one per line, or undef.
101 # @returns HashRef with status and message
102 # @example my $result = $pc->coverage_arguments;
103 # @example print $result->{message} if !$result->{status};
104 4 ▶sub coverage_arguments { my ($self) = @_; return $self->_check_result('arguments') }
Subroutine coverage_arguments: called CC=1 SCAR=0.0
Pod documented
105  
106 # The result of the B<argument_types> check, as C<coverage_arguments> returns it for its check.
107 # @returns HashRef with status and message
108 # @example my $result = $pc->coverage_argument_types;
109 2 ▶sub coverage_argument_types { my ($self) = @_; return $self->_check_result('argument_types') }
Subroutine coverage_argument_types: called CC=1 SCAR=0.0
Pod documented
110  
111 # The result of the B<returns> check, as C<coverage_arguments> returns it for its check.
112 # @returns HashRef with status and message
113 # @example my $result = $pc->coverage_return_types;
114 2 ▶sub coverage_return_types { my ($self) = @_; return $self->_check_result('returns') }
Subroutine coverage_return_types: called CC=1 SCAR=0.0
Pod documented
115  
116 # The result of the B<termination> check, as C<coverage_arguments> returns it for its check.
117 # @returns HashRef with status and message
118 # @example my $result = $pc->coverage_termination;
119 2 ▶sub coverage_termination { my ($self) = @_; return $self->_check_result('termination') }
Subroutine coverage_termination: called CC=1 SCAR=0.0
Pod documented
120  
121 # The result of the B<examples> check, as C<coverage_arguments> returns it for its check.
122 # @returns HashRef with status and message
123 # @example my $result = $pc->coverage_examples;
124 1 ▶sub coverage_examples { my ($self) = @_; return $self->_check_result('examples') }
Subroutine coverage_examples: called CC=1 SCAR=0.0
Pod documented
125  
126 11 ▶sub _check_result {
Subroutine _check_result: called CC=6 SCAR=17.9
127 11 my ( $self, $check ) = @_;
128 11 ▶ my $report = $self->coverage_report or return { status => 0, message => ( $self->{why_unrated} // 'no POD' ) . "\n" };
Branch: 1 branch
BranchTrueFalseTotal
my $report = $self->coverage_report or return {"status", 0, "message", ($self->{"why_unrated"} // "no POD") . "\n"} 10 1 11
Condition50%1/2
$self->{"why_unrated"} // "no POD"
l!l
10
MC/DC0%0/1
$self->{"why_unrated"} // "no POD"
$self->{"why_unrated"}
Truth table50%1/2
A
A= $self->{"why_unrated"}
Aresult
11
00
129 10 my @failures;
130 10 foreach my $name ( sort keys %$report ) {
131 192 push @failures, @{ $report->{$name}{failures}{$check} };
132 }
133 10 ▶ return { status => @failures ? 0 : 1, message => @failures ? join( q{}, map { "$_\n" } @failures ) : undef };
Branch: 2 branches
BranchTrueFalseTotal
@failures ? : 6 4 10
@failures ? : 6 4 10
134 }
135  
136 # The names that a POD argument can match: the parameters, the keys of named arguments, and the declared parameters.
137 145 ▶sub _accepted_names {
Subroutine _accepted_names: called CC=9 SCAR=24.0
138 145 my ($rec) = @_;
139 145 my @names;
140 145 foreach my $param ( @{ $rec->{params} } ) {
141 211 ▶ push @names, $param->{name} if defined $param->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->{"name"} 191 20 211
142 211 ▶ push @names, @{ $param->{keys} || [] } if !_is_invocant( $rec, $param );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_invocant($rec, $param) 188 23 211
Condition100%2/2
$param->{'keys'} || []
l!l
3185
MC/DC100%1/1
$param->{'keys'} || []
$param->{'keys'}
Truth table100%2/2
A
A= $param->{'keys'}
Aresult
11
00
143 }
144 145 ▶ foreach my $param ( @{ $rec->{declared}{params} || [] } ) {
Condition50%1/2
$rec->{'declared'}{'params'} || []
l!l
0145
MC/DC0%0/1
$rec->{'declared'}{'params'} || []
$rec->{'declared'}{'params'}
Truth table50%1/2
A
A= $rec->{'declared'}{'params'}
Aresult
11
00
145 0 ▶ push @names, $param->{name} if defined $param->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->{"name"} 0 0 0
146 0 ▶ push @names, $param->{named} if defined $param->{named};
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->{"named"} 0 0 0
147 }
148 145 return _bare_names(@names);
149 }
150  
151 # The arguments in ARGS, the list of the POD, that stand at the position of a parameter with no name,
152 # such as a placeholder in a signature, which the POD may call anything.
153 158 ▶sub _at_unnamed_params {
Subroutine _at_unnamed_params: called CC=7 SCAR=19.5
154 158 my ( $rec, @args ) = @_;
155 158 my ( @params, %invocants );
156 158 foreach my $param ( sort { $a->{index} <=> $b->{index} } @{ $rec->{params} } ) {
157 233 ▶ if ( _is_invocant( $rec, $param ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_invocant($rec, $param)) 27 206 233
158 27 ▶ $invocants{ Pod::Coverage::More::Documentation->bare_name( $param->{name} ) } = 1 if defined $param->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->{"name"} 27 0 27
159 27 next;
160 }
161 206 push @params, $param;
162 }
163 158 my @listed;
164 158 foreach my $arg (@args) {
165 220 ▶ push @listed, $arg if !$invocants{ Pod::Coverage::More::Documentation->bare_name($arg) };
Branch: 1 branch
BranchTrueFalseTotal
unless $invocants{"Pod::Coverage::More::Documentation"->bare_name($arg)} 220 0 220
166 }
167 158 ▶ return map { $listed[$_] } grep { $_ <= $#params && !defined $params[$_]{name} } 0 .. $#listed;
Condition100%3/3
$_ <= $#params && !defined($params[$_]{'name'})
!ll&&!rl&&r
1418224
MC/DC100%2/2
$_ <= $#params && !defined($params[$_]{'name'})
$_ <= $#params !defined($params[$_]{'name'})
Truth table100%3/3
A && not(B)
A= $_ <= $#paramsB= !defined($params[$_]{'name'})
ABresult
0X0
100
111
168 }
169  
170 # Whether PARAM is the object or class that a method is called on, whose keys are its fields and not named arguments.
171 444 ▶sub _is_invocant {
Subroutine _is_invocant: called CC=6 SCAR=18.3
172 444 my ( $rec, $param ) = @_;
173 444 ▶ return 1 if $param->{source} eq 'invocant';
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"source"} eq "invocant" 0 444 444
174 444 ▶ my $name = $param->{name} // return 0;
Condition100%2/2
$param->{"name"} // (return 0)
l!l
40044
MC/DC100%1/1
$param->{"name"} // (return 0)
$param->{"name"}
Truth table100%2/2
A
A= $param->{"name"}
Aresult
11
00
175 400 ▶ return 1 if $name =~ m/\A\$(?:self|class|proto)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\A\$(?:self|class|proto)\z/aasx 50 350 400
176 350 ▶ return @{ $rec->{usage}{$name}{methods} || [] } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$rec->{'usage'}{$name}{'methods'} or [];} ? : 0 350 350
Condition50%1/2
$rec->{'usage'}{$name}{'methods'} || []
l!l
0350
MC/DC0%0/1
$rec->{'usage'}{$name}{'methods'} || []
$rec->{'usage'}{$name}{'methods'}
Truth table50%1/2
A
A= $rec->{'usage'}{$name}{'methods'}
Aresult
11
00
177 }
178  
179 # Whether the code of a sub shows nothing of its arguments: an XS sub or a constant, or a stub with no signature
180 # that reads nothing of @_, as a default that subclasses override. Its POD names its arguments on the author's word.
181 396 ▶sub _is_stub {
Subroutine _is_stub: called CC=7 SCAR=19.9
182 396 my ($rec) = @_;
183 396 ▶ return 1 if $rec->{kind} ne 'perl';
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"kind"} ne "perl" 0 396 396
184 396 ▶ return 0 if $rec->{signature} || $rec->{reads_args} || @{ $rec->{params} } || @{ $rec->{declared}{params} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"signature"} or $rec->{"reads_args"} or @{$rec->{"params"};} or @{$rec->{"declared"}{"params"} or [];} 290 106 396
Condition72%8/11
$rec->{"signature"} or $rec->{"reads_args"} or @{$rec->{"params"};} or @{$rec->{"declared"}{"params"} or [];}
l!l&&r!l&&!r
2900106
$rec->{"signature"} or $rec->{"reads_args"} or @{$rec->{"params"};}
l!l&&r!l&&!r
2900106
$rec->{"signature"} or $rec->{"reads_args"}
l!l&&r!l&&!r
98192106
$rec->{'declared'}{'params'} || []
l!l
0106
MC/DC50%2/4
$rec->{"signature"} or $rec->{"reads_args"} or @{$rec->{"params"};} or @{$rec->{"declared"}{"params"} or [];}
$rec->{"signature"} $rec->{"reads_args"} @{$rec->{"params"};} @{$rec->{"declared"}{"params"} or [];}
MC/DC0%0/1
$rec->{'declared'}{'params'} || []
$rec->{'declared'}{'params'}
Truth table60%3/5
A or B or C or D
A= $rec->{"signature"}B= $rec->{"reads_args"}C= @{$rec->{"params"};}D= @{$rec->{"declared"}{"params"} or [];}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table50%1/2
A
A= $rec->{'declared'}{'params'}
Aresult
11
00
185 106 return 1;
186 }
187  
188 198 ▶sub _check_arguments {
Subroutine _check_arguments: called CC=5 SCAR=16.1
189 198 my ( $self, $name, $section, $rec ) = @_;
190 198 ▶ return if _is_stub($rec);
Branch: 1 branch
BranchTrueFalseTotal
if _is_stub($rec) 53 145 198
191 145 ▶ my $args = $section->{args}{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $args = $section->{"args"}{$name} or return 145 0 145
192 145 my @accepted = _accepted_names($rec);
193 145 my %unnamed = map { $_ => 1 } _at_unnamed_params( $rec, @$args );
194 145 my @failures;
195 145 foreach my $arg ( _bare_names( grep { !$unnamed{$_} } @$args ) ) {
196 182 ▶ push @failures, "Var Mismatch for function $name: $arg not in @accepted" if none { $_ eq $arg } @accepted;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $_ eq $arg; } , @accepted) 15 167 182
197 }
198 145 return @failures;
199 }
200  
201 13 our %SIGIL_TYPES = ( '$' => 'scalar', '@' => 'array', '%' => 'hash' );
202  
203 198 ▶sub _check_argument_types {
Subroutine _check_argument_types: called CC=13 SCAR=25.7
204 198 my ( $self, $name, $section, $rec ) = @_;
205 198 ▶ return if _is_stub($rec);
Branch: 1 branch
BranchTrueFalseTotal
if _is_stub($rec) 53 145 198
206 145 ▶ my $args = $section->{args}{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $args = $section->{"args"}{$name} or return 145 0 145
207 145 my @params = grep { defined } map { $_->{name} } @{ $rec->{params} };
208  
209 # Strategy 1: the POD wrote each argument with its sigil, so it must match the sigil of the parameter, in any case.
210 145 ▶ if ( any { m/\A[\$*\\@%&|]/ } @$args ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { /\A[\$*\\\@%&|]/aasx; } , @$args)) 13 132 145
211 13 my %unnamed = map { $_ => 1 } _at_unnamed_params( $rec, @$args );
212 13 my @failures;
213 13 foreach my $arg ( map { s/\A\\[\$*@%&|]/\$/r } grep { !$unnamed{$_} } @$args ) {
214 14 ▶ push @failures, "Var Type Mismatch for function $name: $arg not in @params" if none { lc($_) eq lc($arg) } @params;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { lc $_ eq lc $arg; } , @params) 2 12 14
215 }
216 13 return @failures;
217 }
218  
219 # Strategy 2: the type of each argument is in an =item of its section.
220 132 ▶ my $types = $section->{types}{$name} || {};
Condition100%2/2
$section->{'types'}{$name} || {}
l!l
11022
MC/DC100%1/1
$section->{'types'}{$name} || {}
$section->{'types'}{$name}
Truth table100%2/2
A
A= $section->{'types'}{$name}
Aresult
11
00
221 132 my @failures;
222 132 foreach my $arg (@$args) {
223 184 ▶ push @failures, "Var $arg not documented whatsoever for $name!" if !$types->{ Pod::Coverage::More::Documentation->bare_name($arg) };
Branch: 1 branch
BranchTrueFalseTotal
unless $$types{"Pod::Coverage::More::Documentation"->bare_name($arg)} 37 147 184
224 }
225 132 foreach my $param ( @{ $rec->{params} } ) {
226 189 ▶ next if !defined $param->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param->{"name"} 16 173 189
227 173 ▶ my ( $sigil, $arg_name ) = $param->{name} =~ m/\A(.)(.+)\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $param->{"name"} =~ /\A(.)(.+)\z/aasx or next 173 0 173
228 173 ▶ my $documented = $types->{ lc $arg_name } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $documented = $$types{lc $arg_name} or next 120 53 173
229 120 push @failures, _type_failures( $name, $arg_name, $SIGIL_TYPES{$sigil}, $documented, $param );
230 }
231 132 return @failures;
232 }
233  
234 # The failures of the documented type of one parameter: against its sigil, its declared type, and its uses.
235 120 ▶sub _type_failures {
Subroutine _type_failures: called CC=18 SCAR=29.1
236 120 my ( $name, $arg_name, $sigil_type, $documented, $param ) = @_;
237 120 my $word = $documented->{word};
238 120 ▶ return "No type declared for arg $arg_name of $name" if $word eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "" 6 114 120
239 114 ▶ return if $word eq 'mixed';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "mixed" 1 113 114
240  
241 # An item with the sigil of a list documents the type of each element, which the code shows nothing of.
242 113 ▶ if ( my $elements = $documented->{sigil} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elements = $documented->{"sigil"}) 9 104 113
243 9 ▶ return if defined $sigil_type && $SIGIL_TYPES{$elements} eq $sigil_type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sigil_type and $Pod::Coverage::More::SIGIL_TYPES{$elements} eq $sigil_type 5 4 9
Condition66%2/3
defined $sigil_type and $Pod::Coverage::More::SIGIL_TYPES{$elements} eq $sigil_type
!ll&&!rl&&r
045
MC/DC50%1/2
defined $sigil_type and $Pod::Coverage::More::SIGIL_TYPES{$elements} eq $sigil_type
defined $sigil_type $Pod::Coverage::More::SIGIL_TYPES{$elements} eq $sigil_type
Truth table66%2/3
A and B
A= defined $sigil_typeB= $Pod::Coverage::More::SIGIL_TYPES{$elements} eq $sigil_type
ABresult
0X0
100
111
244 4 ▶ return "Type mismatch for arg $arg_name of $name: documented the elements of $elements$arg_name, expected " . ( $sigil_type // 'a parameter with a sigil' );
Condition50%1/2
$sigil_type // "a parameter with a sigil"
l!l
40
MC/DC0%0/1
$sigil_type // "a parameter with a sigil"
$sigil_type
Truth table50%1/2
A
A= $sigil_type
Aresult
11
00
245 }
246  
247 # A word for a container names the kind of the parameter itself, and only a container parameter is one.
248 104 ▶ if ( defined $sigil_type && $word ne $sigil_type && ( $word eq 'array' || $word eq 'hash' || $sigil_type ne 'scalar' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sigil_type and $word ne $sigil_type and $word eq "array" || $word eq "hash" || $sigil_type ne "scalar") 2 102 104
Condition75%9/12
defined $sigil_type and $word ne $sigil_type and $word eq "array" || $word eq "hash" || $sigil_type ne "scalar"
!ll&&!rl&&r
6962
defined $sigil_type and $word ne $sigil_type
!ll&&!rl&&r
0698
$word eq "array" or $word eq "hash" or $sigil_type ne "scalar"
l!l&&r!l&&!r
2096
$word eq "array" or $word eq "hash"
l!l&&r!l&&!r
0296
MC/DC40%2/5
defined $sigil_type and $word ne $sigil_type and $word eq "array" || $word eq "hash" || $sigil_type ne "scalar"
defined $sigil_type $word ne $sigil_type $word eq "array" $word eq "hash" $sigil_type ne "scalar"
Truth table50%3/6
A and B and C or D or E
A= defined $sigil_typeB= $word ne $sigil_typeC= $word eq "array"D= $word eq "hash"E= $sigil_type ne "scalar"
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
249 2 return "Type mismatch for arg $arg_name of $name: got $word, expected $sigil_type";
250 }
251  
252 102 ▶ my $type = $documented->{type} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $type = $documented->{"type"} or return 102 0 102
253 102 ▶ if ( my $declared = $param->{declared} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $declared = $param->{"declared"}) 12 90 102
254 12 ▶ return if $type->equals($declared) || $type->is_subtype_of($declared);
Branch: 1 branch
BranchTrueFalseTotal
if $type->equals($declared) or $type->is_subtype_of($declared) 8 4 12
Condition100%3/3
$type->equals($declared) or $type->is_subtype_of($declared)
l!l&&r!l&&!r
444
MC/DC100%2/2
$type->equals($declared) or $type->is_subtype_of($declared)
$type->equals($declared) $type->is_subtype_of($declared)
Truth table100%3/3
A or B
A= $type->equals($declared)B= $type->is_subtype_of($declared)
ABresult
1X1
011
000
255 4 return "Type mismatch for arg $arg_name of $name: documented " . $type->display_name . ", but $param->{declared_by} declares " . $declared->display_name;
256 }
257 90 ▶ if ( my $inferred = $param->{inferred} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inferred = $param->{"inferred"}) 40 50 90
258 40 ▶ return "Type mismatch for arg $arg_name of $name: documented " . $type->display_name . ', but the code uses it as ' . $inferred->display_name
Branch: 1 branch
BranchTrueFalseTotal
if _contradicts($type, $inferred) 4 36 40
259 if _contradicts( $type, $inferred );
260 }
261 86 return;
262 }
263  
264 # The kinds of value that no type of another kind can be.
265 13 our @KINDS = ( HashRef, ArrayRef, CodeRef, ScalarRef, GlobRef, Str );
266  
267 96 ▶sub _kinds_of {
Subroutine _kinds_of: called CC=5 SCAR=16.3
268 96 my ($type) = @_;
269 0 ▶ my @members = $type->can('type_constraints') ? @{ $type->type_constraints } : ($type);
Branch: 1 branch
BranchTrueFalseTotal
$type->can('type_constraints') ? : 0 96 96
270 96 my %kinds;
271 96 foreach my $member (@members) {
272 96 foreach my $kind (@KINDS) {
273 576 ▶ $kinds{ $kind->name } = 1 if $member->is_a_type_of($kind);
Branch: 1 branch
BranchTrueFalseTotal
if $member->is_a_type_of($kind) 86 490 576
274 }
275 }
276 96 return \%kinds;
277 }
278  
279 # Whether a documented type and a type that the code implies are of different kinds, as a hash reference and an array reference.
280 48 ▶sub _contradicts {
Subroutine _contradicts: called CC=4 SCAR=13.9
281 48 my ( $documented, $inferred ) = @_;
282 48 my $documented_kinds = _kinds_of($documented);
283 48 my $inferred_kinds = _kinds_of($inferred);
284 48 ▶ return 0 if !%$documented_kinds || !%$inferred_kinds;
Branch: 1 branch
BranchTrueFalseTotal
unless %$documented_kinds and %$inferred_kinds 10 38 48
Condition66%2/3
%$documented_kinds and %$inferred_kinds
!ll&&!rl&&r
10038
MC/DC50%1/2
%$documented_kinds and %$inferred_kinds
%$documented_kinds %$inferred_kinds
Truth table66%2/3
A and B
A= %$documented_kindsB= %$inferred_kinds
ABresult
0X0
100
111
285 38 ▶ return ( none { $inferred_kinds->{$_} } keys %$documented_kinds ) ? 1 : 0;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
&none(sub { $inferred_kinds->{$_}; } , keys %$documented_kinds) ? : 8 30 38
286 }
287  
288 198 ▶sub _check_returns {
Subroutine _check_returns: called CC=20 SCAR=30.1
289 198 my ( $self, $name, $section, $rec ) = @_;
290 198 my @returned = grep { $_->{type} ne 'empty' } @{ $rec->{returns} };
291 198 ▶ my @declared = @{ $rec->{declared}{returns} || [] };
Condition50%1/2
$rec->{'declared'}{'returns'} || []
l!l
0198
MC/DC0%0/1
$rec->{'declared'}{'returns'} || []
$rec->{'declared'}{'returns'}
Truth table50%1/2
A
A= $rec->{'declared'}{'returns'}
Aresult
11
00
292 198 ▶ return if !@returned && !@declared;
Branch: 1 branch
BranchTrueFalseTotal
unless @returned or @declared 75 123 198
Condition66%2/3
@returned or @declared
l!l&&r!l&&!r
123075
MC/DC50%1/2
@returned or @declared
@returned @declared
Truth table66%2/3
A or B
A= @returnedB= @declared
ABresult
1X1
011
000
293  
294 123 my @statements = @{ $section->{returns} };
295 123 ▶ return "No return value documented for $name" if !@statements;
Branch: 1 branch
BranchTrueFalseTotal
unless @statements 21 102 123
296 102 my @documented = map { @{ $_->{types} } } @statements;
297 102 ▶ if ( !@documented ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@documented) 32 70 102
298 32 ▶ return if !_all_nothing(@statements);
Branch: 1 branch
BranchTrueFalseTotal
unless _all_nothing(@statements) 16 16 32
299  
300 # What a call returns is not in this code, and may be nothing, so only another value contradicts the POD.
301 16 ▶ return if !@declared && all { $_->{type} eq 'call' || $_->{type} eq 'method' } @returned;
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
BranchTrueFalseTotal
if not @declared and &all(sub { $_->{"type"} eq "call" or $_->{"type"} eq "method"; } , @returned) 8 8 16
$_->{"type"} eq "call" or $_->{"type"} eq "method" 8 12 20
Condition66%2/3
not @declared and &all(sub { $_->{"type"} eq "call" or $_->{"type"} eq "method"; } , @returned)
!ll&&!rl&&r
088
MC/DC50%1/2
not @declared and &all(sub { $_->{"type"} eq "call" or $_->{"type"} eq "method"; } , @returned)
not @declared &all(sub { $_->{"type"} eq "call" or $_->{"type"} eq "method"; } , @returned)
Truth table66%2/3
not(A) and B
A= not @declaredB= &all(sub { $_->{"type"} eq "call" or $_->{"type"} eq "method"; } , @returned)
ABresult
0X0
100
111
302 8 return "$name is documented to return nothing, but it returns a value";
303 }
304  
305 70 my @failures;
306 my %seen;
307 0 my @checked = ( ( map { [ $_->{constraint}, "line $_->{line}", $_->{weak}, $_ ] } grep { $_->{constraint} } @returned ), ( map { [ $_, 'declared', 0 ] } @declared ) );
308 70 foreach my $returned (@checked) {
309 72 my ( $type, $where, $weak, $evidence ) = @$returned;
310 72 ▶ next if _covered( $type, \@documented );
Branch: 1 branch
BranchTrueFalseTotal
if _covered($type, \@documented) 40 32 72
311  
312 # A literal is one value, which can satisfy a type that its own type is no subtype of, as 1 satisfies Bool.
313 32 ▶ next if $evidence && exists $evidence->{value} && _value_covered( $evidence->{value}, \@documented );
Branch: 1 branch
BranchTrueFalseTotal
if $evidence and exists $evidence->{"value"} and _value_covered($evidence->{"value"}, \@documented) 8 24 32
Condition83%5/6
$evidence and exists $evidence->{"value"} and _value_covered($evidence->{"value"}, \@documented)
!ll&&!rl&&r
2048
$evidence and exists $evidence->{"value"}
!ll&&!rl&&r
02012
MC/DC66%2/3
$evidence and exists $evidence->{"value"} and _value_covered($evidence->{"value"}, \@documented)
$evidence exists $evidence->{"value"} _value_covered($evidence->{"value"}, \@documented)
Truth table75%3/4
A and B and C
A= $evidenceB= exists $evidence->{"value"}C= _value_covered($evidence->{"value"}, \@documented)
ABCresult
0XX0
10X0
1100
1111
314  
315 # The code shows the kind of what it returns, as [ ... ] is an ArrayRef, but not what is inside it.
316 24 ▶ next if $evidence && !exists $evidence->{value} && _parameterizes( $type, \@documented );
Branch: 1 branch
BranchTrueFalseTotal
if $evidence and not exists $evidence->{"value"} and _parameterizes($type, \@documented) 4 20 24
Condition83%5/6
$evidence and not exists $evidence->{"value"} and _parameterizes($type, \@documented)
!ll&&!rl&&r
4164
$evidence and not exists $evidence->{"value"}
!ll&&!rl&&r
0420
MC/DC66%2/3
$evidence and not exists $evidence->{"value"} and _parameterizes($type, \@documented)
$evidence not exists $evidence->{"value"} _parameterizes($type, \@documented)
Truth table75%3/4
A and not(B) and C
A= $evidenceB= not exists $evidence->{"value"}C= _parameterizes($type, \@documented)
ABCresult
0XX0
10X0
1100
1111
317  
318 # The type of the result of an operator is weak: overloading can change it, so it fails only when it contradicts.
319 20 ▶ next if $weak && any { !_contradicts( $_, $type ) } @documented;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $weak and &any(sub { not _contradicts($_, $type); } , @documented) 4 16 20
Condition100%3/3
$weak and &any(sub { not _contradicts($_, $type); } , @documented)
!ll&&!rl&&r
1244
MC/DC100%2/2
$weak and &any(sub { not _contradicts($_, $type); } , @documented)
$weak &any(sub { not _contradicts($_, $type); } , @documented)
Truth table100%3/3
A and B
A= $weakB= &any(sub { not _contradicts($_, $type); } , @documented)
ABresult
0X0
100
111
320 16 ▶ next if $seen{ $type->display_name }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$type->display_name}++ 0 16 16
321 16 push @failures, "Return type mismatch for $name: returns " . $type->display_name . " ($where), documented as " . join( ' or ', _names_of( \@documented ) );
322 }
323 70 return @failures;
324 }
325  
326 # Whether the statements of the return value only say that it returns nothing.
327 32 ▶sub _all_nothing {
Subroutine _all_nothing: called CC=2 SCAR=7.0
328 32 my (@statements) = @_;
329 32 ▶ return ( any { $_->{nothing} } @statements ) && ( none { @{ $_->{types} } } @statements );
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition66%2/3
&any(sub { $_->{'nothing'}; } , @statements) && &none(sub { @{$_->{'types'};}; } , @statements)
!ll&&!rl&&r
16016
MC/DC50%1/2
&any(sub { $_->{'nothing'}; } , @statements) && &none(sub { @{$_->{'types'};}; } , @statements)
&any(sub { $_->{'nothing'}; } , @statements) &none(sub { @{$_->{'types'};}; } , @statements)
Truth table66%2/3
A && B
A= &any(sub { $_->{'nothing'}; } , @statements)B= &none(sub { @{$_->{'types'};}; } , @statements)
ABresult
0X0
100
111
330 }
331  
332 12 ▶sub _value_covered {
Subroutine _value_covered: called CC=3 SCAR=11.0
333 12 my ( $value, $documented ) = @_;
334 12 foreach my $candidate (@$documented) {
335 12 ▶ return 1 if $candidate->check($value);
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->check($value) 8 4 12
336 }
337 4 return 0;
338 }
339  
340 72 ▶sub _covered {
Subroutine _covered: called CC=5 SCAR=16.1
341 72 my ( $type, $documented ) = @_;
342 72 foreach my $candidate (@$documented) {
343 77 ▶ return 1 if $candidate->equals(Any) || $type->equals($candidate) || $type->is_subtype_of($candidate);
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->equals(&Any()) or $type->equals($candidate) or $type->is_subtype_of($candidate) 40 37 77
Condition83%5/6
$candidate->equals(&Any()) or $type->equals($candidate) or $type->is_subtype_of($candidate)
l!l&&r!l&&!r
40037
$candidate->equals(&Any()) or $type->equals($candidate)
l!l&&r!l&&!r
53537
MC/DC66%2/3
$candidate->equals(&Any()) or $type->equals($candidate) or $type->is_subtype_of($candidate)
$candidate->equals(&Any()) $type->equals($candidate) $type->is_subtype_of($candidate)
Truth table75%3/4
A or B or C
A= $candidate->equals(&Any())B= $type->equals($candidate)C= $type->is_subtype_of($candidate)
ABCresult
1XX1
01X1
0011
0000
344 }
345 32 return 0;
346 }
347  
348 # Whether a documented type is a parameterization of TYPE, as ArrayRef[HashRef] is of ArrayRef.
349 20 ▶sub _parameterizes {
Subroutine _parameterizes: called CC=4 SCAR=13.9
350 20 my ( $type, $documented ) = @_;
351 20 foreach my $candidate (@$documented) {
352 20 ▶ return 1 if $candidate->is_parameterized && $candidate->parameterized_from->equals($type);
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->is_parameterized and $candidate->parameterized_from->equals($type) 4 16 20
Condition100%3/3
$candidate->is_parameterized and $candidate->parameterized_from->equals($type)
!ll&&!rl&&r
1244
MC/DC100%2/2
$candidate->is_parameterized and $candidate->parameterized_from->equals($type)
$candidate->is_parameterized $candidate->parameterized_from->equals($type)
Truth table100%3/3
A and B
A= $candidate->is_parameterizedB= $candidate->parameterized_from->equals($type)
ABresult
0X0
100
111
353 }
354 16 return 0;
355 }
356  
357 # The names of NAMES without sigils, in lower case, as the POD and the code are compared.
358 290 ▶sub _bare_names {
Subroutine _bare_names: called CC=2 SCAR=6.9
359 290 my (@names) = @_;
360 290 my @bare;
361 290 foreach my $name (@names) {
362 378 push @bare, Pod::Coverage::More::Documentation->bare_name($name);
363 }
364 290 return @bare;
365 }
366  
367 # The display names of the constraints in the ARRAYREF TYPES.
368 16 ▶sub _names_of {
Subroutine _names_of: called CC=2 SCAR=6.9
369 16 my ($types) = @_;
370 16 my @names;
371 16 foreach my $type (@$types) {
372 16 push @names, $type->display_name;
373 }
374 16 return @names;
375 }
376  
377 198 ▶sub _check_termination {
Subroutine _check_termination: called CC=3 SCAR=11.0
378 198 my ( $self, $name, $section, $rec ) = @_;
379 198 my @uncaught = grep { !$_->{caught} } @{ $rec->{dies} };
380 198 ▶ return if !@uncaught || @{ $section->{terminations} };
Branch: 1 branch
BranchTrueFalseTotal
if not @uncaught or @{$section->{"terminations"};} 194 4 198
Condition100%3/3
not @uncaught or @{$section->{"terminations"};}
l!l&&r!l&&!r
18954
MC/DC100%2/2
not @uncaught or @{$section->{"terminations"};}
not @uncaught @{$section->{"terminations"};}
Truth table100%3/3
not(A) or B
A= not @uncaughtB= @{$section->{"terminations"};}
ABresult
1X1
011
000
381 4 return "$name can terminate ($uncaught[0]{via} at line $uncaught[0]{line}), but its POD does not say so";
382 }
383  
384 198 ▶sub _check_examples {
Subroutine _check_examples: called CC=2 SCAR=6.9
385 198 my ( $self, $name, $section ) = @_;
386 198 ▶ return if any { m/\b\Q$name\E\s*\(|->\s*\Q$name\E\b/ } @{ $section->{verbatim} };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { /\b\Q$name\E\s*\(|->\s*\Q$name\E\b/aasx; } , @{$$section{"verbatim"};}) 62 136 198
387 136 return "No example of $name in its POD";
388 }
389  
390 29 ▶sub _trace_dump {
Subroutine _trace_dump: called CC=2 SCAR=10.1
391 29 my ($data) = @_;
392 29 ▶ return if !$TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
unless $Pod::Coverage::More::TRACE_ALL 29 0 29
393 0 require Data::Dumper;
394 0 print Data::Dumper::Dumper($data);
395 0 return;
396 }
397  
398 61 ▶sub _documentation {
Subroutine _documentation: called CC=8 SCAR=21.1
399 61 my $self = shift;
400 61 ▶ return $self->{documentation} if $self->{documentation};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"documentation"} 32 29 61
401  
402 29 my $package = $self->{package};
403 29 ▶ print "getting pod location for '$package'\n" if $TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Coverage::More::TRACE_ALL 0 29 29
404 29 ▶ $self->{pod_from} ||= pod_where( { -inc => 1 }, $package ) // $INC{ module_notional_filename($package) };
Condition100%6/6
$self->{"pod_from"} ||= pod_where({"-inc", 1}, $package) // $INC{&module_notional_filename($package)}
l!l&&r!l&&!r
1262
pod_where({"-inc", 1}, $package) // $INC{&module_notional_filename($package)}
l!l&&r!l&&!r
2242
MC/DC0%0/3
$self->{"pod_from"} ||= pod_where({"-inc", 1}, $package) // $INC{&module_notional_filename($package)}
$self->{"pod_from"} pod_where({"-inc", 1}, $package) $INC{&module_notional_filename($package)}
Truth table0%0/4
A ||= B // C
A= $self->{"pod_from"}B= pod_where({"-inc", 1}, $package)C= $INC{&module_notional_filename($package)}
ABCresult
1XX1
01X1
0011
0000
405 29 my $pod_from = $self->{pod_from};
406 29 ▶ unless ($pod_from) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pod_from) 2 27 29
407 2 $self->{why_unrated} = "couldn't find pod";
408 2 return;
409 }
410  
411 # The headings name subs only once the package is loaded, so load it before reading its symbols.
412 27 ▶ if ( !eval { require_module($package); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { &require_module($package); 1 } }) 0 27 27
413 0 $self->{why_unrated} = "requiring '$package' failed";
414 0 return;
415 }
416  
417 27 ▶ print "parsing '$pod_from'\n" if $TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Coverage::More::TRACE_ALL 0 27 27
418 27 my @subs = Package::Stash->new($package)->list_all_symbols('CODE');
419 27 return $self->{documentation} = Pod::Coverage::More::Documentation->new( subs => \@subs )->parse_file($pod_from);
420 }
421  
422 # The documentation of the package, then of each of its parent classes, as Pod::Coverage::CountParents reads them.
423 253 ▶sub _documentations {
Subroutine _documentations: called CC=6 SCAR=18.0
424 253 my $self = shift;
425 253 ▶ return @{ $self->{documentations} } if $self->{documentations};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"documentations"} 226 27 253
426 27 ▶ my $own = $self->_documentation or return;
Branch: 1 branch
BranchTrueFalseTotal
my $own = $self->_documentation or return 27 0 27
427 27 my @documentations = ($own);
428 27 foreach my $parent ( @{ mro::get_linear_isa( $self->{package} ) } ) {
429 30 ▶ next if $parent eq $self->{package};
Branch: 1 branch
BranchTrueFalseTotal
if $parent eq $self->{"package"} 27 3 30
430 3 ▶ my $file = pod_where( { -inc => 1 }, $parent ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $file = pod_where({"-inc", 1}, $parent) or next 3 0 3
431 3 my @subs = Package::Stash->new($parent)->list_all_symbols('CODE');
432 3 push @documentations, Pod::Coverage::More::Documentation->new( subs => \@subs )->parse_file($file);
433 }
434 27 $self->{documentations} = \@documentations;
435 27 return @documentations;
436 }
437  
438 # The section that documents the sub C<name>, as C<section_for> of L<Pod::Coverage::More::Documentation> returns it:
439 # the section in the POD of the package, or else in that of the nearest parent class that documents it.
440 # Nothing when no POD documents it.
441 # @param name Str the name of the sub
442 # @returns HashRef the section
443 # @example my $section = $pc->section_for('coverage');
444 239 ▶sub section_for {
Subroutine section_for: called CC=3 SCAR=11.0
Pod documented
445 239 my ( $self, $name ) = @_;
446 239 foreach my $documentation ( $self->_documentations ) {
447 243 my $section = $documentation->section_for($name);
448 243 ▶ return $section if $section;
Branch: 1 branch
BranchTrueFalseTotal
if $section 198 45 243
449 }
450 41 return;
451 }
452  
453 # The analysis of every sub of the package, as C<analyze_package> of L<Pod::Coverage::More::Analyzer> returns it.
454 # The package is analyzed once.
455 # @returns HashRef from the name of each sub to the record of its analysis
456 # @example my $records = $pc->analysis;
457 26 ▶sub analysis {
Subroutine analysis: called CC=2 SCAR=7.1
Pod documented
458 26 my ($self) = @_;
459 26 ▶ return $self->{analysis} //= Pod::Coverage::More::Analyzer->new->analyze_package( $self->{package} );
Condition66%2/3
$self->{"analysis"} //= "Pod::Coverage::More::Analyzer"->new->analyze_package($self->{"package"})
l!l&&r!l&&!r
3230
MC/DC0%0/2
$self->{"analysis"} //= "Pod::Coverage::More::Analyzer"->new->analyze_package($self->{"package"})
$self->{"analysis"} "Pod::Coverage::More::Analyzer"->new->analyze_package($self->{"package"})
Truth table66%2/3
A //= B
A= $self->{"analysis"}B= "Pod::Coverage::More::Analyzer"->new->analyze_package($self->{"package"})
ABresult
1X1
011
000
460 }
461  
462 # The public subs of the package, as L<Pod::Coverage> counts them: not private, not imported, and not trusted.
463 # @returns the names of the subs, as a list
464 # @example my @names = $pc->public_subs;
465 10 ▶sub public_subs {
Subroutine public_subs: called CC=3 SCAR=11.0
Pod documented
466 10 my ($self) = @_;
467 10 my @public;
468 10 foreach my $name ( $self->_get_syms( $self->{package} ) ) {
469 55 ▶ push @public, $name if !$self->_trustme_check($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_trustme_check($name) 53 2 55
470 }
471 10 return @public;
472 }
473  
474 13 1;
475  
476 __END__
« blib/lib/Pod/Coverage/More/Generator.pm ↑ Summary lib/Pod/Coverage/More/Analyzer/Perl5_44.pm »