« lib/Perl/Critic/Policy/ControlStructures/ProhibitDeepNests.pm
↑ Summary
lib/Perl/Critic/Policy/Modules/RequireEndWithOne.pm »
| 1 | package Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators; | ||||||||||
| 2 | |||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 40 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 40 | our $VERSION = '1.156'; | |||||||||
| 12 | |||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||
| 14 | |||||||||||
| 15 | 40 | Readonly::Scalar my $DESC => q{Long number not separated with underscores}; | |||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => [ 59 ]; | |||||||||
| 17 | |||||||||||
| 18 | #----------------------------------------------------------------------------- | ||||||||||
| 19 | |||||||||||
| 20 | 40 | Readonly::Scalar my $MINIMUM_INTEGER_WITH_MULTIPLE_DIGITS => 10; | |||||||||
| 21 | |||||||||||
| 22 | 91 | ▶ | sub supported_parameters { | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 23 | return ( | ||||||||||
| 24 | { | ||||||||||
| 25 | 91 | name => 'min_value', | |||||||||
| 26 | description => 'The minimum absolute value to require separators in.', | ||||||||||
| 27 | default_string => '10_000', | ||||||||||
| 28 | behavior => 'integer', | ||||||||||
| 29 | integer_minimum => $MINIMUM_INTEGER_WITH_MULTIPLE_DIGITS, | ||||||||||
| 30 | }, | ||||||||||
| 31 | ); | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 88 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | 83 | ▶ | sub default_themes { return qw( core pbp cosmetic ) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | 31 | ▶ | sub applies_to { return 'PPI::Token::Number' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | #----------------------------------------------------------------------------- | ||||||||||
| 39 | |||||||||||
| 40 | 78 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||
| 41 | 78 | my ( $self, $elem, undef ) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 78 | ▶ | return if $elem->isa( 'PPI::Token::Number::Version' ); # GitHub #856 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | |||||||||||
| 45 | 78 | my $min = $self->{_min_value}; | |||||||||
| 46 | |||||||||||
| 47 | 78 | ▶ | return if $elem !~ m{ \d{4} }xms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 14 | ▶ | return if abs $elem->literal() < $min; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | 14 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 40 | 1; | |||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||