lib/Perl/Critic/Policy/Variables/ProhibitMatchVars.pm

filter: Statementstmt 90.2% 37 / 41 Branchbran 57.1% 8 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 80.0% 4 / 5 totaltotal 80.7% 63 / 78 CC 9 SCAR 13.8
CC
9
Cov
79%
_is_use_english
9.8
violates
3.8
_is_forbidden_var
2.0
CRAP 4.0
« lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitInterpolationOfLiterals.pm ↑ Summary lib/Perl/Critic/Policy/Subroutines/ProhibitBuiltinHomonyms.pm »
1 package Perl::Critic::Policy::Variables::ProhibitMatchVars;
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 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities :data_conversion };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.156';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{Match variable used};
16 40 Readonly::Scalar my $EXPL => [ 82 ];
17  
18 40 Readonly::Array my @FORBIDDEN => qw( $` $& $' $MATCH $PREMATCH $POSTMATCH );
19 40 Readonly::Hash my %FORBIDDEN => hashify( @FORBIDDEN );
20  
21 #-----------------------------------------------------------------------------
22  
23 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 74 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 85 ▶sub default_themes { return qw( core performance pbp ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 33 ▶sub applies_to { return qw( PPI::Token::Symbol
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27 PPI::Statement::Include ) }
28  
29 #-----------------------------------------------------------------------------
30  
31 239 ▶sub violates {
Subroutine violates: called CC=3 SCAR=13.3
Pod documented
32 239 my ( $self, $elem, undef ) = @_;
33 239 ▶ if (_is_use_english($elem) || _is_forbidden_var($elem)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_use_english($elem) or _is_forbidden_var($elem)) 0 239 239
Condition33%1/3
_is_use_english($elem) or _is_forbidden_var($elem)
l!l&&r!l&&!r
00239
MC/DC0%0/2
_is_use_english($elem) or _is_forbidden_var($elem)
_is_use_english($elem) _is_forbidden_var($elem)
Truth table33%1/3
A or B
A= _is_use_english($elem)B= _is_forbidden_var($elem)
ABresult
1X1
011
000
34 0 return $self->violation( $DESC, $EXPL, $elem );
35 }
36 239 return; #ok!
37 }
38  
39 #-----------------------------------------------------------------------------
40  
41 239 ▶sub _is_use_english {
Subroutine _is_use_english: called CC=6 SCAR=22.8
42 239 my $elem = shift;
43 239 ▶ $elem->isa('PPI::Statement::Include') || return;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Statement::Include") or return 61 178 239
44 61 ▶ $elem->type() eq 'use' || return;
Branch: 1 branch
BranchTrueFalseTotal
$elem->type eq "use" or return 59 2 61
45 59 ▶ $elem->module() eq 'English' || return;
Branch: 1 branch
BranchTrueFalseTotal
$elem->module eq "English" or return 0 59 59
46  
47 # Bare, lacking -no_match_vars. Now handled by
48 # Modules::RequireNoMatchVarsWithUseEnglish.
49 0 ▶ return 0 if ($elem =~ m/\A use \s+ English \s* ;\z/xms);
Branch: 1 branch
BranchTrueFalseTotal
if $elem =~ /\A use \s+ English \s* ;\z/msx 0 0 0
50  
51 0 ▶ return 1 if ($elem =~ m/\$(?:PRE|POST|)MATCH/xms);
Branch: 1 branch
BranchTrueFalseTotal
if $elem =~ /\$(?:PRE|POST|)MATCH/msx 0 0 0
52 0 return; # either "-no_match_vars" or a specific list
53 }
54  
55 239 ▶sub _is_forbidden_var {
Subroutine _is_forbidden_var: called CC=2 SCAR=6.9
56 239 my $elem = shift;
57 239 ▶ $elem->isa('PPI::Token::Symbol') || return;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::Symbol") or return 178 61 239
58 178 return exists $FORBIDDEN{$elem};
59 }
60  
61 40 1;
62  
63 __END__
« lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitInterpolationOfLiterals.pm ↑ Summary lib/Perl/Critic/Policy/Subroutines/ProhibitBuiltinHomonyms.pm »