MinimumVersion.pm

filter: Statementstmt 96.1% 101 / 105 Branchbran 76.1% 32 / 42 Conditioncond 100% 21 / 21 MC/DCmcdc 100% 13 / 13 Subroutinesub 100% 20 / 20 Podpod 66.6% 4 / 6 totaltotal 92.2% 191 / 207 CC 31 SCAR 14.2
CC
31
Cov
92%
analyze
9.9
report
6.7
_check_link_display_text
3.0
CRAP 4.1
↑ Summary MinimumVersion/Parser.pm »
1 # Copyright 2009, 2010, 2011 Kevin Ryde
2  
3 # This file is part of Pod-MinimumVersion.
4  
5 # Pod-MinimumVersion is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Pod-MinimumVersion is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Pod-MinimumVersion. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 package Pod::MinimumVersion;
20 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use vars qw($VERSION @CHECKS);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # uncomment this to run the ### lines
27 #use Smart::Comments;
28  
29 2 $VERSION = 50;
30  
31 50 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
32 50 my ($class, %self) = @_;
33 50 ▶ $self{'want_reports'} ||= 'one_per_version';
Condition100%2/2
$self{"want_reports"} ||= "one_per_version"
l!l
149
MC/DC100%1/1
$self{"want_reports"} ||= "one_per_version"
$self{"want_reports"}
Truth table100%2/2
A
A= $self{"want_reports"}
Aresult
11
00
34 50 return bless \%self, $class;
35 }
36  
37 45 ▶sub minimum_version {
Subroutine minimum_version: called CC=2 SCAR=6.9
Pod documented
38 45 my ($self) = @_;
39 45 ▶ my $report = $self->minimum_report || return undef;
Condition100%2/2
$self->minimum_report || (return undef)
l!l
2421
MC/DC100%1/1
$self->minimum_report || (return undef)
$self->minimum_report
Truth table100%2/2
A
A= $self->minimum_report
Aresult
11
00
40 24 return $report->{'version'};
41 }
42 45 ▶sub minimum_report {
Subroutine minimum_report: called CC=2 SCAR=7.0
Pod documented
43 45 my ($self) = @_;
44 45 ▶ if (! exists $self->{'minimum_report'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"minimum_report"}) 45 0 45
45 $self->{'minimum_report'}
46 5 ▶ = List::Util::reduce {$a->{'version'} > $b->{'version'} ? $a : $b}
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$Pod::MinimumVersion::a->{'version'} > $Pod::MinimumVersion::b->{'version'} ? : 3 2 5
47 45 $self->reports;
48 }
49 45 return $self->{'minimum_report'};
50 }
51 91 ▶sub reports {
Subroutine reports: called CC=2 SCAR=6.9
Pod documented
52 91 my ($self) = @_;
53 91 $self->analyze;
54 91 ▶ return @{$self->{'reports'} || []};
Condition100%2/2
$self->{'reports'} || []
l!l
4843
MC/DC100%1/1
$self->{'reports'} || []
$self->{'reports'}
Truth table100%2/2
A
A= $self->{'reports'}
Aresult
11
00
55 }
56  
57 94 ▶sub analyze {
Subroutine analyze: called CC=9 SCAR=23.0
Pod undocumented
58 94 my ($self) = @_;
59 94 ▶ return if $self->{'analyzed'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"analyzed"} 45 49 94
60 49 $self->{'analyzed'} = 1;
61  
62 ### Pod-MinVer analyze()
63  
64 49 my %checks;
65 49 foreach my $elem (@CHECKS) {
66 392 my ($func, $command, $version) = @$elem;
67 392 ▶ next if ($self->{'above_version'} && $version <= $self->{'above_version'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"above_version"} and $version <= $self->{"above_version"} 72 320 392
Condition100%3/3
$self->{"above_version"} and $version <= $self->{"above_version"}
!ll&&!rl&&r
2487272
MC/DC100%2/2
$self->{"above_version"} and $version <= $self->{"above_version"}
$self->{"above_version"} $version <= $self->{"above_version"}
Truth table100%3/3
A and B
A= $self->{"above_version"}B= $version <= $self->{"above_version"}
ABresult
0X0
100
111
68 320 push @{$checks{$command}}, $func;
69 }
70 49 ▶ return if (! %checks);
Branch: 1 branch
BranchTrueFalseTotal
unless %checks 1 48 49
71  
72 48 require Pod::MinimumVersion::Parser;
73 48 my $parser = Pod::MinimumVersion::Parser->new (pmv => $self,
74 checks => \%checks);
75 48 ▶ if (exists $self->{'string'}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $self->{'string'}) { } 48 0 48
elsif (exists $self->{'filehandle'}) { } 0 0 0
elsif (exists $self->{'filename'}) { } 0 0 0
76 48 $parser->parse_from_string ("$self->{'string'}");
77 } elsif (exists $self->{'filehandle'}) {
78 0 $parser->parse_from_filehandle ($self->{'filehandle'});
79 } elsif (exists $self->{'filename'}) {
80 # stringize to parse_from_file() taking an overloaded object to be a handle
81 # ENHANCE-ME: perhaps opening here and parse_from_filehandle() would be
82 # a better way to avoid
83 0 $parser->parse_from_file ("$self->{'filename'}");
84 }
85 }
86  
87 #------------------------------------------------------------------------------
88 # 5.004
89 #
90 # E<> newly documented in 5.004, but is in pod2man right back to 5.002, so
91 # don't report that
92  
93 {
94 2 my $v5004 = version->new('5.004');
95  
96 # =for, =begin, =end new in 5.004
97 #
98 2 push @CHECKS, [ \&_check_for_begin_end, 'command', $v5004 ];
99 2 my %for_begin_end = (for => 1, begin => 1, end => 1);
100 33 ▶ sub _check_for_begin_end {
Subroutine _check_for_begin_end: called CC=2 SCAR=6.9
101 33 my ($self, $command, $text, $para_obj) = @_;
102 33 ▶ if ($for_begin_end{$command}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($for_begin_end{$command}) 9 24 33
103 9 $self->report ('for_begin_end', $v5004, $para_obj, "=$command command");
104 }
105 }
106 }
107  
108 #------------------------------------------------------------------------------
109 # 5.005
110  
111 {
112 2 my $v5005 = version->new('5.005');
113  
114 # L<display|target> display alternative new in 5.005
115 #
116 2 push @CHECKS, [ \&_check_link_display_text, 'interior_sequence', $v5005 ];
117 27 ▶ sub _check_link_display_text {
Subroutine _check_link_display_text: called CC=3 SCAR=11.0
118 27 my ($self, $command, $arg, $seq_obj) = @_;
119 27 ▶ if ($command eq 'L' && $arg =~ /\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "L" and $arg =~ /\|/) 4 23 27
Condition100%3/3
$command eq "L" and $arg =~ /\|/
!ll&&!rl&&r
1944
MC/DC100%2/2
$command eq "L" and $arg =~ /\|/
$command eq "L" $arg =~ /\|/
Truth table100%3/3
A and B
A= $command eq "L"B= $arg =~ /\|/
ABresult
0X0
100
111
120 4 $self->report ('link_display_text', $v5005, $seq_obj,
121 'Display text L<display|target> link');
122 }
123 }
124 }
125  
126 #------------------------------------------------------------------------------
127 # 5.006
128  
129 {
130 2 my $v5006 = version->new('5.006');
131  
132 2 push @CHECKS, [ \&_check_double_angles, 'interior_sequence', $v5006 ];
133 28 ▶ sub _check_double_angles {
Subroutine _check_double_angles: called CC=2 SCAR=6.9
134 28 my ($self, $command, $arg, $seq_obj) = @_;
135  
136 28 ▶ if ($seq_obj->left_delimiter =~ /^<</) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq_obj->left_delimiter =~ /^<</) 8 20 28
137 8 $self->report ('double_angles', $v5006, $seq_obj,
138 'Double angle brackets C<< foo >>');
139 }
140 }
141 }
142  
143 #------------------------------------------------------------------------------
144 # 5.008
145  
146 {
147 2 my $v5008 = version->new('5.008');
148  
149 # =head3 and =head4 new in 5.8.0
150 2 push @CHECKS, [ \&_check_head34, 'command', $v5008 ];
151 2 my %head34 = (head3 => 1, head4 => 1);
152 38 ▶ sub _check_head34 {
Subroutine _check_head34: called CC=2 SCAR=6.9
153 38 my ($self, $command, $text, $para_obj) = @_;
154 38 ▶ if ($head34{$command}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head34{$command}) 2 36 38
155 2 $self->report ('head34', $v5008, $para_obj, "=$command command");
156 }
157 }
158  
159 # E<sol> and E<verbar> documented in 5.6.0, but Pod::Man only has them in
160 # 5.8.0, so rate them as a 5008 feature
161 #
162 # E<apos> is in Pod::Man of 5.8.0, though not documented explicitly
163 #
164 2 push @CHECKS, [ \&_check_E_5008, 'interior_sequence', $v5008 ];
165 2 my %E_5008 = (apos => 1, sol => 1, verbar => 1);
166 29 ▶ sub _check_E_5008 {
Subroutine _check_E_5008: called CC=3 SCAR=11.0
167 29 my ($self, $command, $arg, $seq_obj) = @_;
168  
169 29 ▶ if ($command eq 'E' && $E_5008{$arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "E" and $E_5008{$arg}) 3 26 29
Condition100%3/3
$command eq "E" and $E_5008{$arg}
!ll&&!rl&&r
2333
MC/DC100%2/2
$command eq "E" and $E_5008{$arg}
$command eq "E" $E_5008{$arg}
Truth table100%3/3
A and B
A= $command eq "E"B= $E_5008{$arg}
ABresult
0X0
100
111
170 3 $self->report ('E_5008', $v5008, $seq_obj, "E<$arg> escape");
171 }
172 }
173  
174 # L<http://...> urls new in 5.8.0
175 #
176 # In 5.6 and earlier the "/" is interpreted as a section, so from
177 # L<http://foo.com/index.html> you get something bad like
178 #
179 # the section on "/foo.com/index.html" in the http: manpage
180 #
181 # Crib note: a "|" display text part is not allowed with a url, according
182 # to perlpodspec of perl 5.10.0 under the "Authors wanting to link to a
183 # particular (absolute) URL" bullet point. So no need to watch for that
184 # in applying this test.
185 #
186 2 push @CHECKS, [ \&_check_link_url, 'interior_sequence', $v5008 ];
187 29 ▶ sub _check_link_url {
Subroutine _check_link_url: called CC=3 SCAR=11.0
188 29 my ($self, $command, $arg, $seq_obj) = @_;
189 # this regexp as recommended by perlpodspec of perl 5.10.0
190 29 ▶ if ($command eq 'L' && $arg =~ m/\A\w+:[^:\s]\S*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "L" and $arg =~ /\A\w+:[^:\s]\S*\z/) 2 27 29
Condition100%3/3
$command eq "L" and $arg =~ /\A\w+:[^:\s]\S*\z/
!ll&&!rl&&r
1982
MC/DC100%2/2
$command eq "L" and $arg =~ /\A\w+:[^:\s]\S*\z/
$command eq "L" $arg =~ /\A\w+:[^:\s]\S*\z/
Truth table100%3/3
A and B
A= $command eq "L"B= $arg =~ /\A\w+:[^:\s]\S*\z/
ABresult
0X0
100
111
191 2 $self->report ('link_url', $v5008, $seq_obj,
192 'L<> link to URL');
193 }
194 }
195 }
196  
197 #------------------------------------------------------------------------------
198 # 5.010
199  
200 {
201 2 my $v5010 = version->new('5.010');
202  
203 # =encoding documented in 5.8.0, but Pod::Man doesn't recognise it until
204 # 5.10.0, so rate it as a 5010 feature
205 #
206 2 push @CHECKS, [ \&_check_encoding, 'command', $v5010 ];
207 45 ▶ sub _check_encoding {
Subroutine _check_encoding: called CC=2 SCAR=6.9
208 45 my ($self, $command, $text, $para_obj) = @_;
209 45 ▶ if ($command eq 'encoding') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "encoding") 2 43 45
210 2 $self->report ('encoding', $v5010, $para_obj, '=encoding command');
211 }
212 }
213 }
214  
215 #------------------------------------------------------------------------------
216 # 5.012
217  
218 {
219 2 my $v5012 = version->new('5.012');
220  
221 # L<text|url> documented in 5.12.0 where previously explicitly prohibited,
222 # rate it as a 5012 feature
223 #
224 2 push @CHECKS, [ \&_check_link_url_with_text, 'interior_sequence', $v5012 ];
225 34 ▶ sub _check_link_url_with_text {
Subroutine _check_link_url_with_text: called CC=3 SCAR=11.0
226 34 my ($self, $command, $arg, $seq_obj) = @_;
227 # this regexp adapted from recommendation of perlpodspec from perl 5.10.0
228 34 ▶ if ($command eq 'L' && $arg =~ m/\A.*\|\w+:[^:\s]\S*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "L" and $arg =~ /\A.*\|\w+:[^:\s]\S*\z/) 2 32 34
Condition100%3/3
$command eq "L" and $arg =~ /\A.*\|\w+:[^:\s]\S*\z/
!ll&&!rl&&r
22102
MC/DC100%2/2
$command eq "L" and $arg =~ /\A.*\|\w+:[^:\s]\S*\z/
$command eq "L" $arg =~ /\A.*\|\w+:[^:\s]\S*\z/
Truth table100%3/3
A and B
A= $command eq "L"B= $arg =~ /\A.*\|\w+:[^:\s]\S*\z/
ABresult
0X0
100
111
229 2 $self->report ('link_url_with_text', $v5012, $seq_obj,
230 'L<> link with URL and text');
231 }
232 }
233 }
234  
235 #------------------------------------------------------------------------------
236  
237 2 ▶sub report {
Subroutine report: called CC=6 SCAR=19.1
Pod undocumented
238 32 my ($self, $name, $version, $pod_obj, $why) = @_;
239  
240 32 ▶ if ($self->{'want_reports'} eq 'one_per_check') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"want_reports"} eq "one_per_check") 0 32 32
241 0 ▶ return if ($self->{'seen'}->{$name}++);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"seen"}{$name}++ 0 0 0
242 }
243 32 ▶ if ($self->{'want_reports'} eq 'one_per_version') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"want_reports"} eq "one_per_version") 29 3 32
244 29 ▶ return if ($self->{'seen'}->{$version}++);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"seen"}{$version}++ 1 28 29
245 }
246  
247 31 my ($filename, $linenum) = $pod_obj->file_line;
248 31 ▶ if (defined $self->{'filename'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"filename"}) 0 31 31
249 0 $filename = $self->{'filename'};
250 }
251 31 require Pod::MinimumVersion::Report;
252 31 push @{$self->{'reports'}},
253 Pod::MinimumVersion::Report->new (filename => $filename,
254 name => $name,
255 linenum => $linenum,
256 version => $version,
257 why => $why);
258 }
259  
260 2 1;
261 __END__
↑ Summary MinimumVersion/Parser.pm »