« 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 55 | ▶ | return if $elem->module() ne 'English'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( $current_element->isa('PPI::Token::Quote') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return if $current_element->string() eq '-no_match_vars'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
$current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::COMMA and $current_element->content ne $Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish::FATCOMMA
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
@{$elements_ref;} >= 2 and $current_element->isa("PPI::Token::Word") and $current_element->content =~ /\A v \d+ \z/msx
@{$elements_ref;} >= 2 and $current_element->isa("PPI::Token::Word")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $current_element = $elements[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( $current_element->isa('PPI::Structure::List') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my @grand_children = $current_element->schildren(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if (not @grand_children) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my @great_grand_children = $grand_child->schildren(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (not @great_grand_children) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||