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

filter: Statementstmt 80.5% 29 / 36 Branchbran 12.5% 1 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 91.6% 11 / 12 Podpod 80.0% 4 / 5 totaltotal 69.7% 46 / 66 CC 7 SCAR 22.5
CC
7
Cov
66%
_all_global_vars
30.0
violates
3.8
BEGIN
1.0
CRAP 9.5
« lib/Perl/Critic/Policy/Variables/RequireLocalizedPunctuationVars.pm ↑ Summary lib/Perl/Critic/Annotation.pm »
1 package Perl::Critic::Policy::Variables::ProhibitLocalVars;
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 :classification };
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 $PACKAGE_RX => qr/::/xms;
16 40 Readonly::Scalar my $DESC => q{Variable declared as "local"};
17 40 Readonly::Scalar my $EXPL => [ 77, 78, 79 ];
18  
19 #-----------------------------------------------------------------------------
20  
21 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
22 74 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
23 85 ▶sub default_themes { return qw(core pbp maintenance) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
24 31 ▶sub applies_to { return 'PPI::Statement::Variable' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
25  
26 #-----------------------------------------------------------------------------
27  
28 85 ▶sub violates {
Subroutine violates: called CC=3 SCAR=13.3
Pod documented
29 85 my ( $self, $elem, undef ) = @_;
30 85 ▶ if ( $elem->type() eq 'local' && !_all_global_vars($elem) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->type eq "local" and not _all_global_vars($elem)) 0 85 85
Condition33%1/3
$elem->type eq "local" and not _all_global_vars($elem)
!ll&&!rl&&r
8500
MC/DC0%0/2
$elem->type eq "local" and not _all_global_vars($elem)
$elem->type eq "local" not _all_global_vars($elem)
Truth table33%1/3
A and not(B)
A= $elem->type eq "local"B= not _all_global_vars($elem)
ABresult
0X0
100
111
31 0 return $self->violation( $DESC, $EXPL, $elem );
32 }
33 85 return; #ok!
34 }
35  
36 #-----------------------------------------------------------------------------
37  
38 0 ▶sub _all_global_vars {
Subroutine _all_global_vars: not called CC=5 SCAR=34.0
39  
40 0 my $elem = shift;
41 0 for my $variable_name ( $elem->variables() ) {
42 0 ▶ next if $variable_name =~ $PACKAGE_RX;
Branch: 1 branch
BranchTrueFalseTotal
if $variable_name =~ /$PACKAGE_RX/ 0 0 0
43 # special exception for Test::More
44 0 ▶ next if $variable_name eq '$TODO'; ## no critic (InterpolationOfMetachars)
Branch: 1 branch
BranchTrueFalseTotal
if $variable_name eq "\$TODO" 0 0 0
45 0 ▶ return if ! is_perl_global( $variable_name );
Branch: 1 branch
BranchTrueFalseTotal
unless is_perl_global($variable_name) 0 0 0
46 }
47 0 return 1;
48 }
49  
50 40 1;
51  
52 __END__
« lib/Perl/Critic/Policy/Variables/RequireLocalizedPunctuationVars.pm ↑ Summary lib/Perl/Critic/Annotation.pm »