line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JMAP::Validation::Tests::String; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
67
|
use strict; |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
237
|
|
4
|
11
|
|
|
11
|
|
32
|
use warnings; |
|
11
|
|
|
|
|
11
|
|
|
11
|
|
|
|
|
186
|
|
5
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
702
|
use DateTime; |
|
11
|
|
|
|
|
72120
|
|
|
11
|
|
|
|
|
151
|
|
7
|
11
|
|
|
11
|
|
4794
|
use Encode; |
|
11
|
|
|
|
|
75749
|
|
|
11
|
|
|
|
|
643
|
|
8
|
11
|
|
|
11
|
|
3241
|
use JMAP::Validation::Tests::Array; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
2795
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# data types {{{ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_string { |
13
|
63399336
|
|
|
63399336
|
0
|
39766812
|
my ($value) = @_; |
14
|
|
|
|
|
|
|
|
15
|
63399336
|
|
50
|
|
|
151106957
|
return (ref($value) || '') eq 'JSON::Typist::String'; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# }}} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# restrictions {{{ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub has_at_least_one_character { |
23
|
471206
|
|
|
471206
|
0
|
290465
|
my ($value) = @_; |
24
|
|
|
|
|
|
|
|
25
|
471206
|
|
|
|
|
554816
|
return length($value) >= 1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub has_at_most_256_bytes { |
29
|
471206
|
|
|
471206
|
0
|
1982716
|
my ($value) = @_; |
30
|
|
|
|
|
|
|
|
31
|
471206
|
|
|
|
|
641757
|
return length(Encode::encode_utf8($value)) <= 256; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub has_no_leading_hash { |
35
|
471202
|
|
|
471202
|
0
|
3067840
|
my ($value) = @_; |
36
|
|
|
|
|
|
|
|
37
|
471202
|
|
|
|
|
516889
|
return $value !~ /^#/; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub is_id { |
41
|
471202
|
|
|
471202
|
0
|
324497
|
my ($value) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return |
44
|
471202
|
|
33
|
|
|
429915
|
is_string($value) |
45
|
|
|
|
|
|
|
&& has_at_least_one_character($value) |
46
|
|
|
|
|
|
|
&& has_at_most_256_bytes($value) |
47
|
|
|
|
|
|
|
&& has_no_leading_hash($value); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub is_array_of_ids { |
51
|
4
|
|
|
4
|
0
|
5
|
my ($value) = @_; |
52
|
|
|
|
|
|
|
|
53
|
4
|
50
|
|
|
|
13
|
return unless JMAP::Validation::Tests::Array::is_array($value); |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
3
|
foreach my $id (@{$value}) { |
|
4
|
|
|
|
|
5
|
|
56
|
4
|
50
|
|
|
|
13
|
return unless is_id($id); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
17
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub is_date { |
63
|
497664
|
|
|
497664
|
0
|
379160
|
my ($value) = @_; |
64
|
|
|
|
|
|
|
|
65
|
497664
|
|
|
|
|
429733
|
return is_string($value); |
66
|
0
|
0
|
|
|
|
|
return unless $value =~ m{^(\d\d\d\d)-(\d\d)-(\d\d)$}; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
return unless eval { |
69
|
0
|
|
|
|
|
|
DateTime->new( |
70
|
|
|
|
|
|
|
year => $1, |
71
|
|
|
|
|
|
|
month => $2, |
72
|
|
|
|
|
|
|
day => $3, |
73
|
|
|
|
|
|
|
) |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# }}} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |