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