Policy/Modules/ProhibitUseQuotedVersion.pm

filter: Statementstmt 100% 45 / 45 Branchbran 87.5% 7 / 8 Conditioncond 72.7% 8 / 11 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 13 / 13 Podpod 50.0% 1 / 2 totaltotal 90.4% 76 / 84 CC 9 SCAR 11.1
CC
9
Cov
94%
violates
6.0
elem_is_last_of_statement
4.1
BEGIN
1.0
CRAP 3.0
« Pulp/PodParser.pm ↑ Summary Policy/Documentation/ProhibitVerbatimMarkup.pm »
1 # Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
2  
3 # Perl-Critic-Pulp is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by the
5 # Free Software Foundation; either version 3, or (at your option) any later
6 # version.
7 #
8 # Perl-Critic-Pulp is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
15  
16  
17 package Perl::Critic::Policy::Modules::ProhibitUseQuotedVersion;
18 40 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 40 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 40 ▶use Perl::Critic::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 40 ▶use Perl::Critic::Pulp::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 40 ▶use version (); # but don't import qv()
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 40 our $VERSION = 100;
27  
28 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_MEDIUM;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 40 ▶use constant default_themes => qw(pulp bugs);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 40 ▶use constant applies_to => 'PPI::Statement::Include';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 16 ▶sub violates {
Subroutine violates: called CC=6 SCAR=18.0
Pod documented
34 16 my ($self, $elem, $document) = @_;
35  
36 16 ▶ defined($elem->module) || return; # if a "use 5.005" etc
Branch: 1 branch
BranchTrueFalseTotal
defined $elem->module or return 16 0 16
37 16 ▶ my $arg = $elem->schild(2) || return; # if a "use Foo" with no args
Condition50%1/2
$elem->schild(2) || (return)
l!l
160
MC/DC0%0/1
$elem->schild(2) || (return)
$elem->schild(2)
Truth table50%1/2
A
A= $elem->schild(2)
Aresult
11
00
38 16 ▶ $arg->isa('PPI::Token::Quote') || return;
Branch: 1 branch
BranchTrueFalseTotal
$arg->isa("PPI::Token::Quote") or return 6 10 16
39 6 ▶ elem_is_last_of_statement($arg) || return;
Branch: 1 branch
BranchTrueFalseTotal
elem_is_last_of_statement($arg) or return 5 1 6
40  
41 # This is a strict match of what a module version number is like.
42 # Previously looser forms like '.500' were matched too, but of course
43 # unquoting that doesn't give something that's checked by perl itself.
44 # There don't seem to be forms like .500 used in practice, so don't think
45 # it's important.
46 #
47 5 my $str = $arg->string;
48 5 ▶ $str =~ $Perl::Critic::Pulp::Utils::use_module_version_number_re
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /$Perl::Critic::Pulp::Utils::use_module_version_number_re/ or return 4 1 5
49 or return;
50  
51 4 return $self->violation
52 ("Don't use a quoted string version number in a \"use\" statement",
53 '',
54 $arg);
55 }
56  
57 # return true if $elem is the last thing in its statement, apart from an
58 # optional terminating ";"
59 #
60 6 ▶sub elem_is_last_of_statement {
Subroutine elem_is_last_of_statement: called CC=4 SCAR=14.0
Pod undocumented
61 6 my ($elem) = @_;
62 6 my $next = $elem->snext_sibling;
63 6 ▶ return (! $next
Condition77%7/9
!$next || $next->isa('PPI::Token::Structure') && $next eq ';' && !$next->snext_sibling
l!l&&r!l&&!r
321
$next->isa("PPI::Token::Structure") and $next eq ";" and not $next->snext_sibling
!ll&&!rl&&r
102
$next->isa("PPI::Token::Structure") and $next eq ";"
!ll&&!rl&&r
102
MC/DC50%2/4
!$next || $next->isa('PPI::Token::Structure') && $next eq ';' && !$next->snext_sibling
!$next $next->isa("PPI::Token::Structure") $next eq ";" not $next->snext_sibling
Truth table60%3/5
not(A) || B and C and not(D)
A= !$nextB= $next->isa("PPI::Token::Structure")C= $next eq ";"D= not $next->snext_sibling
ABCDresult
1XXX1
01111
00XX0
010X0
01100
64 || ($next->isa('PPI::Token::Structure')
65 && $next eq ';'
66 && ! $next->snext_sibling));
67 }
68  
69 40 1;
70 __END__
« Pulp/PodParser.pm ↑ Summary Policy/Documentation/ProhibitVerbatimMarkup.pm »