line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Validator::Custom::CheckFunction; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
138
|
|
4
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
141
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
28
|
use Carp 'croak'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
2490
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub ascii_graphic { |
9
|
4
|
|
|
4
|
0
|
7
|
my ($vc, $value, $arg) = @_; |
10
|
|
|
|
|
|
|
|
11
|
4
|
100
|
|
|
|
13
|
return undef unless defined $value; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
|
|
9
|
my $is_valid = $value =~ /^[\x21-\x7E]+$/; |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
9
|
return $is_valid; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub number { |
19
|
26
|
|
|
26
|
0
|
36
|
my ($vc, $value, $arg) = @_; |
20
|
|
|
|
|
|
|
|
21
|
26
|
100
|
|
|
|
57
|
return undef unless defined $value; |
22
|
|
|
|
|
|
|
|
23
|
24
|
|
|
|
|
27
|
my $decimal_part_max; |
24
|
24
|
100
|
|
|
|
52
|
if ($arg) { |
25
|
13
|
50
|
|
|
|
29
|
croak "The argument of number checking function must be a hash reference" |
26
|
|
|
|
|
|
|
unless ref $arg eq 'HASH'; |
27
|
|
|
|
|
|
|
|
28
|
13
|
|
|
|
|
21
|
$decimal_part_max = delete $arg->{decimal_part_max}; |
29
|
|
|
|
|
|
|
|
30
|
13
|
50
|
|
|
|
26
|
croak "decimal_part_max must be more than 0" |
31
|
|
|
|
|
|
|
unless $decimal_part_max > 0; |
32
|
|
|
|
|
|
|
|
33
|
13
|
50
|
|
|
|
36
|
croak "The argument of number checking function allow only decimal_part_max" |
34
|
|
|
|
|
|
|
if keys %$arg; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
24
|
100
|
|
|
|
41
|
if (defined $decimal_part_max) { |
38
|
13
|
100
|
|
|
|
102
|
if ($value =~ /^-?[0-9]+(\.[0-9]{0,$decimal_part_max})?$/) { |
39
|
7
|
|
|
|
|
23
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
6
|
|
|
|
|
19
|
return undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
11
|
100
|
|
|
|
36
|
if ($value =~ /^-?[0-9]+(\.[0-9]*)?$/) { |
47
|
7
|
|
|
|
|
19
|
return 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
4
|
|
|
|
|
11
|
return undef; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub int { |
56
|
9
|
|
|
9
|
0
|
14
|
my ($vc, $value, $arg) = @_; |
57
|
|
|
|
|
|
|
|
58
|
9
|
100
|
|
|
|
19
|
return undef unless defined $value; |
59
|
|
|
|
|
|
|
|
60
|
8
|
|
|
|
|
32
|
my $is_valid = $value =~ /^\-?[0-9]+$/; |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
23
|
return $is_valid; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub in { |
66
|
3
|
|
|
3
|
0
|
5
|
my ($vc, $value, $arg) = @_; |
67
|
|
|
|
|
|
|
|
68
|
3
|
100
|
|
|
|
57
|
return undef unless defined $value; |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
4
|
my $valid_values = $arg; |
71
|
|
|
|
|
|
|
|
72
|
2
|
50
|
|
|
|
8
|
croak "\"in\" check argument must be array reference" |
73
|
|
|
|
|
|
|
unless ref $valid_values eq 'ARRAY'; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
4
|
my $match = grep { $_ eq $value } @$valid_values; |
|
4
|
|
|
|
|
10
|
|
76
|
2
|
100
|
|
|
|
9
|
return $match > 0 ? 1 : 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Validator::Custom::CheckFunction - Checking functions |