| 1 | package Perl::Critic::Policy::CodeLayout::RequireBreakBeforeOperator; | ||||||||||
| 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 :booleans ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use constant OPERATORS => qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | ++ -- ** ! ~ + - | ||||||||||
| 9 | =~ !~ * / % x | ||||||||||
| 10 | << >> lt gt le ge cmp ~~ | ||||||||||
| 11 | == != <=> . .. ... | ||||||||||
| 12 | & | ^ && || // | ||||||||||
| 13 | ? : **= += -= .= *= /= | ||||||||||
| 14 | %= x= &= |= ^= <<= >>= &&= | ||||||||||
| 15 | ||= //= < > <= >= <> => -> | ||||||||||
| 16 | and or xor not eq ne | ||||||||||
| 17 | 2 | ); | |||||||||
| 18 | 2 | ▶ | use constant PBP_PAGE => 28; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 3 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 0 | ▶ | sub default_themes { return qw[ cosmetic pbp ] } | ||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 22 | 3 | ▶ | sub applies_to { return 'PPI::Token::Operator' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 23 | |||||||||||
| 24 | 3 | ▶ | sub supported_parameters { | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 25 | return ( | ||||||||||
| 26 | { | ||||||||||
| 27 | 3 | name => 'exclude', | |||||||||
| 28 | description => 'Exempt operators.', | ||||||||||
| 29 | behavior => 'enumeration', | ||||||||||
| 30 | enumeration_values => [OPERATORS], | ||||||||||
| 31 | enumeration_allow_multiple_values => 1, | ||||||||||
| 32 | default_string => '', | ||||||||||
| 33 | }, | ||||||||||
| 34 | ); | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 3 | ▶ | sub initialize_if_enabled { | ||||||||
|
Subroutine
initialize_if_enabled: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | 3 | my ($self, $config) = @_; | |||||||||
| 39 | |||||||||||
| 40 | 3 | $self->{_ops_to_check} = { map { $_ => 1 } grep { not $self->{_exclude}{$_} } OPERATORS }; | |||||||||
| 41 | |||||||||||
| 42 | 3 | return $TRUE; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 19 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||
| 46 | 19 | my ($self, $elem, $doc) = @_; | |||||||||
| 47 | 19 | ▶ | return if not $self->{_ops_to_check}{$elem}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 14 | my $whitespace = $elem->next_sibling(); | |||||||||
| 50 | 14 | ▶ | return if not ref $whitespace; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 14 | ▶ | return if not $whitespace->isa('PPI::Token::Whitespace'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 14 | ▶ | if (index($whitespace->content, "\n") != -1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 3 | return $self->violation('Expression broken after operator', PBP_PAGE, $elem); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 11 | return; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 2 | 1; | |||||||||
| 61 | __END__ | ||||||||||