lib/Perl/Critic/Policy/NamingConventions/ProhibitAmbiguousNames.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 89.0% 65 / 73 CC 9 SCAR 16.5
CC
9
Cov
88%
violates
9.8
BEGIN
1.0
BEGIN
1.0
CRAP 5.2
« lib/Perl/Critic/PolicyFactory.pm ↑ Summary lib/Perl/Critic/Statistics.pm »
1 package Perl::Critic::Policy::NamingConventions::ProhibitAmbiguousNames;
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 $EXPL => [ 48 ];
16  
17 40 Readonly::Scalar my $DEFAULT_FORBID =>
18 'abstract bases close contract last left no record right second set';
19  
20 #-----------------------------------------------------------------------------
21  
22 91 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
23 return (
24 {
25 91 name => 'forbid',
26 description => 'The variable names that are not to be allowed.',
27 default_string => $DEFAULT_FORBID,
28 behavior => 'string list',
29 },
30 );
31 }
32  
33 74 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
34 85 ▶sub default_themes { return qw(core pbp maintenance) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
35 31 ▶sub applies_to { return qw(PPI::Statement::Sub
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
36 PPI::Statement::Variable) }
37  
38 #-----------------------------------------------------------------------------
39  
40 90 ▶sub violates {
Subroutine violates: called CC=9 SCAR=22.9
Pod documented
41 90 my ( $self, $elem, undef ) = @_;
42  
43 90 ▶ if ( $elem->isa('PPI::Statement::Sub') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Statement::Sub")) 5 85 90
44 5 my @words = grep { $_->isa('PPI::Token::Word') } $elem->schildren();
45 5 for my $word (@words) {
46  
47 # strip off any leading "Package::"
48 10 my ($name) = $word =~ m/ (\w+) \z /xms;
49 10 ▶ next if not defined $name; # should never happen, right?
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 10 10
50  
51 10 ▶ if ( exists $self->{_forbid}->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_forbid"}{$name}) 0 10 10
52 0 return $self->violation(
53 qq<Ambiguously named subroutine "$name">,
54 $EXPL,
55 $elem,
56 );
57 }
58 }
59 5 return; # ok
60 }
61  
62 # PPI::Statement::Variable
63  
64 # Accumulate them since there can be more than one violation
65 # per variable statement
66 85 my @violations;
67  
68 # TODO: false positive bug - this can erroneously catch the
69 # assignment half of a variable statement
70  
71 85 my $symbols = $elem->find('PPI::Token::Symbol');
72 85 ▶ if ($symbols) { # this should always be true, right?
Branch: 1 branch
BranchTrueFalseTotal
if ($symbols) 85 0 85
73 85 for my $symbol ( @{$symbols} ) {
74  
75 # Strip off sigil and any leading "Package::"
76 # Beware that punctuation vars may have no
77 # alphanumeric characters.
78  
79 85 my ($name) = $symbol =~ m/ (\w+) \z /xms;
80 85 ▶ next if ! defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 85 85
81  
82 85 ▶ if ( exists $self->{_forbid}->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_forbid"}{$name}) 0 85 85
83 0 push
84 @violations,
85 $self->violation(
86 qq<Ambiguously named variable "$name">,
87 $EXPL,
88 $elem,
89 );
90 }
91 }
92 }
93  
94 85 return @violations;
95 }
96  
97 40 1;
98  
99 __END__
« lib/Perl/Critic/PolicyFactory.pm ↑ Summary lib/Perl/Critic/Statistics.pm »