File Coverage

blib/lib/Perl/Critic/Policy/References/ProhibitDoubleSigils.pm
Criterion Covered Total %
statement 30 30 100.0
branch 9 10 90.0
condition 3 3 100.0
subroutine 11 11 100.0
pod 4 5 80.0
total 57 59 96.6


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::References::ProhibitDoubleSigils;
2              
3 40     40   26852 use 5.010001;
  40         215  
4 40     40   245 use strict;
  40         106  
  40         856  
5 40     40   228 use warnings;
  40         110  
  40         1068  
6 40     40   236 use Readonly;
  40         107  
  40         2044  
7              
8 40     40   304 use Perl::Critic::Utils qw{ :severities };
  40         123  
  40         2012  
9 40     40   5114 use parent 'Perl::Critic::Policy';
  40         105  
  40         241  
10              
11             our $VERSION = '1.148';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Double-sigil dereference};
16             Readonly::Scalar my $EXPL => [ 228 ];
17              
18             #-----------------------------------------------------------------------------
19              
20 93     93 0 1651 sub supported_parameters { return () }
21 80     80 1 369 sub default_severity { return $SEVERITY_LOW }
22 84     84 1 475 sub default_themes { return qw(core pbp cosmetic) }
23 34     34 1 111 sub applies_to { return 'PPI::Token::Cast' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 21     21 1 40 my ( $self, $elem, undef ) = @_;
29 21 100       53 return if $elem eq q{\\};
30 17 100       229 return if $elem =~ /[@ $ % * &] [*]/xms;
31 12 100       69 return if $elem eq q{$#*}; ## no critic (RequireInterpolationOfMetachars)
32              
33 11         131 my $sib = $elem->snext_sibling;
34 11 50       283 return if !$sib;
35 11 100 100     69 if ( ! $sib->isa('PPI::Structure::Block') && ! $sib->isa('PPI::Structure::Subscript') ) {
36 6         32 return $self->violation( $DESC, $EXPL, $elem );
37             }
38 5         17 return; #ok!
39             }
40              
41             1;
42              
43             __END__
44              
45             #-----------------------------------------------------------------------------
46              
47             =pod
48              
49             =head1 NAME
50              
51             Perl::Critic::Policy::References::ProhibitDoubleSigils - Write C<@{ $array_ref }> instead of C<@$array_ref>.
52              
53             =head1 AFFILIATION
54              
55             This Policy is part of the core L<Perl::Critic|Perl::Critic>
56             distribution.
57              
58              
59             =head1 DESCRIPTION
60              
61             When dereferencing a reference, put braces around the reference to
62             separate the sigils. Especially for newbies, the braces eliminate any
63             potential confusion about the relative precedence of the sigils.
64              
65             push @$array_ref, 'foo', 'bar', 'baz'; #not ok
66             push @{ $array_ref }, 'foo', 'bar', 'baz'; #ok
67              
68             foreach ( keys %$hash_ref ){} #not ok
69             foreach ( keys %{ $hash_ref } ){} #ok
70              
71              
72             =head1 CONFIGURATION
73              
74             This Policy is not configurable except for the standard options.
75              
76              
77             =head1 AUTHOR
78              
79             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
80              
81             =head1 COPYRIGHT
82              
83             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
84              
85             This program is free software; you can redistribute it and/or modify
86             it under the same terms as Perl itself. The full text of this license
87             can be found in the LICENSE file included with this module.
88              
89             =cut
90              
91             # Local Variables:
92             # mode: cperl
93             # cperl-indent-level: 4
94             # fill-column: 78
95             # indent-tabs-mode: nil
96             # c-indentation-style: bsd
97             # End:
98             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :