Perl/Lint/Policy/ValuesAndExpressions/RequireNumberSeparators.pm

filter: Statementstmt 82.5% 33 / 40 Branchbran 58.3% 7 / 12 Conditioncond 37.5% 3 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 69.4% 50 / 72 CC 11 SCAR 25.4
CC
11
Cov
72%
evaluate
18.0
BEGIN
1.0
BEGIN
1.0
CRAP 12.7
« Perl/Lint.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/RequireUpperCaseHeredocTerminator.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::RequireNumberSeparators;
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 => 'Long number not separated with underscores',
9 EXPL => [59],
10 3 };
11  
12 2 ▶sub evaluate {
Subroutine evaluate: called CC=11 SCAR=28.9
Pod undocumented
13 2 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 2 my $min_value = 100_000;
16 2 ▶ if (my $this_policies_arg = $args->{require_number_separators}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"require_number_separators"}) 0 2 2
17 0 ▶ $min_value = $this_policies_arg->{min_value} || $min_value;
Condition0%0/3
$this_policies_arg->{'min_value'} || $min_value
l!l&&r!l&&!r
000
MC/DC0%0/2
$this_policies_arg->{'min_value'} || $min_value
$this_policies_arg->{'min_value'} $min_value
Truth table0%0/3
A || B
A= $this_policies_arg->{'min_value'}B= $min_value
ABresult
1X1
011
000
18 }
19  
20 2 my @violations;
21 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
22 51 my $token_type = $token->{type};
23  
24 51 ▶ if ($token_type == INT || $token_type == DOUBLE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 170 or $token_type == 171) 2 49 51
Condition66%2/3
$token_type == 170 or $token_type == 171
l!l&&r!l&&!r
2049
MC/DC50%1/2
$token_type == 170 or $token_type == 171
$token_type == 170 $token_type == 171
Truth table66%2/3
A or B
A= $token_type == 170B= $token_type == 171
ABresult
1X1
011
000
25 2 (my $num = $token->{data}) =~ s/\A[+-]//;
26  
27 2 my ($decimal_part, $fractional_part) = split /\./, $num;
28 2 my @decimals = split /_/, $decimal_part;
29 2 my @fractionals = ();
30  
31 2 my $joined;
32 2 ▶ if (defined $fractional_part) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fractional_part) { } 0 2 2
33 0 @fractionals = split /_/, $fractional_part;
34 0 $joined = join('', @decimals) . '.' . join('', @fractionals);
35 } else {
36 2 $joined = join '', @decimals;
37 }
38  
39 2 ▶ if ((eval($joined) // -$min_value - 1) < $min_value) { ## no critic
Branch: 1 branch
BranchTrueFalseTotal
if ((eval $joined // -$min_value - 1) < $min_value) 2 0 2
Condition50%1/2
eval $joined // -$min_value - 1
l!l
20
MC/DC0%0/1
eval $joined // -$min_value - 1
eval $joined
Truth table50%1/2
A
A= eval $joined
Aresult
11
00
40 # ~~~~~~~~~~~~~~~ If reach here, $joined is not a number
41 2 next;
42 }
43  
44 0 for my $part (@decimals, @fractionals) {
45 0 ▶ if (eval($part) >= 1000) { ## no critic
Branch: 1 branch
BranchTrueFalseTotal
if (eval $part >= 1000) 0 0 0
46 push @violations, {
47 filename => $file,
48 line => $token->{line},
49 0 description => DESC,
50 explanation => EXPL,
51 policy => __PACKAGE__,
52 };
53 0 last;
54 }
55 }
56 }
57 }
58  
59 2 return \@violations;
60 }
61  
62 3 1;
63  
« Perl/Lint.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/RequireUpperCaseHeredocTerminator.pm »