Perl/Lint/Policy/RegularExpressions/RequireBracesForMultiline.pm

filter: Statementstmt 78.1% 25 / 32 Branchbran 50.0% 6 / 12 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 65.5% 40 / 61 CC 10 SCAR 27.3
CC
10
Cov
66%
evaluate
22.5
BEGIN
1.0
BEGIN
1.0
CRAP 15.3
« Perl/Lint/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitLongChainsOfMethodCalls.pm »
1 package Perl::Lint::Policy::RegularExpressions::RequireBracesForMultiline;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 DESC => 'Use "{" and "}" to delimit multi-line regexps',
9 EXPL => [242],
10 3 };
11  
12 2 ▶sub evaluate {
Subroutine evaluate: called CC=10 SCAR=31.1
Pod undocumented
13 2 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 2 my $brackets_regex = qr/\A\{\Z/;
16 2 ▶ if ($args->{require_braces_for_multiline}->{allow_all_brackets}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"require_braces_for_multiline"}{"allow_all_brackets"}) 0 2 2
17 0 $brackets_regex = qr/\A[\{\(\[\<]\Z/;
18 }
19  
20 2 my @violations;
21 2 ▶ for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
22 51 $token_type = $token->{type};
23  
24 51 ▶ if ($token_type == REG_EXP || $token_type == REG_REPLACE_FROM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 187 or $token_type == 156) 2 49 51
Condition66%2/3
$token_type == 187 or $token_type == 156
l!l&&r!l&&!r
2049
MC/DC50%1/2
$token_type == 187 or $token_type == 156
$token_type == 187 $token_type == 156
Truth table66%2/3
A or B
A= $token_type == 187B= $token_type == 156
ABresult
1X1
011
000
25 2 ▶ if (my @backslashes = $token->{data} =~ /(\\*)\n/g) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@backslashes) = $token->{"data"} =~ /(\\*)\n/g) 0 2 2
26 0 my $reg_delim_token = $tokens->[$i-1];
27 0 ▶ if ($reg_delim_token->{data} !~ $brackets_regex) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($reg_delim_token->{"data"} =~ /$brackets_regex/) 0 0 0
28 0 for my $backslash (@backslashes) {
29 0 ▶ if (!$backslash || length($backslash) % 2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $backslash or length($backslash) % 2 == 0) 0 0 0
Condition0%0/3
not $backslash or length($backslash) % 2 == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not $backslash or length($backslash) % 2 == 0
not $backslash length($backslash) % 2 == 0
Truth table0%0/3
not(A) or B
A= not $backslashB= length($backslash) % 2 == 0
ABresult
1X1
011
000
30 push @violations, {
31 filename => $file,
32 line => $token->{line},
33 0 description => DESC,
34 explanation => EXPL,
35 policy => __PACKAGE__,
36 };
37 0 last;
38 }
39 }
40 }
41 }
42 }
43 }
44  
45 2 return \@violations;
46 }
47  
48 3 1;
49  
« Perl/Lint/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitLongChainsOfMethodCalls.pm »