line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Schema::AsType::Draft3::Types; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: JSON-schema v3 keywords as types |
4
|
|
|
|
|
|
|
$JSON::Schema::AsType::Draft3::Types::VERSION = '0.4.3'; |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
42206
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
137
|
|
7
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
134
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
803
|
use Type::Utils -all; |
|
5
|
|
|
|
|
41277
|
|
|
5
|
|
|
|
|
35
|
|
10
|
5
|
|
|
|
|
53
|
use Types::Standard qw/ |
11
|
|
|
|
|
|
|
InstanceOf |
12
|
|
|
|
|
|
|
Str StrictNum HashRef ArrayRef |
13
|
|
|
|
|
|
|
Int |
14
|
|
|
|
|
|
|
Dict slurpy Optional Any |
15
|
|
|
|
|
|
|
Tuple |
16
|
5
|
|
|
5
|
|
17603
|
/; |
|
5
|
|
|
|
|
78085
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Type::Library |
19
|
5
|
|
|
|
|
30
|
-base, |
20
|
|
|
|
|
|
|
-declare => qw( |
21
|
|
|
|
|
|
|
Disallow |
22
|
|
|
|
|
|
|
Extends |
23
|
|
|
|
|
|
|
DivisibleBy |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Properties |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Dependencies Dependency |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Schema |
30
|
5
|
|
|
5
|
|
9285
|
); |
|
5
|
|
|
|
|
11
|
|
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
5
|
|
7097
|
use List::MoreUtils qw/ all any zip none /; |
|
5
|
|
|
|
|
7728
|
|
|
5
|
|
|
|
|
47
|
|
33
|
5
|
|
|
5
|
|
4731
|
use List::Util qw/ pairs pairmap reduce uniq /; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
446
|
|
34
|
|
|
|
|
|
|
|
35
|
5
|
|
|
5
|
|
559
|
use JSON qw/ to_json from_json /; |
|
5
|
|
|
|
|
7949
|
|
|
5
|
|
|
|
|
42
|
|
36
|
|
|
|
|
|
|
|
37
|
5
|
|
|
5
|
|
1421
|
use JSON::Schema::AsType; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
222
|
|
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
74
|
use JSON::Schema::AsType::Draft4::Types 'Not', 'Integer', 'MultipleOf', |
40
|
5
|
|
|
5
|
|
2681
|
'Boolean', 'Number', 'String', 'Null', 'Object', 'Array', 'LaxNumber', 'LaxInteger', 'LaxString'; |
|
5
|
|
|
|
|
23
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__PACKAGE__->meta->add_type( $_ ) for Integer, Boolean, Number, String, Null, Object, Array, LaxNumber, LaxInteger, LaxString; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
declare Dependencies, |
45
|
|
|
|
|
|
|
constraint_generator => sub { |
46
|
|
|
|
|
|
|
my %deps = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return reduce { $a & $b } pairmap { Dependency[$a => $b] } %deps; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
declare Dependency, |
52
|
|
|
|
|
|
|
constraint_generator => sub { |
53
|
|
|
|
|
|
|
my( $property, $dep) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub { |
56
|
|
|
|
|
|
|
return 1 unless Object->check($_); |
57
|
|
|
|
|
|
|
return 1 unless exists $_->{$property}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $obj = $_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return all { exists $obj->{$_} } @$dep if ref $dep eq 'ARRAY'; |
62
|
|
|
|
|
|
|
return exists $obj->{$dep} unless ref $dep; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return $dep->check($_); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
declare Properties => |
69
|
|
|
|
|
|
|
constraint_generator => sub { |
70
|
|
|
|
|
|
|
my $type = Dict[@_, slurpy Any]; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub { |
73
|
|
|
|
|
|
|
! Object->check($_) or $type->check($_) |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
declare Disallow => |
78
|
|
|
|
|
|
|
constraint_generator => sub { |
79
|
|
|
|
|
|
|
Not[ shift ]; |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
declare Extends => |
83
|
|
|
|
|
|
|
constraint_generator => sub { |
84
|
|
|
|
|
|
|
reduce { $a & $b } @_; |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
declare DivisibleBy => |
88
|
|
|
|
|
|
|
constraint_generator => sub { |
89
|
|
|
|
|
|
|
MultipleOf[shift]; |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
declare Schema, as InstanceOf['Type::Tiny']; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
coerce Schema, |
95
|
|
|
|
|
|
|
from HashRef, |
96
|
|
|
|
|
|
|
via { |
97
|
|
|
|
|
|
|
my $schema = JSON::Schema::AsType->new( draft_version => 3, schema => $_ ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if ( $schema->validate_schema ) { |
100
|
|
|
|
|
|
|
die "not a valid draft3 json schema\n"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$schema->type |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=encoding UTF-8 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
JSON::Schema::AsType::Draft3::Types - JSON-schema v3 keywords as types |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 VERSION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
version 0.4.3 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SYNOPSIS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
use JSON::Schema::AsType::Draft3::Types '-all'; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $type = Object & |
127
|
|
|
|
|
|
|
Properties[ |
128
|
|
|
|
|
|
|
foo => Minimum[3] |
129
|
|
|
|
|
|
|
]; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$type->check({ foo => 5 }); # => 1 |
132
|
|
|
|
|
|
|
$type->check({ foo => 1 }); # => 0 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 EXPORTED TYPES |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Null Boolean Array Object String Integer Pattern Number Enum |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
OneOf AllOf AnyOf |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Not |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Minimum ExclusiveMinimum Maximum ExclusiveMaximum MultipleOf |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
MaxLength MinLength |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Items AdditionalItems MaxItems MinItems UniqueItems |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
PatternProperties AdditionalProperties MaxProperties MinProperties |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Dependencies Dependency |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 Schema |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Only verifies that the variable is a L<Type::Tiny>. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Can coerce the value from a hashref defining the schema. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $schema = Schema->coerce( \%schema ); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# equivalent to |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
$schema = JSON::Schema::AsType::Draft4->new( |
163
|
|
|
|
|
|
|
draft_version => 3, |
164
|
|
|
|
|
|
|
schema => \%schema; |
165
|
|
|
|
|
|
|
)->type; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Yanick Champoux <yanick@babyl.dyndns.org> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This software is copyright (c) 2017, 2015 by Yanick Champoux. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
176
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |