Policy/NamingConventions/ProhibitMixedCaseVars.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 91.6% 11 / 12 Podpod 80.0% 4 / 5 totaltotal 95.4% 63 / 66 CC 6 SCAR 8.6
CC
6
Cov
98%
_has_mixed_case_vars
5.0
default_themes
2.0
violates
2.0
CRAP 2.4
« Utils/PPIRegexp.pm ↑ Summary Policy/Miscellanea/RequireRcsKeywords.pm »
1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-Deprecated/lib/Perl/Critic/Policy/NamingConventions/ProhibitMixedCaseVars.pm $
3 # $Date: 2013-10-29 09:11:44 -0700 (Tue, 29 Oct 2013) $
4 # $Author: thaljef $
5 # $Revision: 4214 $
6 ##############################################################################
7  
8 package Perl::Critic::Policy::NamingConventions::ProhibitMixedCaseVars;
9  
10 1 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 our $VERSION = '1.119';
21  
22 #-----------------------------------------------------------------------------
23  
24 1 Readonly::Scalar my $PACKAGE_RX => qr/ :: /xms;
25 1 Readonly::Scalar my $UPPER_LOWER => qr/ [[:upper:]] [[:lower:]] /xms;
26 1 Readonly::Scalar my $LOWER_UPPER => qr/ [[:lower:]] [[:upper:]] /xms;
27 1 Readonly::Scalar my $MIXED_RX => qr{ $UPPER_LOWER | $LOWER_UPPER }xmso;
28 1 Readonly::Scalar my $DESC => 'Mixed-case variable name(s)';
29 1 Readonly::Scalar my $EXPL => [ 45, 46 ];
30  
31 #-----------------------------------------------------------------------------
32  
33 4 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
34 10 ▶sub default_severity { return $SEVERITY_LOWEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
35 0 ▶sub default_themes { return qw( deprecated pbp cosmetic ) }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
36 4 ▶sub applies_to { return 'PPI::Statement::Variable' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
37  
38 #-----------------------------------------------------------------------------
39  
40 20 ▶sub violates {
Subroutine violates: called CC=2 SCAR=6.9
Pod documented
41 20 my ( $self, $elem, undef ) = @_;
42 20 ▶ if ( _has_mixed_case_vars($elem) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_has_mixed_case_vars($elem)) 10 10 20
43 10 return $self->violation( $DESC, $EXPL, $elem );
44 }
45 10 return; #ok!
46 }
47  
48  
49 20 ▶sub _has_mixed_case_vars {
Subroutine _has_mixed_case_vars: called CC=5 SCAR=16.1
50 20 my $elem = shift;
51 20 for my $variable_name ( $elem->variables() ) {
52  
53 #Variables with fully qualified package names are exempt
54 #because we can't really be responsible for symbols that
55 #are defined in other packages.
56  
57 31 ▶ next if 'local' eq $elem->type() && $variable_name =~ m/$PACKAGE_RX/xms;
Branch: 1 branch
BranchTrueFalseTotal
if "local" eq $elem->type and $variable_name =~ /$PACKAGE_RX/msx 2 29 31
Condition100%3/3
"local" eq $elem->type and $variable_name =~ /$PACKAGE_RX/msx
!ll&&!rl&&r
2272
MC/DC100%2/2
"local" eq $elem->type and $variable_name =~ /$PACKAGE_RX/msx
"local" eq $elem->type $variable_name =~ /$PACKAGE_RX/msx
Truth table100%3/3
A and B
A= "local" eq $elem->typeB= $variable_name =~ /$PACKAGE_RX/msx
ABresult
0X0
100
111
58 29 ▶ return 1 if $variable_name =~ m/$MIXED_RX/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $variable_name =~ /$MIXED_RX/msx 10 19 29
59 }
60 10 return 0;
61 }
62  
63 1 1;
64  
65 __END__
« Utils/PPIRegexp.pm ↑ Summary Policy/Miscellanea/RequireRcsKeywords.pm »