Policy/Community/LoopOnHash.pm

filter: Statementstmt 93.7% 15 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 91.6% 22 / 24 CC 1 SCAR 1.5
CC
1
Cov
94%
default_themes
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Policy/Community/LexicalForeachIterator.pm ↑ Summary
1 package Perl::Critic::Policy::Community::LoopOnHash;
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::ProhibitLoopOnHash';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = 'v1.0.4';
10  
11 4 ▶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::LoopOnHash - Don't loop over hashes
19  
20 =head1 DESCRIPTION
21  
22 It's possible to loop over a hash as if it was a list, which results in
23 alternating between the keys and values of the hash. Often, the intent was
24 instead to loop over either the keys or the values of the hash.
25  
26 foreach my $foo (%hash) { ... } # not ok
27 action() for %hash; # not ok
28 foreach my $foo (keys %hash) { ... } # ok
29 action() for values %hash; # ok
30  
31 If you intended to loop over alternating keys and values, you can make this
32 intent clear by first copying them to an array:
33  
34 foreach my $key_or_value (@{[%hash]}) { ... }
35 foreach my $key_or_value (my @dummy = %hash) { ... }
36  
37 This policy is a subclass of the policy
38 L<Perl::Critic::Policy::Variables::ProhibitLoopOnHash>, and performs the same
39 function but in the C<community> theme.
40  
41 =head1 AFFILIATION
42  
43 This policy is part of L<Perl::Critic::Community>.
44  
45 =head1 CONFIGURATION
46  
47 This policy is not configurable except for the standard options.
48  
49 =head1 AUTHOR
50  
51 Dan Book, C<dbook@cpan.org>
52  
53 =head1 COPYRIGHT AND LICENSE
54  
55 Copyright 2015, Dan Book.
56  
57 This library is free software; you may redistribute it and/or modify it under
58 the terms of the Artistic License version 2.0.
59  
60 =head1 SEE ALSO
61  
62 L<Perl::Critic>
« Policy/Community/LexicalForeachIterator.pm ↑ Summary