File Coverage

blib/lib/Perl/Critic/Policy/Community/ArrayAssignAref.pm
Criterion Covered Total %
statement 13 14 92.8
branch n/a
condition n/a
subroutine 5 6 83.3
pod 2 2 100.0
total 20 22 90.9


line stmt bran cond sub pod time code
1              
2             use strict;
3 1     1   343 use warnings;
  1         2  
  1         22  
4 1     1   4  
  1         25  
  1         62  
5             use Perl::Critic::Utils qw(:severities :classification :ppi);
6 1     1   6 use parent 'Perl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref';
  1         2  
  1         89  
7 1     1   299  
  1         2  
  1         5  
8             our $VERSION = 'v1.0.3';
9              
10              
11 2     2 1 26652 1;
12 0     0 1    
13             =head1 NAME
14              
15             Perl::Critic::Policy::Community::ArrayAssignAref - Don't assign an anonymous
16             arrayref to an array
17              
18             =head1 DESCRIPTION
19              
20             A common mistake is to assign values to an array but use arrayref brackets
21             C<[]> rather than parentheses C<()>. This results in the array containing one
22             element, an arrayref, which is usually unintended. If intended, the arrayref
23             brackets can be wrapped in parentheses for clarity.
24              
25             @array = []; # not ok
26             @array = [1, 2, 3]; # not ok
27             @array = ([1, 2, 3]); # ok
28              
29             This policy is a subclass of the L<Perl::Critic::Pulp> policy
30             L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref>, and
31             performs the same function but in the C<community> theme.
32              
33             =head1 AFFILIATION
34              
35             This policy is part of L<Perl::Critic::Community>.
36              
37             =head1 CONFIGURATION
38              
39             This policy is not configurable except for the standard options.
40              
41             =head1 AUTHOR
42              
43             Dan Book, C<dbook@cpan.org>
44              
45             =head1 COPYRIGHT AND LICENSE
46              
47             Copyright 2015, Dan Book.
48              
49             This library is free software; you may redistribute it and/or modify it under
50             the terms of the Artistic License version 2.0.
51              
52             =head1 SEE ALSO
53              
54             L<Perl::Critic>, L<Perl::Critic::Pulp>