lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitUselessTopic.pm

filter: Statementstmt 84.2% 48 / 57 Branchbran 45.0% 9 / 20 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 10 / 10 Podpod 80.0% 4 / 5 totaltotal 69.1% 74 / 107 CC 14 SCAR 30.4
CC
14
Cov
70%
violates
33.6
BEGIN
1.0
BEGIN
1.0
CRAP 20.9
« lib/Perl/Critic/Policy/Modules/RequireFilenameMatchesPackage.pm ↑ Summary lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitNoStrict.pm »
1 package Perl::Critic::Policy::BuiltinFunctions::ProhibitUselessTopic;
2  
3 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Perl::Critic::Utils qw{ :severities :classification :ppi hashify };
Subroutine BEGIN: called CC=1 SCAR=0.0
8 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 40 our $VERSION = '1.156';
11  
12 ## no critic ( ValuesAndExpressions::RequireInterpolationOfMetachars )
13 ## The numerous $_ variables make false positives.
14 40 Readonly::Scalar my $DESC => q{Useless use of $_};
15 40 Readonly::Scalar my $EXPL_FILETEST => q{$_ should be omitted when using a filetest operator};
16 40 Readonly::Scalar my $EXPL_FUNCTION => q{$_ should be omitted when calling "%s"};
17 40 Readonly::Scalar my $EXPL_FUNCTION_SPLIT => q{$_ should be omitted when calling "split" with two arguments};
18  
19 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
20 74 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
21 73 ▶sub default_themes { return qw( core ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
22 31 ▶sub applies_to { return 'PPI::Token::Operator', 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
23  
24 40 Readonly::Array my @FILETEST_OPERATORS => qw( -r -w -x -o -R -W -X -O -e -z -s -f -d -l -p -S -b -c -u -g -k -T -B -M -A -C );
25 40 Readonly::Hash my %FILETEST_OPERATORS => hashify( @FILETEST_OPERATORS );
26  
27 40 Readonly::Array my @TOPICAL_FUNCS => qw(
28 abs alarm
29 chomp chop chr chroot cos
30 defined
31 eval exp
32 fc
33 glob
34 hex
35 int
36 lc lcfirst length log lstat
37 mkdir
38 oct ord
39 pos print
40 quotemeta
41 readlink readpipe ref require reverse rmdir
42 say sin split sqrt stat study
43 uc ucfirst unlink unpack
44 );
45 40 Readonly::Hash my %TOPICAL_FUNCS => hashify( @TOPICAL_FUNCS );
46  
47 40 Readonly::Hash my %APPLIES_TO => ( %TOPICAL_FUNCS, %FILETEST_OPERATORS );
48  
49 467 ▶sub violates {
Subroutine violates: called CC=14 SCAR=35.2
Pod documented
50 467 my ( $self, $elem, undef ) = @_;
51  
52 467 ▶ return if not exists $APPLIES_TO{ $elem->content };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $APPLIES_TO{$elem->content} 453 14 467
53  
54 14 my $content = $elem->content;
55  
56 # Are we looking at a filetest?
57 14 ▶ if ( $FILETEST_OPERATORS{ $content } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FILETEST_OPERATORS{$content}) 0 14 14
58 # Is there a $_ following it?
59 0 my $op_node = $elem->snext_sibling;
60 0 ▶ if ( $op_node && $op_node->isa('PPI::Token::Magic') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op_node and $op_node->isa("PPI::Token::Magic")) 0 0 0
Condition0%0/3
$op_node and $op_node->isa("PPI::Token::Magic")
!ll&&!rl&&r
000
MC/DC0%0/2
$op_node and $op_node->isa("PPI::Token::Magic")
$op_node $op_node->isa("PPI::Token::Magic")
Truth table0%0/3
A and B
A= $op_nodeB= $op_node->isa("PPI::Token::Magic")
ABresult
0X0
100
111
61 0 my $op = $op_node->content;
62 0 ▶ if ( $op eq '$_' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$_") 0 0 0
63 0 return $self->violation( $DESC, $EXPL_FILETEST, $elem );
64 }
65 }
66 0 return;
67 }
68  
69 14 ▶ if ( $TOPICAL_FUNCS{ $content } && is_perl_builtin( $elem ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TOPICAL_FUNCS{$content} and is_perl_builtin($elem)) 14 0 14
Condition33%1/3
$TOPICAL_FUNCS{$content} and is_perl_builtin($elem)
!ll&&!rl&&r
0014
MC/DC0%0/2
$TOPICAL_FUNCS{$content} and is_perl_builtin($elem)
$TOPICAL_FUNCS{$content} is_perl_builtin($elem)
Truth table33%1/3
A and B
A= $TOPICAL_FUNCS{$content}B= is_perl_builtin($elem)
ABresult
0X0
100
111
70 14 my $is_split = $content eq 'split';
71  
72 14 my @args = parse_arg_list( $elem );
73  
74 14 my $nth_arg_for_topic;
75 14 ▶ if ( $is_split ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_split) { } 1 13 14
76 1 ▶ return if @args != 2; # Ignore split( /\t/ ) or split( /\t/, $_, 3 )
Branch: 1 branch
BranchTrueFalseTotal
if @args != 2 0 1 1
77 1 $nth_arg_for_topic = 2;
78 }
79 else {
80 13 $nth_arg_for_topic = 1;
81 }
82  
83 14 ▶ if ( @args == $nth_arg_for_topic ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == $nth_arg_for_topic) 14 0 14
84 14 my $topic_arg = $args[ $nth_arg_for_topic - 1 ];
85 14 my @tokens = @{$topic_arg};
86 14 ▶ if ( (@tokens == 1) && ($tokens[0]->content eq '$_') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens == 1 and $tokens[0]->content eq "\$_") 0 14 14
Condition66%2/3
@tokens == 1 and $tokens[0]->content eq "\$_"
!ll&&!rl&&r
3110
MC/DC0%0/2
@tokens == 1 and $tokens[0]->content eq "\$_"
@tokens == 1 $tokens[0]->content eq "\$_"
Truth table66%2/3
A and B
A= @tokens == 1B= $tokens[0]->content eq "\$_"
ABresult
0X0
100
111
87 0 ▶ my $msg = $is_split ? $EXPL_FUNCTION_SPLIT : (sprintf $EXPL_FUNCTION, $content);
Branch: 1 branch
BranchTrueFalseTotal
$is_split ? : 0 0 0
88 0 return $self->violation( $DESC, $msg, $elem );
89 }
90 }
91 14 return;
92 }
93  
94 0 return;
95 }
96  
97  
98 40 1;
99  
100 __END__
« lib/Perl/Critic/Policy/Modules/RequireFilenameMatchesPackage.pm ↑ Summary lib/Perl/Critic/Policy/TestingAndDebugging/ProhibitNoStrict.pm »