line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JMAP::Validation::Tests::String; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
71
|
use strict; |
|
11
|
|
|
|
|
13
|
|
|
11
|
|
|
|
|
276
|
|
4
|
11
|
|
|
11
|
|
36
|
use warnings; |
|
11
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
207
|
|
5
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
714
|
use DateTime; |
|
11
|
|
|
|
|
70987
|
|
|
11
|
|
|
|
|
223
|
|
7
|
11
|
|
|
11
|
|
5053
|
use Encode; |
|
11
|
|
|
|
|
79082
|
|
|
11
|
|
|
|
|
694
|
|
8
|
11
|
|
|
11
|
|
3665
|
use JMAP::Validation::Tests::Array; |
|
11
|
|
|
|
|
38
|
|
|
11
|
|
|
|
|
3003
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# data types {{{ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_string { |
13
|
63399336
|
|
|
63399336
|
0
|
40290597
|
my ($value) = @_; |
14
|
|
|
|
|
|
|
|
15
|
63399336
|
|
50
|
|
|
153319475
|
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
|
301503
|
my ($value) = @_; |
24
|
|
|
|
|
|
|
|
25
|
471206
|
|
|
|
|
567873
|
return length($value) >= 1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub has_at_most_256_bytes { |
29
|
471206
|
|
|
471206
|
0
|
2093079
|
my ($value) = @_; |
30
|
|
|
|
|
|
|
|
31
|
471206
|
|
|
|
|
585935
|
return length(Encode::encode_utf8($value)) <= 256; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub has_no_leading_hash { |
35
|
471202
|
|
|
471202
|
0
|
3162651
|
my ($value) = @_; |
36
|
|
|
|
|
|
|
|
37
|
471202
|
|
|
|
|
531476
|
return $value !~ /^#/; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub is_id { |
41
|
471202
|
|
|
471202
|
0
|
311428
|
my ($value) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return |
44
|
471202
|
|
33
|
|
|
442389
|
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
|
4
|
my ($value) = @_; |
52
|
|
|
|
|
|
|
|
53
|
4
|
50
|
|
|
|
9
|
return unless JMAP::Validation::Tests::Array::is_array($value); |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
4
|
foreach my $id (@{$value}) { |
|
4
|
|
|
|
|
7
|
|
56
|
4
|
50
|
|
|
|
13
|
return unless is_id($id); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
16
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub is_date { |
63
|
497664
|
|
|
497664
|
0
|
354802
|
my ($value) = @_; |
64
|
|
|
|
|
|
|
|
65
|
497664
|
|
|
|
|
454875
|
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; |