Policy/CodeLayout/RequireBreakBeforeOperator.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 83.3% 5 / 6 totaltotal 91.9% 57 / 62 CC 5 SCAR 8.4
CC
5
Cov
93%
violates
5.0
default_themes
2.0
BEGIN
1.0
CRAP 2.3
« Policy/CodeLayout/RequireSpaceAroundBinaryOperators.pm ↑ Summary PolicyBundle/SNEZ.pm »
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
BranchTrueFalseTotal
unless $$self{"_ops_to_check"}{$elem} 5 14 19
48  
49 14 my $whitespace = $elem->next_sibling();
50 14 ▶ return if not ref $whitespace;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $whitespace 0 14 14
51 14 ▶ return if not $whitespace->isa('PPI::Token::Whitespace');
Branch: 1 branch
BranchTrueFalseTotal
unless $whitespace->isa("PPI::Token::Whitespace") 0 14 14
52  
53 14 ▶ if (index($whitespace->content, "\n") != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($whitespace->content, "\n") != -1) 3 11 14
54 3 return $self->violation('Expression broken after operator', PBP_PAGE, $elem);
55 }
56  
57 11 return;
58 }
59  
60 2 1;
61 __END__
« Policy/CodeLayout/RequireSpaceAroundBinaryOperators.pm ↑ Summary PolicyBundle/SNEZ.pm »