line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::ControlStructures::ProhibitSwitchStatements; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1692
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
72
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
70
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
234
|
use parent 'Perl::Critic::Policy'; |
|
3
|
|
|
|
|
220
|
|
|
3
|
|
|
|
|
17
|
|
7
|
3
|
|
|
3
|
|
123548
|
use Perl::Critic::Utils qw{ :severities }; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
157
|
|
8
|
3
|
|
|
3
|
|
300
|
use Readonly; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
544
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Switch statement keywords used}; |
13
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Avoid using switch statement keywords}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub supported_parameters { |
16
|
2
|
|
|
2
|
0
|
12978
|
return (); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub default_severity { |
20
|
6
|
|
|
6
|
1
|
58
|
return $SEVERITY_MEDIUM; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub default_themes { |
24
|
0
|
|
|
0
|
1
|
0
|
return qw( core ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub applies_to { |
28
|
|
|
|
|
|
|
# PPI::Statement and PPI::Structure works for (given|when|default), |
29
|
|
|
|
|
|
|
# yet do not for CORE::(given|when|default) |
30
|
2
|
|
|
2
|
1
|
21595
|
return 'PPI::Token'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub violates { |
34
|
82
|
|
|
82
|
1
|
2053
|
my ( $self, $elem, undef ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
82
|
100
|
|
|
|
143
|
return if $elem !~ m{^(CORE::)?(given|when|default)$}; |
37
|
6
|
|
|
|
|
44
|
return $self->violation( $DESC, $EXPL, $elem ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=encoding utf-8 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Perl::Critic::Policy::ControlStructures::ProhibitSwitchStatements |
49
|
|
|
|
|
|
|
- avoid using switch statement keywords which might imply implicit smartmatching |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Switch statements are considered experimental, see L<perlsyn/"Switch Statements">. |
54
|
|
|
|
|
|
|
This policy aims to avoid using switch statement keywords. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
given ($foo) { |
57
|
|
|
|
|
|
|
when (42) { say 'Heureka!'; } |
58
|
|
|
|
|
|
|
default { die 'Oh!'; } |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 AUTHOR |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Jan Holcapek E<lt>holcapek@gmail.comE<gt> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |