line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSV::Keyword::Draft4::Type; |
2
|
|
|
|
|
|
|
|
3
|
47
|
|
|
47
|
|
21692
|
use strict; |
|
47
|
|
|
|
|
52
|
|
|
47
|
|
|
|
|
1076
|
|
4
|
47
|
|
|
47
|
|
131
|
use warnings; |
|
47
|
|
|
|
|
55
|
|
|
47
|
|
|
|
|
995
|
|
5
|
47
|
|
|
47
|
|
130
|
use parent qw(JSV::Keyword); |
|
47
|
|
|
|
|
48
|
|
|
47
|
|
|
|
|
161
|
|
6
|
|
|
|
|
|
|
|
7
|
47
|
|
|
47
|
|
1886
|
use B; |
|
47
|
|
|
|
|
45
|
|
|
47
|
|
|
|
|
1417
|
|
8
|
47
|
|
|
47
|
|
134
|
use JSON; |
|
47
|
|
|
|
|
46
|
|
|
47
|
|
|
|
|
187
|
|
9
|
47
|
|
|
47
|
|
3861
|
use List::Util qw(first); |
|
47
|
|
|
|
|
51
|
|
|
47
|
|
|
|
|
2101
|
|
10
|
47
|
|
|
47
|
|
159
|
use Scalar::Util qw(blessed); |
|
47
|
|
|
|
|
45
|
|
|
47
|
|
|
|
|
1850
|
|
11
|
|
|
|
|
|
|
|
12
|
47
|
|
|
47
|
|
153
|
use JSV::Keyword qw(:constants); |
|
47
|
|
|
|
|
48
|
|
|
47
|
|
|
|
|
13487
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub instance_type() { INSTANCE_TYPE_ANY(); } |
15
|
|
|
|
|
|
|
sub keyword() { "type" } |
16
|
|
|
|
|
|
|
sub keyword_priority() { 10; } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub validate { |
19
|
866
|
|
|
866
|
0
|
807
|
my ($class, $context, $schema, $instance) = @_; |
20
|
|
|
|
|
|
|
|
21
|
866
|
|
|
|
|
1615
|
my $keyword_value = $class->keyword_value($schema); |
22
|
|
|
|
|
|
|
|
23
|
866
|
100
|
|
|
|
1306
|
if (ref $keyword_value eq "ARRAY") { |
24
|
13
|
100
|
|
23
|
|
70
|
unless ( first { $class->validate_singular_type( $context, $_, $context->current_type, $instance ) } @$keyword_value ) { |
|
23
|
|
|
|
|
43
|
|
25
|
7
|
|
|
|
|
13
|
$context->log_error("instance type doesn't match schema type list"); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
853
|
100
|
|
|
|
1386
|
unless ($class->validate_singular_type( $context, $keyword_value, $context->current_type, $instance )) { |
30
|
167
|
|
|
|
|
335
|
$context->log_error("instance type doesn't match schema type"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub validate_singular_type { |
36
|
876
|
|
|
876
|
0
|
3464
|
my ($class, $context, $schema_type, $given_type, $instance) = @_; |
37
|
|
|
|
|
|
|
|
38
|
876
|
100
|
100
|
|
|
2333
|
if ( $schema_type eq $given_type || ( $schema_type eq "number" && $given_type eq "integer") ) { |
|
|
|
66
|
|
|
|
|
39
|
538
|
|
|
|
|
1397
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
338
|
100
|
|
|
|
653
|
if ( $given_type eq "number_or_string" ) { |
|
|
100
|
|
|
|
|
|
43
|
27
|
100
|
66
|
|
|
145
|
return 1 if ( $schema_type eq "string" || $schema_type eq "number" ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ( $given_type eq "integer_or_string" ) { |
46
|
131
|
100
|
100
|
|
|
734
|
return 1 if ( $schema_type eq "string" || $schema_type eq "number" || $schema_type eq "integer" ); |
|
|
|
100
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
184
|
|
|
|
|
352
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |