Pod/Coverage/More.pm

filter: Statementstmt 95.9% 282 / 294 Branchbran 80.4% 111 / 138 Conditioncond 75.0% 57 / 76 MC/DCmcdc 51.2% 21 / 41 Subroutinesub 100% 50 / 50 Podpod 100% 10 / 10 totaltotal 87.1% 531 / 609 CC 120 SCAR 20.3
CC
120
Cov
89%
_check_returns
15.1
_type_failures
14.1
_check_argument_types
13.1
CRAP 7.6
« Pod/Coverage/More/Analyzer/Perl5_44.pm ↑ Summary Pod/Coverage/More/Declared/TypeParams.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.001;
5  
6 9 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use warnings FATAL => q{all};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use re q{/xsaa};
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use List::Util qw{any none};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Module::Runtime qw{require_module};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use mro;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Pod::Find qw(pod_where);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use Types::Standard qw{Any ArrayRef CodeRef GlobRef HashRef ScalarRef Str};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 9 ▶use parent 'Pod::Coverage';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 9 ▶use Pod::Coverage::More::Analyzer;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶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 9 our $TRACE_ALL = 0;
24  
25  
26 9 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 10 ▶sub coverage {
Subroutine coverage: called CC=11 SCAR=25.7
Pod documented
34 10 my $self = shift;
35  
36 10 my $package = $self->{package};
37 10 my $doc = $self->_documentation;
38 10 _trace_dump($doc);
39 10 ▶ return unless $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc 1 9 10
40  
41 9 my %symbols = map { $_ => 0 } $self->_get_syms($package);
42  
43 9 ▶ if ( !%symbols && $self->{why_unrated} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %symbols and $self->{"why_unrated"}) 0 9 9
Condition33%1/3
not %symbols and $self->{"why_unrated"}
!ll&&!rl&&r
900
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 9 ▶ print "tying shoelaces\n" if $TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Coverage::More::TRACE_ALL 0 9 9
50 9 foreach my $documentation ( $self->_documentations ) {
51 10 foreach my $pod ( $documentation->identifiers ) {
52 80 ▶ $symbols{$pod} = 1 if exists $symbols{$pod};
Branch: 1 branch
BranchTrueFalseTotal
if exists $symbols{$pod} 80 0 80
53 }
54 }
55 9 foreach my $sym ( keys %symbols ) {
56 81 ▶ $symbols{$sym} = 1 if $self->_trustme_check($sym);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_trustme_check($sym) 0 81 81
57 }
58  
59 # stash the results for later
60 9 $self->{symbols} = \%symbols;
61 9 _trace_dump($self);
62  
63 9 my $symbols = scalar keys %symbols;
64 9 my $documented = scalar grep { $_ } values %symbols;
65 9 ▶ unless ($symbols) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($symbols) 0 9 9
66 0 $self->{why_unrated} = "no public symbols defined";
67 0 return;
68 }
69 9 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 19 ▶sub coverage_report {
Subroutine coverage_report: called CC=7 SCAR=19.5
Pod documented
80 19 my $self = shift;
81 19 ▶ return $self->{report} if $self->{report};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"report"} 4 15 19
82 15 ▶ return if !$self->_documentation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_documentation 1 14 15
83 14 my $analysis = $self->analysis;
84  
85 14 my %report;
86 14 foreach my $name ( sort $self->_get_syms( $self->{package} ) ) {
87 151 ▶ my $section = $self->section_for($name) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $section = $self->section_for($name) or next 150 1 151
88 150 ▶ my $rec = $analysis->{$name} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $rec = $analysis->{$name} or next 150 0 150
89 150 my %failures;
90 150 foreach my $check (@CHECKS) {
91 750 my $method = "_check_$check";
92 750 $failures{$check} = [ $self->$method( $name, $section, $rec ) ];
93 }
94 150 $report{$name} = { section => $section, failures => \%failures };
95 }
96 14 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 148 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 97 ▶sub _accepted_names {
Subroutine _accepted_names: called CC=9 SCAR=24.8
138 97 my ($rec) = @_;
139 97 my @names;
140 97 foreach my $param ( @{ $rec->{params} } ) {
141 138 ▶ push @names, $param->{name} if defined $param->{name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->{"name"} 138 0 138
142 138 ▶ push @names, @{ $param->{keys} || [] } if !_is_invocant( $rec, $param );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_invocant($rec, $param) 131 7 138
Condition100%2/2
$param->{'keys'} || []
l!l
3128
MC/DC100%1/1
$param->{'keys'} || []
$param->{'keys'}
Truth table100%2/2
A
A= $param->{'keys'}
Aresult
11
00
143 }
144 97 ▶ foreach my $param ( @{ $rec->{declared}{params} || [] } ) {
Condition50%1/2
$rec->{'declared'}{'params'} || []
l!l
097
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 97 return _bare_names(@names);
149 }
150  
151 # Whether PARAM is the object or class that a method is called on, whose keys are its fields and not named arguments.
152 138 ▶sub _is_invocant {
Subroutine _is_invocant: called CC=6 SCAR=18.8
153 138 my ( $rec, $param ) = @_;
154 138 ▶ return 1 if $param->{source} eq 'invocant';
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"source"} eq "invocant" 0 138 138
155 138 ▶ my $name = $param->{name} // return 0;
Condition50%1/2
$param->{"name"} // (return 0)
l!l
1380
MC/DC0%0/1
$param->{"name"} // (return 0)
$param->{"name"}
Truth table50%1/2
A
A= $param->{"name"}
Aresult
11
00
156 138 ▶ return 1 if $name =~ m/\A\$(?:self|class|proto)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\A\$(?:self|class|proto)\z/aasx 7 131 138
157 131 ▶ return @{ $rec->{usage}{$name}{methods} || [] } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$rec->{'usage'}{$name}{'methods'} or [];} ? : 0 131 131
Condition50%1/2
$rec->{'usage'}{$name}{'methods'} || []
l!l
0131
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
158 }
159  
160 # Whether the code of a sub shows nothing of its arguments: an XS sub or a constant, or a stub with no signature
161 # that reads nothing of @_, as a default that subclasses override. Its POD names its arguments on the author's word.
162 300 ▶sub _is_stub {
Subroutine _is_stub: called CC=7 SCAR=19.9
163 300 my ($rec) = @_;
164 300 ▶ return 1 if $rec->{kind} ne 'perl';
Branch: 1 branch
BranchTrueFalseTotal
if $rec->{"kind"} ne "perl" 0 300 300
165 300 ▶ 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 [];} 194 106 300
Condition72%8/11
$rec->{"signature"} or $rec->{"reads_args"} or @{$rec->{"params"};} or @{$rec->{"declared"}{"params"} or [];}
l!l&&r!l&&!r
1940106
$rec->{"signature"} or $rec->{"reads_args"} or @{$rec->{"params"};}
l!l&&r!l&&!r
1940106
$rec->{"signature"} or $rec->{"reads_args"}
l!l&&r!l&&!r
8186106
$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
166 106 return 1;
167 }
168  
169 150 ▶sub _check_arguments {
Subroutine _check_arguments: called CC=5 SCAR=16.1
170 150 my ( $self, $name, $section, $rec ) = @_;
171 150 ▶ return if _is_stub($rec);
Branch: 1 branch
BranchTrueFalseTotal
if _is_stub($rec) 53 97 150
172 97 ▶ my $args = $section->{args}{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $args = $section->{"args"}{$name} or return 97 0 97
173 97 my @accepted = _accepted_names($rec);
174 97 my @failures;
175 97 foreach my $arg ( _bare_names(@$args) ) {
176 141 ▶ 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) 10 131 141
177 }
178 97 return @failures;
179 }
180  
181 9 our %SIGIL_TYPES = ( '$' => 'scalar', '@' => 'array', '%' => 'hash' );
182  
183 150 ▶sub _check_argument_types {
Subroutine _check_argument_types: called CC=13 SCAR=25.7
184 150 my ( $self, $name, $section, $rec ) = @_;
185 150 ▶ return if _is_stub($rec);
Branch: 1 branch
BranchTrueFalseTotal
if _is_stub($rec) 53 97 150
186 97 ▶ my $args = $section->{args}{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $args = $section->{"args"}{$name} or return 97 0 97
187 97 my @params = grep { defined } map { $_->{name} } @{ $rec->{params} };
188  
189 # Strategy 1: the POD wrote each argument with its sigil, so it must match the sigil of the parameter, in any case.
190 97 ▶ if ( any { m/\A[\$*\\@%&|]/ } @$args ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { /\A[\$*\\\@%&|]/aasx; } , @$args)) 9 88 97
191 9 my @failures;
192 9 foreach my $arg ( map { s/\A\\[\$*@%&|]/\$/r } @$args ) {
193 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
194 }
195 9 return @failures;
196 }
197  
198 # Strategy 2: the type of each argument is in an =item of its section.
199 88 ▶ my $types = $section->{types}{$name} || {};
Condition100%2/2
$section->{'types'}{$name} || {}
l!l
6622
MC/DC100%1/1
$section->{'types'}{$name} || {}
$section->{'types'}{$name}
Truth table100%2/2
A
A= $section->{'types'}{$name}
Aresult
11
00
200 88 my @failures;
201 88 foreach my $arg (@$args) {
202 127 ▶ 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 90 127
203 }
204 88 foreach my $param ( @{ $rec->{params} } ) {
205 124 ▶ next if !defined $param->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param->{"name"} 0 124 124
206 124 ▶ my ( $sigil, $arg_name ) = $param->{name} =~ m/\A(.)(.+)\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $param->{"name"} =~ /\A(.)(.+)\z/aasx or next 124 0 124
207 124 ▶ my $documented = $types->{ lc $arg_name } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $documented = $$types{lc $arg_name} or next 84 40 124
208 84 push @failures, _type_failures( $name, $arg_name, $SIGIL_TYPES{$sigil}, $documented, $param );
209 }
210 88 return @failures;
211 }
212  
213 # The failures of the documented type of one parameter: against its sigil, its declared type, and its uses.
214 84 ▶sub _type_failures {
Subroutine _type_failures: called CC=14 SCAR=26.5
215 84 my ( $name, $arg_name, $sigil_type, $documented, $param ) = @_;
216 84 my $word = $documented->{word};
217 84 ▶ return "No type declared for arg $arg_name of $name" if $word eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "" 6 78 84
218 78 ▶ return if $word eq 'mixed';
Branch: 1 branch
BranchTrueFalseTotal
if $word eq "mixed" 1 77 78
219  
220 # A word for a container names the kind of the parameter itself, and only a container parameter is one.
221 77 ▶ 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 75 77
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
6692
defined $sigil_type and $word ne $sigil_type
!ll&&!rl&&r
0671
$word eq "array" or $word eq "hash" or $sigil_type ne "scalar"
l!l&&r!l&&!r
2069
$word eq "array" or $word eq "hash"
l!l&&r!l&&!r
0269
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
222 2 return "Type mismatch for arg $arg_name of $name: got $word, expected $sigil_type";
223 }
224  
225 75 ▶ my $type = $documented->{type} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $type = $documented->{"type"} or return 75 0 75
226 75 ▶ if ( my $declared = $param->{declared} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $declared = $param->{"declared"}) 12 63 75
227 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
228 4 return "Type mismatch for arg $arg_name of $name: documented " . $type->display_name . ", but $param->{declared_by} declares " . $declared->display_name;
229 }
230 63 ▶ if ( my $inferred = $param->{inferred} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inferred = $param->{"inferred"}) 25 38 63
231 25 ▶ 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 21 25
232 if _contradicts( $type, $inferred );
233 }
234 59 return;
235 }
236  
237 # The kinds of value that no type of another kind can be.
238 9 our @KINDS = ( HashRef, ArrayRef, CodeRef, ScalarRef, GlobRef, Str );
239  
240 66 ▶sub _kinds_of {
Subroutine _kinds_of: called CC=5 SCAR=16.3
241 66 my ($type) = @_;
242 0 ▶ my @members = $type->can('type_constraints') ? @{ $type->type_constraints } : ($type);
Branch: 1 branch
BranchTrueFalseTotal
$type->can('type_constraints') ? : 0 66 66
243 66 my %kinds;
244 66 foreach my $member (@members) {
245 66 foreach my $kind (@KINDS) {
246 396 ▶ $kinds{ $kind->name } = 1 if $member->is_a_type_of($kind);
Branch: 1 branch
BranchTrueFalseTotal
if $member->is_a_type_of($kind) 56 340 396
247 }
248 }
249 66 return \%kinds;
250 }
251  
252 # Whether a documented type and a type that the code implies are of different kinds, as a hash reference and an array reference.
253 33 ▶sub _contradicts {
Subroutine _contradicts: called CC=4 SCAR=13.9
254 33 my ( $documented, $inferred ) = @_;
255 33 my $documented_kinds = _kinds_of($documented);
256 33 my $inferred_kinds = _kinds_of($inferred);
257 33 ▶ return 0 if !%$documented_kinds || !%$inferred_kinds;
Branch: 1 branch
BranchTrueFalseTotal
unless %$documented_kinds and %$inferred_kinds 10 23 33
Condition66%2/3
%$documented_kinds and %$inferred_kinds
!ll&&!rl&&r
10023
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
258 23 ▶ 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 15 23
259 }
260  
261 150 ▶sub _check_returns {
Subroutine _check_returns: called CC=15 SCAR=27.2
262 150 my ( $self, $name, $section, $rec ) = @_;
263 150 my @returned = grep { $_->{type} ne 'empty' } @{ $rec->{returns} };
264 150 ▶ my @declared = @{ $rec->{declared}{returns} || [] };
Condition50%1/2
$rec->{'declared'}{'returns'} || []
l!l
0150
MC/DC0%0/1
$rec->{'declared'}{'returns'} || []
$rec->{'declared'}{'returns'}
Truth table50%1/2
A
A= $rec->{'declared'}{'returns'}
Aresult
11
00
265 150 ▶ return if !@returned && !@declared;
Branch: 1 branch
BranchTrueFalseTotal
unless @returned or @declared 59 91 150
Condition66%2/3
@returned or @declared
l!l&&r!l&&!r
91059
MC/DC50%1/2
@returned or @declared
@returned @declared
Truth table66%2/3
A or B
A= @returnedB= @declared
ABresult
1X1
011
000
266  
267 91 my @statements = @{ $section->{returns} };
268 91 ▶ return "No return value documented for $name" if !@statements;
Branch: 1 branch
BranchTrueFalseTotal
unless @statements 21 70 91
269 70 my @documented = map { @{ $_->{types} } } @statements;
270 70 ▶ if ( !@documented ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@documented) 11 59 70
271 11 ▶ return "$name is documented to return nothing, but it returns a value" if _all_nothing(@statements);
Branch: 1 branch
BranchTrueFalseTotal
if _all_nothing(@statements) 4 7 11
272 7 return;
273 }
274  
275 59 my @failures;
276 my %seen;
277 0 my @checked = ( ( map { [ $_->{constraint}, "line $_->{line}", $_->{weak}, $_ ] } grep { $_->{constraint} } @returned ), ( map { [ $_, 'declared', 0 ] } @declared ) );
278 59 foreach my $returned (@checked) {
279 61 my ( $type, $where, $weak, $evidence ) = @$returned;
280 61 ▶ next if _covered( $type, \@documented );
Branch: 1 branch
BranchTrueFalseTotal
if _covered($type, \@documented) 37 24 61
281  
282 # A literal is one value, which can satisfy a type that its own type is no subtype of, as 1 satisfies Bool.
283 24 ▶ 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 16 24
Condition83%5/6
$evidence and exists $evidence->{"value"} and _value_covered($evidence->{"value"}, \@documented)
!ll&&!rl&&r
1248
$evidence and exists $evidence->{"value"}
!ll&&!rl&&r
01212
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
284  
285 # The type of the result of an operator is weak: overloading can change it, so it fails only when it contradicts.
286 16 ▶ 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 12 16
Condition100%3/3
$weak and &any(sub { not _contradicts($_, $type); } , @documented)
!ll&&!rl&&r
844
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
287 12 ▶ next if $seen{ $type->display_name }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$type->display_name}++ 0 12 12
288 12 push @failures, "Return type mismatch for $name: returns " . $type->display_name . " ($where), documented as " . join( ' or ', _names_of( \@documented ) );
289 }
290 59 return @failures;
291 }
292  
293 # Whether the statements of the return value only say that it returns nothing.
294 11 ▶sub _all_nothing {
Subroutine _all_nothing: called CC=2 SCAR=7.0
295 11 my (@statements) = @_;
296 11 ▶ 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
704
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
297 }
298  
299 12 ▶sub _value_covered {
Subroutine _value_covered: called CC=3 SCAR=11.0
300 12 my ( $value, $documented ) = @_;
301 12 foreach my $candidate (@$documented) {
302 12 ▶ return 1 if $candidate->check($value);
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->check($value) 8 4 12
303 }
304 4 return 0;
305 }
306  
307 61 ▶sub _covered {
Subroutine _covered: called CC=5 SCAR=16.1
308 61 my ( $type, $documented ) = @_;
309 61 foreach my $candidate (@$documented) {
310 66 ▶ 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) 37 29 66
Condition83%5/6
$candidate->equals(&Any()) or $type->equals($candidate) or $type->is_subtype_of($candidate)
l!l&&r!l&&!r
37029
$candidate->equals(&Any()) or $type->equals($candidate)
l!l&&r!l&&!r
53229
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
311 }
312 24 return 0;
313 }
314  
315 # The names of NAMES without sigils, in lower case, as the POD and the code are compared.
316 194 ▶sub _bare_names {
Subroutine _bare_names: called CC=2 SCAR=6.9
317 194 my (@names) = @_;
318 194 my @bare;
319 194 foreach my $name (@names) {
320 284 push @bare, Pod::Coverage::More::Documentation->bare_name($name);
321 }
322 194 return @bare;
323 }
324  
325 # The display names of the constraints in the ARRAYREF TYPES.
326 12 ▶sub _names_of {
Subroutine _names_of: called CC=2 SCAR=6.9
327 12 my ($types) = @_;
328 12 my @names;
329 12 foreach my $type (@$types) {
330 12 push @names, $type->display_name;
331 }
332 12 return @names;
333 }
334  
335 150 ▶sub _check_termination {
Subroutine _check_termination: called CC=3 SCAR=11.0
336 150 my ( $self, $name, $section, $rec ) = @_;
337 150 my @uncaught = grep { !$_->{caught} } @{ $rec->{dies} };
338 150 ▶ return if !@uncaught || @{ $section->{terminations} };
Branch: 1 branch
BranchTrueFalseTotal
if not @uncaught or @{$section->{"terminations"};} 146 4 150
Condition100%3/3
not @uncaught or @{$section->{"terminations"};}
l!l&&r!l&&!r
14154
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
339 4 return "$name can terminate ($uncaught[0]{via} at line $uncaught[0]{line}), but its POD does not say so";
340 }
341  
342 150 ▶sub _check_examples {
Subroutine _check_examples: called CC=2 SCAR=6.9
343 150 my ( $self, $name, $section ) = @_;
344 150 ▶ 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"};}) 14 136 150
345 136 return "No example of $name in its POD";
346 }
347  
348 19 ▶sub _trace_dump {
Subroutine _trace_dump: called CC=2 SCAR=10.1
349 19 my ($data) = @_;
350 19 ▶ return if !$TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
unless $Pod::Coverage::More::TRACE_ALL 19 0 19
351 0 require Data::Dumper;
352 0 print Data::Dumper::Dumper($data);
353 0 return;
354 }
355  
356 47 ▶sub _documentation {
Subroutine _documentation: called CC=7 SCAR=19.8
357 47 my $self = shift;
358 47 ▶ return $self->{documentation} if $self->{documentation};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"documentation"} 24 23 47
359  
360 23 my $package = $self->{package};
361 23 ▶ print "getting pod location for '$package'\n" if $TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Coverage::More::TRACE_ALL 0 23 23
362 23 ▶ $self->{pod_from} ||= pod_where( { -inc => 1 }, $package );
Condition100%3/3
$self->{"pod_from"} ||= pod_where({"-inc", 1}, $package)
l!l&&r!l&&!r
1184
MC/DC100%2/2
$self->{"pod_from"} ||= pod_where({"-inc", 1}, $package)
$self->{"pod_from"} pod_where({"-inc", 1}, $package)
Truth table100%3/3
A ||= B
A= $self->{"pod_from"}B= pod_where({"-inc", 1}, $package)
ABresult
1X1
011
000
363 23 my $pod_from = $self->{pod_from};
364 23 ▶ unless ($pod_from) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pod_from) 4 19 23
365 4 $self->{why_unrated} = "couldn't find pod";
366 4 return;
367 }
368  
369 # The headings name subs only once the package is loaded, so load it before reading its symbols.
370 19 ▶ if ( !eval { require_module($package); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { &require_module($package); 1 } }) 0 19 19
371 0 $self->{why_unrated} = "requiring '$package' failed";
372 0 return;
373 }
374  
375 19 ▶ print "parsing '$pod_from'\n" if $TRACE_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Coverage::More::TRACE_ALL 0 19 19
376 19 my @subs = Package::Stash->new($package)->list_all_symbols('CODE');
377 19 return $self->{documentation} = Pod::Coverage::More::Documentation->new( subs => \@subs )->parse_file($pod_from);
378 }
379  
380 # The documentation of the package, then of each of its parent classes, as Pod::Coverage::CountParents reads them.
381 192 ▶sub _documentations {
Subroutine _documentations: called CC=6 SCAR=17.9
382 192 my $self = shift;
383 192 ▶ return @{ $self->{documentations} } if $self->{documentations};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"documentations"} 171 21 192
384 21 ▶ my $own = $self->_documentation or return;
Branch: 1 branch
BranchTrueFalseTotal
my $own = $self->_documentation or return 19 2 21
385 19 my @documentations = ($own);
386 19 foreach my $parent ( @{ mro::get_linear_isa( $self->{package} ) } ) {
387 20 ▶ next if $parent eq $self->{package};
Branch: 1 branch
BranchTrueFalseTotal
if $parent eq $self->{"package"} 19 1 20
388 1 ▶ my $file = pod_where( { -inc => 1 }, $parent ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $file = pod_where({"-inc", 1}, $parent) or next 1 0 1
389 1 my @subs = Package::Stash->new($parent)->list_all_symbols('CODE');
390 1 push @documentations, Pod::Coverage::More::Documentation->new( subs => \@subs )->parse_file($file);
391 }
392 19 $self->{documentations} = \@documentations;
393 19 return @documentations;
394 }
395  
396 # The section that documents the sub C<name>, as C<section_for> of L<Pod::Coverage::More::Documentation> returns it:
397 # the section in the POD of the package, or else in that of the nearest parent class that documents it.
398 # Nothing when no POD documents it.
399 # @param name Str the name of the sub
400 # @returns HashRef the section
401 # @example my $section = $pc->section_for('coverage');
402 183 ▶sub section_for {
Subroutine section_for: called CC=3 SCAR=11.0
Pod documented
403 183 my ( $self, $name ) = @_;
404 183 foreach my $documentation ( $self->_documentations ) {
405 182 my $section = $documentation->section_for($name);
406 182 ▶ return $section if $section;
Branch: 1 branch
BranchTrueFalseTotal
if $section 150 32 182
407 }
408 33 return;
409 }
410  
411 # The analysis of every sub of the package, as C<analyze_package> of L<Pod::Coverage::More::Analyzer> returns it.
412 # The package is analyzed once.
413 # @returns HashRef from the name of each sub to the record of its analysis
414 # @example my $records = $pc->analysis;
415 21 ▶sub analysis {
Subroutine analysis: called CC=2 SCAR=7.1
Pod documented
416 21 my ($self) = @_;
417 21 ▶ 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
3180
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
418 }
419  
420 # The public subs of the package, as L<Pod::Coverage> counts them: not private, not imported, and not trusted.
421 # @returns the names of the subs, as a list
422 # @example my @names = $pc->public_subs;
423 7 ▶sub public_subs {
Subroutine public_subs: called CC=3 SCAR=11.1
Pod documented
424 7 my ($self) = @_;
425 7 my @public;
426 7 foreach my $name ( $self->_get_syms( $self->{package} ) ) {
427 44 ▶ push @public, $name if !$self->_trustme_check($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_trustme_check($name) 44 0 44
428 }
429 7 return @public;
430 }
431  
432 9 1;
433  
434 __END__
« Pod/Coverage/More/Analyzer/Perl5_44.pm ↑ Summary Pod/Coverage/More/Declared/TypeParams.pm »