| 1 | package Perl::Critic::Policy::Community::LexicalForeachIterator; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use Perl::Critic::Utils qw(:severities :classification :ppi); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use parent 'Perl::Critic::Policy::Variables::RequireLexicalLoopIterators'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 1 | our $VERSION = 'v1.0.4'; | |
| 10 | |||
| 11 | 2 | ▶ | sub default_severity { $SEVERITY_HIGH } |
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||
| 12 | 0 | ▶ | sub default_themes { 'community' } |
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 13 | |||
| 14 | 1 | 1; | |
| 15 | |||
| 16 | =head1 NAME | ||
| 17 | |||
| 18 | Perl::Critic::Policy::Community::LexicalForeachIterator - Don't use undeclared | ||
| 19 | foreach loop iterators | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | It's possible to use a variable that's already been declared as the iterator | ||
| 24 | for a L<foreach loop|perlsyn/"Foreach Loops">, but this will localize the | ||
| 25 | variable to the loop and its value will be reverted after the loop is done. | ||
| 26 | Always declare the loop iterator in the lexical scope of the loop with C<my>. | ||
| 27 | |||
| 28 | foreach $foo (...) {...} # not ok | ||
| 29 | for $bar (...) {...} # not ok | ||
| 30 | foreach my $foo (...) {...} # ok | ||
| 31 | for my $bar (...) {...} # ok | ||
| 32 | |||
| 33 | This policy is a subclass of the L<Perl::Critic> core policy | ||
| 34 | L<Perl::Critic::Policy::Variables::RequireLexicalLoopIterators>, and performs | ||
| 35 | the same function but in the C<community> theme. | ||
| 36 | |||
| 37 | =head1 AFFILIATION | ||
| 38 | |||
| 39 | This policy is part of L<Perl::Critic::Community>. | ||
| 40 | |||
| 41 | =head1 CONFIGURATION | ||
| 42 | |||
| 43 | This policy is not configurable except for the standard options. | ||
| 44 | |||
| 45 | =head1 AUTHOR | ||
| 46 | |||
| 47 | Dan Book, C<dbook@cpan.org> | ||
| 48 | |||
| 49 | =head1 COPYRIGHT AND LICENSE | ||
| 50 | |||
| 51 | Copyright 2015, Dan Book. | ||
| 52 | |||
| 53 | This library is free software; you may redistribute it and/or modify it under | ||
| 54 | the terms of the Artistic License version 2.0. | ||
| 55 | |||
| 56 | =head1 SEE ALSO | ||
| 57 | |||
| 58 | L<Perl::Critic> | ||