line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JMAP::Validation::Tests::String; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
67
|
use strict; |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
235
|
|
4
|
11
|
|
|
11
|
|
30
|
use warnings; |
|
11
|
|
|
|
|
12
|
|
|
11
|
|
|
|
|
182
|
|
5
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
732
|
use DateTime; |
|
11
|
|
|
|
|
77039
|
|
|
11
|
|
|
|
|
157
|
|
7
|
11
|
|
|
11
|
|
4928
|
use Encode; |
|
11
|
|
|
|
|
75681
|
|
|
11
|
|
|
|
|
660
|
|
8
|
11
|
|
|
11
|
|
3316
|
use JMAP::Validation::Tests::Array; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
2920
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# data types {{{ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_string { |
13
|
63399336
|
|
|
63399336
|
0
|
40764449
|
my ($value) = @_; |
14
|
|
|
|
|
|
|
|
15
|
63399336
|
|
50
|
|
|
153824262
|
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
|
306866
|
my ($value) = @_; |
24
|
|
|
|
|
|
|
|
25
|
471206
|
|
|
|
|
602072
|
return length($value) >= 1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub has_at_most_256_bytes { |
29
|
471206
|
|
|
471206
|
0
|
2159828
|
my ($value) = @_; |
30
|
|
|
|
|
|
|
|
31
|
471206
|
|
|
|
|
683290
|
return length(Encode::encode_utf8($value)) <= 256; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub has_no_leading_hash { |
35
|
471202
|
|
|
471202
|
0
|
3134692
|
my ($value) = @_; |
36
|
|
|
|
|
|
|
|
37
|
471202
|
|
|
|
|
532975
|
return $value !~ /^#/; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub is_id { |
41
|
471202
|
|
|
471202
|
0
|
310449
|
my ($value) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return |
44
|
471202
|
|
33
|
|
|
445345
|
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
|
|
|
|
8
|
return unless JMAP::Validation::Tests::Array::is_array($value); |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
2
|
foreach my $id (@{$value}) { |
|
4
|
|
|
|
|
6
|
|
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
|
359464
|
my ($value) = @_; |
64
|
|
|
|
|
|
|
|
65
|
497664
|
|
|
|
|
447143
|
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; |