line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Decimal Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Decimal; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
44273
|
use strict; |
|
109
|
|
|
|
|
274
|
|
|
109
|
|
|
|
|
2611
|
|
6
|
109
|
|
|
109
|
|
483
|
use warnings; |
|
109
|
|
|
|
|
199
|
|
|
109
|
|
|
|
|
2357
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
477
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
203
|
|
|
109
|
|
|
|
|
9151
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
639
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
219
|
|
|
109
|
|
|
|
|
620
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900058'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 1; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 0; |
18
|
|
|
|
|
|
|
has 'message' => '%s requires a valid decimal number'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub validate { |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
0
|
10
|
my ($self, $proto, $field, $param) = @_; |
23
|
|
|
|
|
|
|
|
24
|
4
|
50
|
33
|
|
|
15
|
if (defined $field->{decimal} && defined $param) { |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# checks for a valid decimal. Both the sign and exponent are optional |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# 0 => Any number of decimal places, including none |
29
|
|
|
|
|
|
|
# 1 => Any number of decimal places greater than 0, or a float|double |
30
|
|
|
|
|
|
|
# 2 => Exactly that many number of decimal places |
31
|
|
|
|
|
|
|
|
32
|
4
|
50
|
33
|
|
|
16
|
if ($field->{required} || $param) { |
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
7
|
my $type = $field->{decimal}; |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
6
|
my $lnum = '[0-9]+'; |
37
|
4
|
|
|
|
|
9
|
my $dnum = "[0-9]*[\.]${lnum}"; |
38
|
4
|
|
|
|
|
5
|
my $sign = '[+-]?'; |
39
|
4
|
|
|
|
|
9
|
my $exp = "(?:[eE]${sign}${lnum})?"; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
6
|
my $dre; |
42
|
|
|
|
|
|
|
|
43
|
4
|
50
|
|
|
|
19
|
if ($type == 0) { |
|
|
50
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
$dre = qr/^${sign}(?:${lnum}|${dnum})${exp}$/; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
elsif ($type == 1) { |
48
|
4
|
|
|
|
|
56
|
$dre = qr/^${sign}${dnum}${exp}$/; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
else { |
52
|
0
|
|
|
|
|
0
|
$type = "[0-9]\{${type}}"; |
53
|
0
|
|
|
|
|
0
|
$dnum = "(?:[0-9]*[\.]${type}|${lnum}[\.]${type})"; |
54
|
0
|
|
|
|
|
0
|
$dre = qr/^${sign}${dnum}${exp}$/; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
4
|
100
|
|
|
|
37
|
$self->error($proto, $field) unless $param =~ $dre; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
11
|
return $self; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |