line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSV::Keyword::Draft4::Type; |
2
|
|
|
|
|
|
|
|
3
|
47
|
|
|
47
|
|
37689
|
use strict; |
|
47
|
|
|
|
|
98
|
|
|
47
|
|
|
|
|
1274
|
|
4
|
47
|
|
|
47
|
|
292
|
use warnings; |
|
47
|
|
|
|
|
94
|
|
|
47
|
|
|
|
|
1292
|
|
5
|
47
|
|
|
47
|
|
266
|
use parent qw(JSV::Keyword); |
|
47
|
|
|
|
|
82
|
|
|
47
|
|
|
|
|
249
|
|
6
|
|
|
|
|
|
|
|
7
|
47
|
|
|
47
|
|
2409
|
use B; |
|
47
|
|
|
|
|
87
|
|
|
47
|
|
|
|
|
1897
|
|
8
|
47
|
|
|
47
|
|
244
|
use JSON; |
|
47
|
|
|
|
|
97
|
|
|
47
|
|
|
|
|
411
|
|
9
|
47
|
|
|
47
|
|
6052
|
use List::Util qw(first); |
|
47
|
|
|
|
|
91
|
|
|
47
|
|
|
|
|
2850
|
|
10
|
47
|
|
|
47
|
|
250
|
use Scalar::Util qw(blessed); |
|
47
|
|
|
|
|
92
|
|
|
47
|
|
|
|
|
2451
|
|
11
|
|
|
|
|
|
|
|
12
|
47
|
|
|
47
|
|
241
|
use JSV::Keyword qw(:constants); |
|
47
|
|
|
|
|
88
|
|
|
47
|
|
|
|
|
20312
|
|
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
|
1654
|
my ($class, $context, $schema, $instance) = @_; |
20
|
|
|
|
|
|
|
|
21
|
866
|
|
|
|
|
2829
|
my $keyword_value = $class->keyword_value($schema); |
22
|
|
|
|
|
|
|
|
23
|
866
|
100
|
|
|
|
2389
|
if (ref $keyword_value eq "ARRAY") { |
24
|
13
|
100
|
|
23
|
|
87
|
unless ( first { $class->validate_singular_type( $context, $_, $context->current_type, $instance ) } @$keyword_value ) { |
|
23
|
|
|
|
|
71
|
|
25
|
7
|
|
|
|
|
24
|
$context->log_error("instance type doesn't match schema type list"); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
853
|
100
|
|
|
|
2714
|
unless ($class->validate_singular_type( $context, $keyword_value, $context->current_type, $instance )) { |
30
|
167
|
|
|
|
|
581
|
$context->log_error("instance type doesn't match schema type"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub validate_singular_type { |
36
|
876
|
|
|
876
|
0
|
6540
|
my ($class, $context, $schema_type, $given_type, $instance) = @_; |
37
|
|
|
|
|
|
|
|
38
|
876
|
100
|
100
|
|
|
4045
|
if ( $schema_type eq $given_type || ( $schema_type eq "number" && $given_type eq "integer") ) { |
|
|
|
66
|
|
|
|
|
39
|
538
|
|
|
|
|
2599
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
338
|
100
|
|
|
|
1112
|
if ( $given_type eq "number_or_string" ) { |
|
|
100
|
|
|
|
|
|
43
|
27
|
100
|
66
|
|
|
227
|
return 1 if ( $schema_type eq "string" || $schema_type eq "number" ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ( $given_type eq "integer_or_string" ) { |
46
|
131
|
100
|
100
|
|
|
1365
|
return 1 if ( $schema_type eq "string" || $schema_type eq "number" || $schema_type eq "integer" ); |
|
|
|
100
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
184
|
|
|
|
|
626
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |