Policy/Variables/ProhibitExcessiveNames.pm

filter: Statementstmt 98.6% 72 / 73 Branchbran 95.8% 23 / 24 Conditioncond 95.0% 19 / 20 MC/DCmcdc 92.3% 12 / 13 Subroutinesub 93.3% 14 / 15 Podpod 44.4% 4 / 9 totaltotal 93.5% 144 / 154 CC 21 SCAR 17.9
CC
21
Cov
97%
happy
12.0
violates
6.0
invalid
3.1
CRAP 6.0
« Policy/ControlStructures/ProhibitInlineDo.pm ↑ Summary Grape.pm »
1 package Perl::Critic::Policy::Variables::ProhibitExcessiveNames;
2  
3 11 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Perl::Critic::Utils qw/:severities/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 our $VERSION = '0.1.4';
12  
13 11 Readonly::Scalar my $DESC => q{Use concise names};
14 11 Readonly::Scalar my $EXPL => undef;
15  
16 100 ▶sub applies_to { return qw/PPI::Statement::Variable PPI::Statement::Sub/ }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
17 52 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
18 0 ▶sub default_themes { return qw/cosmetic/ }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
19  
20 13 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 return (
22 {
23 13 name => 'subs',
24 description => 'Report excessive subroutine names.',
25 default_string => '1',
26 behavior => 'boolean',
27 },
28 {
29 name => 'vars',
30 description => 'Report excessive variable names.',
31 default_string => '1',
32 behavior => 'boolean',
33 },
34 {
35 name => 'length',
36 description => 'Maximum identify length.',
37 default_string => '15',
38 behavior => 'integer',
39 integer_minimum=> 0,
40 },
41 {
42 name => 'words',
43 description => 'Maximum number of words.',
44 default_string => '3',
45 behavior => 'integer',
46 integer_minimum=> 0,
47 },
48 {
49 name => 'smallest',
50 description => 'Smallest word length in a multi-word.',
51 default_string => '4',
52 behavior => 'integer',
53 integer_minimum=> 0,
54 },
55 {
56 name => 'lpw',
57 description => 'Length-per-word maximum average.',
58 default_string => '7',
59 behavior => 'integer',
60 integer_minimum=> 0,
61 },
62 {
63 name => 'short',
64 description => 'Always allowed at-or-below this length.',
65 default_string => '6',
66 behavior => 'integer',
67 integer_minimum=> 0,
68 },
69 );
70 }
71  
72 147 ▶sub desigil {
Subroutine desigil: called CC=1 SCAR=0.0
Pod undocumented
73 147 my ($name)=@_;
74 147 $name=~s/^[\%\@\$\&\*]//;
75 147 $name=~s/.*:://;
76 147 return $name;
77 }
78  
79 133 ▶sub splitter {
Subroutine splitter: called CC=3 SCAR=11.0
Pod undocumented
80 133 my ($name)=@_;
81 133 $name=~s/^[\%\@\$\&\*]//;
82 133 $name=~s/.*:://;
83 133 $name=~s/^_+//;
84 133 ▶ if($name=~/^[A-Z]+$/) { return $name }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^[A-Z]+$/) 2 131 133
85 131 ▶ if($name=~/_/) { return split(/_+/,$name) }
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /_/) 35 96 131
86 96 return split(/(?=[A-Z])/,$name)
87 }
88  
89 147 ▶sub happy {
Subroutine happy: called CC=12 SCAR=24.8
Pod undocumented
90 147 my ($name,$w,$L,$lpw,$small,$short)=@_;
91 147 $name=desigil($name);
92 147 my $NL=length($name);
93 147 ▶ if($short&&($NL<=$short)) { return 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($short and $NL <= $short) 26 121 147
Condition100%3/3
$short and $NL <= $short
!ll&&!rl&&r
863526
MC/DC100%2/2
$short and $NL <= $short
$short $NL <= $short
Truth table100%3/3
A and B
A= $shortB= $NL <= $short
ABresult
0X0
100
111
94 121 ▶ if($L&&($NL>$L)) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($L and $NL > $L) 10 111 121
Condition100%3/3
$L and $NL > $L
!ll&&!rl&&r
111010
MC/DC100%2/2
$L and $NL > $L
$L $NL > $L
Truth table100%3/3
A and B
A= $LB= $NL > $L
ABresult
0X0
100
111
95 111 my @S=splitter($name);
96 111 ▶ if($w&&($#S>=$w)) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($w and $#S >= $w) 10 101 111
Condition100%3/3
$w and $#S >= $w
!ll&&!rl&&r
110010
MC/DC100%2/2
$w and $#S >= $w
$w $#S >= $w
Truth table100%3/3
A and B
A= $wB= $#S >= $w
ABresult
0X0
100
111
97 101 ▶ if($#S) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#S) 78 23 101
98 78 ▶ if($lpw&&($NL>$lpw*(1+$#S))) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($lpw and $NL > $lpw * (1 + $#S)) 13 65 78
Condition100%3/3
$lpw and $NL > $lpw * (1 + $#S)
!ll&&!rl&&r
16413
MC/DC100%2/2
$lpw and $NL > $lpw * (1 + $#S)
$lpw $NL > $lpw * (1 + $#S)
Truth table100%3/3
A and B
A= $lpwB= $NL > $lpw * (1 + $#S)
ABresult
0X0
100
111
99 65 ▶ if($small) { foreach my $word (grep {length($_)<$small} @S) { return 0 } }
Branch: 1 branch
BranchTrueFalseTotal
if ($small) 63 2 65
100 }
101 59 return 1;
102 }
103  
104 52 ▶sub invalid {
Subroutine invalid: called CC=3 SCAR=11.3
Pod undocumented
105 52 my ($self,$elem,$note)=@_;
106 52 ▶ $note//='';
Condition50%1/2
$note //= ""
l!l
520
MC/DC0%0/1
$note //= ""
$note
Truth table50%1/2
A
A= $note
Aresult
11
00
107 52 ▶ if($note) { $note=" ($note)" }
Branch: 1 branch
BranchTrueFalseTotal
if ($note) 52 0 52
108 52 return $self->violation(sprintf("%s%s",$DESC,$note),$EXPL,$elem);
109 }
110  
111 100 ▶sub violates {
Subroutine violates: called CC=6 SCAR=17.9
Pod documented
112 100 my ($self,$elem,undef)=@_;
113 100 my %violations;
114 100 ▶ if($$self{_vars}&&$elem->isa('PPI::Statement::Variable')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_vars'} and $elem->isa('PPI::Statement::Variable')) { } 62 38 100
elsif ($self->{'_subs'} and $elem->isa('PPI::Statement::Sub')) { } 30 12 42
Condition100%3/3
$self->{"_vars"} and $elem->isa("PPI::Statement::Variable")
!ll&&!rl&&r
83062
MC/DC100%2/2
$self->{"_vars"} and $elem->isa("PPI::Statement::Variable")
$self->{"_vars"} $elem->isa("PPI::Statement::Variable")
Truth table100%3/3
A and B
A= $self->{"_vars"}B= $elem->isa("PPI::Statement::Variable")
ABresult
0X0
100
111
115 62 %violations=map {$_=>undef} grep {!happy($_,@$self{qw/_words _length _lpw _smallest _short/})} $elem->variables()
116 }
117 ▶ elsif($$self{_subs}&&$elem->isa('PPI::Statement::Sub')) {
Condition100%3/3
$self->{"_subs"} and $elem->isa("PPI::Statement::Sub")
!ll&&!rl&&r
4430
MC/DC100%2/2
$self->{"_subs"} and $elem->isa("PPI::Statement::Sub")
$self->{"_subs"} $elem->isa("PPI::Statement::Sub")
Truth table100%3/3
A and B
A= $self->{"_subs"}B= $elem->isa("PPI::Statement::Sub")
ABresult
0X0
100
111
118 30 %violations=map {$_=>undef} grep {!happy($_,@$self{qw/_words _length _lpw _smallest _short/})} $elem->name();
119 }
120 100 ▶ if(%violations) { return $self->invalid($elem,join(',',sort keys(%violations))) }
Branch: 1 branch
BranchTrueFalseTotal
if (%violations) 52 48 100
121 48 return;
122 }
123  
124 11 1;
125  
126 __END__
« Policy/ControlStructures/ProhibitInlineDo.pm ↑ Summary Grape.pm »