File Coverage

blib/lib/Perl/Critic/Policy/Operators/ProhibitSmartmatch.pm
Criterion Covered Total %
statement 23 24 95.8
branch 1 2 50.0
condition n/a
subroutine 10 11 90.9
pod 4 5 80.0
total 38 42 90.4


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Operators::ProhibitSmartmatch;
2              
3 2     2   864 use 5.008005;
  2         6  
4 2     2   11 use strict;
  2         4  
  2         39  
5 2     2   8 use warnings;
  2         4  
  2         49  
6              
7 2     2   9 use parent 'Perl::Critic::Policy';
  2         3  
  2         15  
8 2     2   48704 use Readonly;
  2         6  
  2         78  
9 2     2   12 use Perl::Critic::Utils qw{ :severities };
  2         4  
  2         84  
10              
11             our $VERSION = '0.01';
12              
13             Readonly::Scalar my $DESC => q{Smartmatch operator used};
14             Readonly::Scalar my $EXPL => q{Avoid using smartmatch operator};
15              
16             sub supported_parameters {
17 1     1 0 10161 return ();
18             }
19              
20             sub default_severity {
21 1     1 1 17 return $SEVERITY_MEDIUM;
22             }
23              
24             sub default_themes {
25 0     0 1 0 return qw( core );
26             }
27              
28             sub applies_to {
29 1     1 1 8656 return 'PPI::Token::Operator';
30             }
31              
32             sub violates {
33 1     1 1 22 my ( $self, $elem ) = @_;
34 1 50       5 return if $elem ne '~~';
35 1         26 return $self->violation( $DESC, $EXPL, $elem );
36             }
37              
38             1;
39              
40             __END__
41              
42             =encoding utf-8
43              
44             =head1 NAME
45              
46             Perl::Critic::Policy::Operators::ProhibitSmartmatch
47             - avoid using explicit smartmatching via C<~~> operator
48              
49             =head1 DESCRIPTION
50              
51             Smartmatch operator is considered experimental, see L<perlop/"Smartmatch Operator">.
52              
53             if ($foo ~~ [ $bar ]) {
54             say 'No!';
55             }
56              
57             =head1 AUTHOR
58              
59             Jan Holcapek E<lt>holcapek@gmail.comE<gt>, who was heavily inspired by the work of
60             hisaichi5518 E<lt>hisada.kazuki@gmail.comE<gt>
61              
62             =cut
63