line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::TooMuchCode::ProhibitUnnecessaryScalarKeyword; |
2
|
4
|
|
|
4
|
|
2604
|
use strict; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
123
|
|
3
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
147
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
26
|
use Perl::Critic::Utils; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
82
|
|
6
|
4
|
|
|
4
|
|
3509
|
use parent 'Perl::Critic::Policy'; |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
23
|
|
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { return qw(maintenance) } |
9
|
1
|
|
|
1
|
1
|
13715
|
sub applies_to { return 'PPI::Token::Word' } |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub violates { |
12
|
3
|
|
|
3
|
1
|
44
|
my ( $self, $elem, undef ) = @_; |
13
|
3
|
100
|
|
|
|
10
|
return unless $elem->content eq 'scalar'; |
14
|
1
|
|
|
|
|
26
|
my $e = $elem->snext_sibling; |
15
|
1
|
50
|
33
|
|
|
57
|
return unless $e && $e->isa('PPI::Token::Symbol') && $e->raw_type eq '@'; |
|
|
|
33
|
|
|
|
|
16
|
1
|
|
|
|
|
63
|
$e = $elem->sprevious_sibling; |
17
|
1
|
50
|
33
|
|
|
54
|
return unless $e && $e->isa('PPI::Token::Operator') && $e->content eq '='; |
|
|
|
33
|
|
|
|
|
18
|
1
|
|
|
|
|
19
|
$e = $e->sprevious_sibling; |
19
|
1
|
50
|
33
|
|
|
56
|
return unless $e && $e->isa('PPI::Token::Symbol') && $e->raw_type eq '$'; |
|
|
|
33
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
21
|
return $self->violation('Unnecessary scalar keyword', "Assigning an array to a scalar implies scalar context.", $elem); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
1; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
__END__ |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
TooMuchCode::ProhibitUnnecessaryScalarKeyword - Finds `scalar` in scalar context. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This policy dictates that the use of `scalar` for in statement like this needs to be removed: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $n = scalar @items; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
If the left-hand side of assignment is a single scalar variable, then the assignment is in scalar |
39
|
|
|
|
|
|
|
context. There is no need to add C<scalar> keyword. |