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