Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / ValuesAndExpressions / RequireNumberSeparators.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireNumberSeparators.pm $
3 #     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{Long number not separated with underscores};
23 Readonly::Scalar my $EXPL => [ 59 ];
24
25 #-----------------------------------------------------------------------------
26
27 Readonly::Scalar my $MINIMUM_INTEGER_WITH_MULTIPLE_DIGITS => 10;
28
29 sub supported_parameters {
30     return (
31         {
32             name            => 'min_value',
33             description     => 'The minimum absolute value to require separators in.',
34             default_string  => '10_000',
35             behavior        => 'integer',
36             integer_minimum => $MINIMUM_INTEGER_WITH_MULTIPLE_DIGITS,
37         },
38     );
39 }
40
41 sub default_severity  { return $SEVERITY_LOW           }
42 sub default_themes    { return qw( core pbp cosmetic ) }
43 sub applies_to        { return 'PPI::Token::Number'    }
44
45 #-----------------------------------------------------------------------------
46
47 sub violates {
48     my ( $self, $elem, undef ) = @_;
49     my $min = $self->{_min_value};
50
51     return if $elem !~ m{ \d{4} }mx;
52     return if abs $elem->literal() < $min;
53
54     return $self->violation( $DESC, $EXPL, $elem );
55 }
56
57 1;
58
59 __END__
60
61 #-----------------------------------------------------------------------------
62
63 =pod
64
65 =head1 NAME
66
67 Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators - Write C< 141_234_397.0145 > instead of C< 141234397.0145 >.
68
69 =head1 AFFILIATION
70
71 This Policy is part of the core L<Perl::Critic> distribution.
72
73
74 =head1 DESCRIPTION
75
76 Long numbers can be difficult to read.  To improve legibility, Perl
77 allows numbers to be split into groups of digits separated by
78 underscores.  This policy requires number sequences of more than
79 three digits to be separated.
80
81  $long_int = 123456789;   #not ok
82  $long_int = 123_456_789; #ok
83
84  $long_float = 12345678.001;   #not ok
85  $long_float = 12_345_678.001; #ok
86
87 =head1 CONFIGURATION
88
89 The minimum absolute value of numbers that must contain separators can
90 be configured via the C<min_value> option.  The default is 10,000;
91 thus, all numbers >= 10,000 and <= -10,000 must have separators.  For
92 example:
93
94   [ValuesAndExpressions::RequireNumberSeparators]
95   min_value = 100000    # That's one-hundred-thousand!
96
97 =head1 NOTES
98
99 As it is currently written, this policy only works properly with
100 decimal (base 10) numbers.  And it is obviously biased toward Western
101 notation.  I'll try and address those issues in the future.
102
103 =head1 AUTHOR
104
105 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
106
107 =head1 COPYRIGHT
108
109 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
110
111 This program is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself.  The full text of this license
113 can be found in the LICENSE file included with this module.
114
115 =cut
116
117 # Local Variables:
118 #   mode: cperl
119 #   cperl-indent-level: 4
120 #   fill-column: 78
121 #   indent-tabs-mode: nil
122 #   c-indentation-style: bsd
123 # End:
124 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :