« 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
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | $min_value = $this_policies_arg->{min_value} || $min_value; | ||||||||||||||||||||||||||
|
Condition0%0/3
$this_policies_arg->{'min_value'} || $min_value
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
| |||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my @violations; | |||||||||||||||||||||||||||
| 21 | 2 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 51 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 51 | ▶ | if ($token_type == INT || $token_type == DOUBLE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token_type == 170 or $token_type == 171
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
eval $joined // -$min_value - 1
MC/DC0%0/1
eval $joined // -$min_value - 1
eval $joined
Truth table50%1/2
A
A= eval $joined
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||