| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::BuiltinFunctions::ProhibitDeleteOnArrays; |
|
2
|
|
|
|
|
|
|
$Perl::Critic::Policy::BuiltinFunctions::ProhibitDeleteOnArrays::VERSION = '0.02'; |
|
3
|
1
|
|
|
1
|
|
872012
|
use 5.006001; |
|
|
1
|
|
|
|
|
2
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
17
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
24
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Readonly; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
54
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Perl::Critic::Utils qw{ :severities :classification :ppi }; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
65
|
|
|
9
|
1
|
|
|
1
|
|
322
|
use base 'Perl::Critic::Policy'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
540
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{"delete" on array}; |
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Calling delete on array values is strongly discouraged}; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
18
|
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
0
|
140531
|
sub supported_parameters { return () } |
|
20
|
12
|
|
|
12
|
1
|
74
|
sub default_severity { return $SEVERITY_LOW } |
|
21
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { return qw(maintenance) } |
|
22
|
3
|
|
|
3
|
1
|
48266
|
sub applies_to { return 'PPI::Token::Word' } |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub violates { |
|
27
|
42
|
|
|
42
|
1
|
2722
|
my ( $self, $elem, undef ) = @_; |
|
28
|
42
|
100
|
|
|
|
82
|
return if $elem ne 'delete'; |
|
29
|
24
|
100
|
|
|
|
297
|
return if !is_function_call($elem); |
|
30
|
|
|
|
|
|
|
|
|
31
|
21
|
|
|
|
|
3662
|
my ($ppi_arg) = parse_arg_list($elem); |
|
32
|
21
|
50
|
|
|
|
2618
|
return if !$ppi_arg; |
|
33
|
|
|
|
|
|
|
|
|
34
|
21
|
|
|
|
|
36
|
my $subscr = _get_delete_subscript($ppi_arg); |
|
35
|
21
|
50
|
|
|
|
45
|
return if !$subscr; |
|
36
|
|
|
|
|
|
|
|
|
37
|
21
|
100
|
|
|
|
51
|
if ($subscr->start->content eq q#[#) { |
|
38
|
12
|
|
|
|
|
80
|
return $self->violation( $DESC, $EXPL, $elem ); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
56
|
return; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _get_delete_subscript { |
|
46
|
21
|
|
|
21
|
|
26
|
my ($arg) = @_; |
|
47
|
|
|
|
|
|
|
|
|
48
|
21
|
|
|
|
|
17
|
my $subscr; |
|
49
|
21
|
|
|
|
|
44
|
for my $i (1 .. $#$arg) { |
|
50
|
43
|
|
|
|
|
78
|
my $token = $arg->[$i]; |
|
51
|
|
|
|
|
|
|
|
|
52
|
43
|
100
|
100
|
|
|
179
|
if ( |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$token->isa("PPI::Structure::Subscript") |
|
54
|
|
|
|
|
|
|
|| ( |
|
55
|
|
|
|
|
|
|
$i == 2 && |
|
56
|
|
|
|
|
|
|
$token->isa("PPI::Structure::Constructor") && |
|
57
|
|
|
|
|
|
|
$arg->[$i-2]->isa("PPI::Token::Cast") |
|
58
|
|
|
|
|
|
|
) |
|
59
|
|
|
|
|
|
|
) { |
|
60
|
26
|
|
|
|
|
22
|
$subscr = $token; |
|
61
|
26
|
|
|
|
|
32
|
next; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
last if !( |
|
65
|
17
|
100
|
66
|
|
|
181
|
$token->isa("PPI::Token::Cast") || |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$token->isa("PPI::Token::Symbol") || |
|
67
|
|
|
|
|
|
|
$token->isa("PPI::Structure::Block") || |
|
68
|
|
|
|
|
|
|
( $token->isa("PPI::Token::Operator") && $token->content eq '->' ) |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
21
|
|
|
|
|
31
|
return $subscr; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 NAME |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Perl::Critic::Policy::BuiltinFunctions::ProhibitDeleteOnArrays - Do not use |
|
88
|
|
|
|
|
|
|
C<delete> on arrays. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Calling delete on array values is strongly discouraged. See |
|
93
|
|
|
|
|
|
|
L<http://perldoc.perl.org/functions/delete.html>. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Aleksey Korabelshchikov L<mailto:xliosha@gmail.com> |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
|
104
|
|
|
|
|
|
|
|