« Policy/ControlStructures/ProhibitMultipleSubscripts.pm
↑ Summary
Policy/ValuesAndExpressions/ProhibitListsInMultiConstants.pm »
| 1 | package Perl::Critic::Policy::CodeLayout::RequireKRParens; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use parent qw[ Perl::Critic::Policy ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Perl::Critic::Utils qw[ :severities :classification ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use constant PBP_PAGE => 9; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub default_themes { return qw[ cosmetic pbp ] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | sub applies_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | return qw[ | |||||||||||||||||||||||||||||||||||||||||
| 14 | PPI::Token::Word | ||||||||||||||||||||||||||||||||||||||||||
| 15 | PPI::Structure::Condition | ||||||||||||||||||||||||||||||||||||||||||
| 16 | PPI::Statement::Compound | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 37 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 37 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 37 | ▶ | goto &_violates_subroutine if $elem->isa('PPI::Token::Word'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | ▶ | goto &_violates_condition if $elem->isa('PPI::Structure::Condition'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | goto &_violates_compound; # PPI::Statement::Compound | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | sub _violates_condition { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_violates_condition: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | my @violations; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | my $prev = $elem->previous_sibling; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | ▶ | if (ref $prev and not $prev->isa('PPI::Token::Whitespace')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $prev and not $prev->isa("PPI::Token::Whitespace")
MC/DC50%1/2
ref $prev and not $prev->isa("PPI::Token::Whitespace")
ref $prev
not $prev->isa("PPI::Token::Whitespace")
Truth table66%2/3
A and not(B)
A= ref $prevB= not $prev->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | push @violations, | |||||||||||||||||||||||||||||||||||||||||
| 35 | $self->violation('No whitespace before opening condition parenthesis', PBP_PAGE, $elem); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | my $next = $elem->next_sibling; # end of statement means it's a trailing condition | |||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | if (ref $next and not $next->isa('PPI::Token::Whitespace') and not _is_end_of_statement($next)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $next and not $next->isa("PPI::Token::Whitespace") and not _is_end_of_statement($next)
ref $next and not $next->isa("PPI::Token::Whitespace")
MC/DC66%2/3
ref $next and not $next->isa("PPI::Token::Whitespace") and not _is_end_of_statement($next)
ref $next
not $next->isa("PPI::Token::Whitespace")
not _is_end_of_statement($next)
Truth table75%3/4
A and not(B) and not(C)
A= ref $nextB= not $next->isa("PPI::Token::Whitespace")C= not _is_end_of_statement($next)
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | push @violations, | |||||||||||||||||||||||||||||||||||||||||
| 41 | $self->violation('No whitespace after closing condition parenthesis', PBP_PAGE, $elem); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | return @violations; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 27 | ▶ | sub _violates_subroutine { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_violates_subroutine: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 27 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 27 | ▶ | return if is_perl_builtin($elem); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 24 | ▶ | return if not is_function_call($elem) and not is_method_call($elem); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_function_call($elem) or is_method_call($elem)
MC/DC100%2/2
is_function_call($elem) or is_method_call($elem)
is_function_call($elem)
is_method_call($elem)
Truth table100%3/3
A or B
A= is_function_call($elem)B= is_method_call($elem)
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # Check for calls with no parentheses | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 12 | my $parens = $elem->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 12 | ▶ | return if ref $parens and not $parens->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $parens and not $parens->isa("PPI::Structure::List")
MC/DC50%1/2
ref $parens and not $parens->isa("PPI::Structure::List")
ref $parens
not $parens->isa("PPI::Structure::List")
Truth table66%2/3
A and not(B)
A= ref $parensB= not $parens->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 11 | my $next_sib = $elem->next_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 11 | ▶ | if (ref $next_sib and $next_sib->isa('PPI::Token::Whitespace')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $next_sib and $next_sib->isa("PPI::Token::Whitespace")
MC/DC50%1/2
ref $next_sib and $next_sib->isa("PPI::Token::Whitespace")
ref $next_sib
$next_sib->isa("PPI::Token::Whitespace")
Truth table66%2/3
A and B
A= ref $next_sibB= $next_sib->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | return $self->violation('Whitespace between subroutine name and its opening parenthesis', | |||||||||||||||||||||||||||||||||||||||||
| 59 | PBP_PAGE, $elem); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | ▶ | sub _violates_compound { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_violates_compound: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | my $type = $elem->type; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | ▶ | my $parens = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | $type eq 'foreach' ? $elem->find_first('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||
| 71 | : $type eq 'for' ? $elem->find_first('PPI::Structure::For') | ||||||||||||||||||||||||||||||||||||||||||
| 72 | : return; # if and while are handled in _violates_condition() | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | my @violations; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | my $prev = $parens->previous_sibling; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | if (ref $prev and not $prev->isa('PPI::Token::Whitespace')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $prev and not $prev->isa("PPI::Token::Whitespace")
MC/DC0%0/2
ref $prev and not $prev->isa("PPI::Token::Whitespace")
ref $prev
not $prev->isa("PPI::Token::Whitespace")
Truth table33%1/3
A and not(B)
A= ref $prevB= not $prev->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | push @violations, | |||||||||||||||||||||||||||||||||||||||||
| 78 | $self->violation("No whitespace before opening $type parenthesis", PBP_PAGE, $parens); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | my $next = $parens->next_sibling; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | if (ref $next and not $next->isa('PPI::Token::Whitespace')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $next and not $next->isa("PPI::Token::Whitespace")
MC/DC50%1/2
ref $next and not $next->isa("PPI::Token::Whitespace")
ref $next
not $next->isa("PPI::Token::Whitespace")
Truth table66%2/3
A and not(B)
A= ref $nextB= not $next->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | push @violations, | |||||||||||||||||||||||||||||||||||||||||
| 84 | $self->violation("No whitespace after closing $type parenthesis", PBP_PAGE, $parens); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | return @violations; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | sub _is_end_of_statement { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_end_of_statement: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | return if not ref $elem; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | return if not $elem->isa('PPI::Token::Structure'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | return ($elem eq '}' or $elem eq ';'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$elem eq '}' || $elem eq ';'
MC/DC0%0/2
$elem eq '}' || $elem eq ';'
$elem eq '}'
$elem eq ';'
Truth table33%1/3
A || B
A= $elem eq '}'B= $elem eq ';'
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||||||||||||||||