« 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Make sure it really is a function call. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return if not is_function_call($elem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | return if not ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $object->isa( 'PPI::Token::Word' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
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")
$object->isa("PPI::Token::Word") or $object->isa("PPI::Token::Symbol") and $DOLLAR eq $object->raw_type
$object->isa("PPI::Token::Symbol") and $DOLLAR eq $object->raw_type
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")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | return if | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | $operator->isa( 'PPI::Token::Operator' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | and $COMMA{ $operator->content() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$operator->isa("PPI::Token::Operator") and $COMMA{$operator->content}
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}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||