lib/Perl/Critic/Policy/Modules/RequireNoMatchVarsWithUseEnglish.pm

filter: Statementstmt 38.8% 28 / 72 Branchbran 8.8% 3 / 34 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 84.6% 11 / 13 Podpod 80.0% 4 / 5 totaltotal 31.5% 46 / 146 CC 23 SCAR 41.1
CC
23
Cov
26%
violates
125.2
_skip_version_number
42.0
_descend_into_parenthesized_list_if_present
42.0
CRAP 61.2
« lib/Perl/Critic/Policy/ErrorHandling/RequireCarping.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitComplexMappings.pm »
1 package Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw< :characters :severities >;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Scalar my $EXPL =>
17 q{"use English" without the '-no_match_vars' argument degrades performance.'};
18 40 Readonly::Scalar my $DESC => q{"use English" without '-no_match_vars' argument};
19  
20 #-----------------------------------------------------------------------------
21  
22 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
23 74 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
24 73 ▶sub default_themes { return qw( core performance ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
25 31 ▶sub applies_to { return 'PPI::Statement::Include' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
26  
27 #-----------------------------------------------------------------------------
28  
29 57 ▶sub violates {
Subroutine violates: called CC=13 SCAR=48.3
Pod documented
30 57 my ( $self, $elem, undef ) = @_;
31  
32 # "require"ing English is kind of useless.
33 57 ▶ return if $elem->type() ne 'use';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->type ne "use" 2 55 57
34 55 ▶ return if $elem->module() ne 'English';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->module ne "English" 55 0 55
35  
36 0 my @elements = $elem->schildren();
37 0 shift @elements; # dump "use"
38 0 shift @elements; # dump "English"
39  
40 0 ▶ if (not @elements) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@elements) 0 0 0
41 0 return $self->violation($DESC, $EXPL, $elem);
42 }
43  
44 0 _skip_version_number( \@elements );
45  
46 0 @elements = _descend_into_parenthesized_list_if_present(@elements);
47  
48 0 ▶ if (not @elements) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@elements) 0 0 0
49 0 return $self->violation($DESC, $EXPL, $elem);
50 }
51  
52 0 my $current_element = $elements[0];
53  
54 0 ▶ while ( $current_element ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_element) 0 0 0
55 0 ▶ if ( $current_element->isa('PPI::Token::Quote') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($current_element->isa('PPI::Token::Quote')) { } 0 0 0
elsif ($current_element->isa('PPI::Token::QuoteLike::Words')) { } 0 0 0
elsif (not $current_element->isa('PPI::Token::Operator') or $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::COMMA and $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::FATCOMMA) { } 0 0 0
56 0 ▶ return if $current_element->string() eq '-no_match_vars';
Branch: 1 branch
BranchTrueFalseTotal
if $current_element->string eq "-no_match_vars" 0 0 0
57 }
58 elsif ( $current_element->isa('PPI::Token::QuoteLike::Words') ) {
59 0 ▶ return if $current_element->content() =~ m/-no_match_vars \b/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $current_element->content =~ /-no_match_vars \b/msx 0 0 0
60 }
61 ▶ elsif (
Condition0%0/6
not $current_element->isa("PPI::Token::Operator") or $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::COMMA and $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::FATCOMMA
l!l&&r!l&&!r
000
$current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::COMMA and $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::FATCOMMA
!ll&&!rl&&r
000
MC/DC0%0/3
not $current_element->isa("PPI::Token::Operator") or $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::COMMA and $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::FATCOMMA
not $current_element->isa("PPI::Token::Operator") $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::COMMA $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::FATCOMMA
Truth table0%0/4
not(A) or B and C
A= not $current_element->isa("PPI::Token::Operator")B= $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::COMMAC= $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::FATCOMMA
ABCresult
1XX1
0111
00X0
0100
62 not $current_element->isa('PPI::Token::Operator')
63 or $current_element->content() ne $COMMA
64 and $current_element->content() ne $FATCOMMA
65 ) {
66 0 return $self->violation($DESC, $EXPL, $elem);
67 }
68  
69 0 shift @elements;
70 0 $current_element = $elements[0];
71 }
72  
73 0 return $self->violation($DESC, $EXPL, $elem);
74 }
75  
76  
77 0 ▶sub _skip_version_number {
Subroutine _skip_version_number: not called CC=6 SCAR=37.4
78 0 my ($elements_ref) = @_;
79  
80 0 my $current_element = $elements_ref->[0];
81  
82 0 ▶ if ( $current_element->isa('PPI::Token::Number') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($current_element->isa('PPI::Token::Number')) { } 0 0 0
elsif (@{$elements_ref;} >= 2 and $current_element->isa('PPI::Token::Word') and $current_element->content =~ /\A v \d+ \z/msx and $elements_ref->[1]->isa('PPI::Token::Number')) { } 0 0 0
83 0 shift @{$elements_ref};
84 }
85 ▶ elsif (
Condition0%0/9
@{$elements_ref;} >= 2 and $current_element->isa("PPI::Token::Word") and $current_element->content =~ /\A v \d+ \z/msx and $elements_ref->[1]->isa("PPI::Token::Number")
!ll&&!rl&&r
000
@{$elements_ref;} >= 2 and $current_element->isa("PPI::Token::Word") and $current_element->content =~ /\A v \d+ \z/msx
!ll&&!rl&&r
000
@{$elements_ref;} >= 2 and $current_element->isa("PPI::Token::Word")
!ll&&!rl&&r
000
MC/DC0%0/4
@{$elements_ref;} >= 2 and $current_element->isa("PPI::Token::Word") and $current_element->content =~ /\A v \d+ \z/msx and $elements_ref->[1]->isa("PPI::Token::Number")
@{$elements_ref;} >= 2 $current_element->isa("PPI::Token::Word") $current_element->content =~ /\A v \d+ \z/msx $elements_ref->[1]->isa("PPI::Token::Number")
Truth table0%0/5
A and B and C and D
A= @{$elements_ref;} >= 2B= $current_element->isa("PPI::Token::Word")C= $current_element->content =~ /\A v \d+ \z/msxD= $elements_ref->[1]->isa("PPI::Token::Number")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
86 0 @{$elements_ref} >= 2
87 and $current_element->isa('PPI::Token::Word')
88 and $current_element->content() =~ m/\A v \d+ \z/xms
89 and $elements_ref->[1]->isa('PPI::Token::Number')
90 ) {
91 # The above messy conditional necessary due to PPI not handling
92 # v-strings.
93 0 shift @{$elements_ref};
94 0 shift @{$elements_ref};
95 }
96  
97 0 return;
98 }
99  
100 0 ▶sub _descend_into_parenthesized_list_if_present {
Subroutine _descend_into_parenthesized_list_if_present: not called CC=6 SCAR=37.4
101 0 my @elements = @_;
102  
103 0 ▶ return if not @elements;
Branch: 1 branch
BranchTrueFalseTotal
unless @elements 0 0 0
104  
105 0 my $current_element = $elements[0];
106  
107 0 ▶ if ( $current_element->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_element->isa("PPI::Structure::List")) 0 0 0
108 0 my @grand_children = $current_element->schildren();
109 0 ▶ if (not @grand_children) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@grand_children) 0 0 0
110 0 return;
111 }
112  
113 0 my $grand_child = $grand_children[0];
114  
115 0 ▶ if ( $grand_child->isa('PPI::Statement::Expression') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grand_child->isa('PPI::Statement::Expression')) { } 0 0 0
116 0 my @great_grand_children = $grand_child->schildren();
117  
118 0 ▶ if (not @great_grand_children) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@great_grand_children) 0 0 0
119 0 return;
120 }
121  
122 0 return @great_grand_children;
123 }
124 else {
125 0 return @grand_children;
126 }
127 }
128  
129 0 return @elements;
130 }
131  
132 40 1;
133  
134 __END__
« lib/Perl/Critic/Policy/ErrorHandling/RequireCarping.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitComplexMappings.pm »