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

filter: Statementstmt 97.6% 41 / 42 Branchbran 58.3% 7 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 83.3% 5 / 6 totaltotal 85.9% 67 / 78 CC 8 SCAR 12.7
CC
8
Cov
86%
violates
8.0
prepare_to_scan_document
2.1
BEGIN
1.0
CRAP 3.6
« lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitVoidMap.pm ↑ Summary lib/Perl/Critic/Policy/InputOutput/ProhibitBacktickOperators.pm »
1 package Perl::Critic::Policy::Variables::RequireLexicalLoopIterators;
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 40 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw( :severities );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Scalar my $DESC => q{Loop iterator is not lexical};
17 40 Readonly::Scalar my $EXPL => [ 108 ];
18  
19 40 Readonly::Scalar my $MINIMUM_PERL_VERSION => version->new( 5.004 );
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_HIGHEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 91 ▶sub default_themes { return qw(core pbp bugs certrec ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 37 ▶sub applies_to { return 'PPI::Statement::Compound' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27  
28 #-----------------------------------------------------------------------------
29  
30 37 ▶sub prepare_to_scan_document {
Subroutine prepare_to_scan_document: called CC=2 SCAR=7.6
Pod documented
31 37 my ( undef, $document ) = @_;
32 # perl5004delta says that is when lexical iterators were introduced,
33 # so ... (RT 67760)
34 37 my $version = $document->highest_explicit_perl_version();
35 37 ▶ return ! $version || $version >= $MINIMUM_PERL_VERSION;
Condition33%1/3
!$version || $version >= $MINIMUM_PERL_VERSION
l!l&&r!l&&!r
3700
MC/DC0%0/2
!$version || $version >= $MINIMUM_PERL_VERSION
!$version $version >= $MINIMUM_PERL_VERSION
Truth table33%1/3
not(A) || B
A= !$versionB= $version >= $MINIMUM_PERL_VERSION
ABresult
1X1
011
000
36 }
37  
38 #-----------------------------------------------------------------------------
39  
40 11 ▶sub violates {
Subroutine violates: called CC=7 SCAR=20.8
Pod documented
41 11 my ( $self, $elem, undef ) = @_;
42  
43 # First child will be 'for' or 'foreach' keyword
44 11 ▶ return if $elem->type() ne 'foreach';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->type ne "foreach" 5 6 11
45  
46 6 my $first_child = $elem->schild(0);
47 6 ▶ return if not $first_child;
Branch: 1 branch
BranchTrueFalseTotal
unless $first_child 0 6 6
48 6 ▶ my $start = $first_child->isa('PPI::Token::Label') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$first_child->isa('PPI::Token::Label') ? : 0 6 6
49  
50 6 my $potential_scope = $elem->schild($start + 1);
51 6 ▶ return if not $potential_scope;
Branch: 1 branch
BranchTrueFalseTotal
unless $potential_scope 0 6 6
52 6 ▶ return if $potential_scope->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if $potential_scope->isa("PPI::Structure::List") 0 6 6
53  
54 6 ▶ return if $potential_scope eq 'my';
Branch: 1 branch
BranchTrueFalseTotal
if $potential_scope eq "my" 6 0 6
55  
56 0 return $self->violation( $DESC, $EXPL, $elem );
57 }
58  
59 #-----------------------------------------------------------------------------
60  
61 40 1;
62  
63 __END__
« lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitVoidMap.pm ↑ Summary lib/Perl/Critic/Policy/InputOutput/ProhibitBacktickOperators.pm »