lib/Perl/Critic/Policy/Objects/ProhibitIndirectSyntax.pm

filter: Statementstmt 80.5% 29 / 36 Branchbran 8.3% 1 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 54.8% 45 / 82 CC 11 SCAR 39.9
CC
11
Cov
50%
violates
101.9
BEGIN
1.0
BEGIN
1.0
CRAP 53.9
« lib/Perl/Critic/Policy/Subroutines/RequireFinalReturn.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitBooleanGrep.pm »
1 package Perl::Critic::Policy::Objects::ProhibitIndirectSyntax;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Perl::Critic::Utils qw{ :severities :classification };
Subroutine BEGIN: called CC=1 SCAR=0.0
8 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Hash my %COMMA => {
17 q<,> => 1,
18 q{=>} => 1,
19 };
20 40 Readonly::Scalar my $DOLLAR => q<$>;
21  
22 40 Readonly::Scalar my $DESC => 'Subroutine "%s" called using indirect syntax';
23 40 Readonly::Scalar my $EXPL => [ 349 ];
24  
25 #-----------------------------------------------------------------------------
26  
27 91 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
28 return (
29 {
30 91 name => 'forbid',
31 description => 'Indirect method syntax is forbidden for these methods.',
32 behavior => 'string list',
33 list_always_present_values => [ qw{ new } ],
34 }
35 );
36 }
37  
38 74 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
39 85 ▶sub default_themes { return qw( core pbp maintenance certrule ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
40 33 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
41  
42 #-----------------------------------------------------------------------------
43  
44 349 ▶sub violates {
Subroutine violates: called CC=11 SCAR=46.2
Pod documented
45 349 my ( $self, $elem, undef ) = @_;
46  
47 # We are only interested in the functions we have been told to check.
48 # Do this before calling is_function_call() because we want to weed
49 # out as many candidate tokens as possible before calling it.
50 349 ▶ return if not $self->{_forbid}->{$elem->content()};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_forbid"}{$elem->content} 349 0 349
51  
52 # Make sure it really is a function call.
53 0 ▶ return if not is_function_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($elem) 0 0 0
54  
55 # Per perlobj, it is only an indirect object call if the next sibling
56 # is a word, a scalar symbol, or a block.
57 0 ▶ my $object = $elem->snext_sibling() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $object = $elem->snext_sibling or return 0 0 0
58 return if not (
59 0 ▶ $object->isa( 'PPI::Token::Word' )
Branch: 1 branch
BranchTrueFalseTotal
unless $object->isa("PPI::Token::Word") or $object->isa("PPI::Token::Symbol") and $DOLLAR eq $object->raw_type or $object->isa("PPI::Structure::Block") 0 0 0
Condition0%0/9
$object->isa("PPI::Token::Word") or $object->isa("PPI::Token::Symbol") and $DOLLAR eq $object->raw_type or $object->isa("PPI::Structure::Block")
l!l&&r!l&&!r
000
$object->isa("PPI::Token::Word") or $object->isa("PPI::Token::Symbol") and $DOLLAR eq $object->raw_type
l!l&&r!l&&!r
000
$object->isa("PPI::Token::Symbol") and $DOLLAR eq $object->raw_type
!ll&&!rl&&r
000
MC/DC0%0/4
$object->isa("PPI::Token::Word") or $object->isa("PPI::Token::Symbol") and $DOLLAR eq $object->raw_type or $object->isa("PPI::Structure::Block")
$object->isa("PPI::Token::Word") $object->isa("PPI::Token::Symbol") $DOLLAR eq $object->raw_type $object->isa("PPI::Structure::Block")
Truth table0%0/6
A or B and C or D
A= $object->isa("PPI::Token::Word")B= $object->isa("PPI::Token::Symbol")C= $DOLLAR eq $object->raw_typeD= $object->isa("PPI::Structure::Block")
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
60 or $object->isa( 'PPI::Token::Symbol' )
61 and $DOLLAR eq $object->raw_type()
62 or $object->isa( 'PPI::Structure::Block' )
63 );
64  
65 # Per perlobj, it is not an indirect object call if the operator after
66 # the possible indirect object is a comma.
67 0 ▶ if ( my $operator = $object->snext_sibling() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $operator = $object->snext_sibling) 0 0 0
68 return if
69 $operator->isa( 'PPI::Token::Operator' )
70 0 ▶ and $COMMA{ $operator->content() };
Branch: 1 branch
BranchTrueFalseTotal
if $operator->isa("PPI::Token::Operator") and $COMMA{$operator->content} 0 0 0
Condition0%0/3
$operator->isa("PPI::Token::Operator") and $COMMA{$operator->content}
!ll&&!rl&&r
000
MC/DC0%0/2
$operator->isa("PPI::Token::Operator") and $COMMA{$operator->content}
$operator->isa("PPI::Token::Operator") $COMMA{$operator->content}
Truth table0%0/3
A and B
A= $operator->isa("PPI::Token::Operator")B= $COMMA{$operator->content}
ABresult
0X0
100
111
71 }
72  
73 0 my $message = sprintf $DESC, $elem->content();
74  
75 0 return $self->violation( $message, $EXPL, $elem );
76 }
77  
78 40 1;
79  
80 __END__
« lib/Perl/Critic/Policy/Subroutines/RequireFinalReturn.pm ↑ Summary lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitBooleanGrep.pm »