line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Schema::Shorthand; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Alternative, condensed format for JSON Schemas |
4
|
|
|
|
|
|
|
$JSON::Schema::Shorthand::VERSION = '0.0.1'; |
5
|
1
|
|
|
1
|
|
30493
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
350
|
use experimental 'postderef'; |
|
1
|
|
|
|
|
2215
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
491
|
use parent 'Exporter::Tiny'; |
|
1
|
|
|
|
|
201
|
|
|
1
|
|
|
|
|
3
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = ( 'js_shorthand' ); |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
2873
|
use Clone qw/ clone /; |
|
1
|
|
|
|
|
1768
|
|
|
1
|
|
|
|
|
328
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub js_shorthand { |
17
|
22
|
|
|
22
|
1
|
30850
|
my $object = clone( shift ); |
18
|
|
|
|
|
|
|
|
19
|
22
|
100
|
|
|
|
48
|
unless( ref $object ) { |
20
|
10
|
100
|
|
|
|
37
|
$object = { ( ( '#' eq substr $object, 0, 1 ) ? '$ref' : 'type' ) => $object }; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
22
|
100
|
|
|
|
47
|
if ( my $array = delete $object->{array} ) { |
24
|
2
|
|
|
|
|
3
|
$object->{type} = 'array'; |
25
|
|
|
|
|
|
|
$object->{items} = ref $array eq 'ARRAY' |
26
|
2
|
100
|
|
|
|
7
|
? [ map { js_shorthand($_) } @$array ] |
|
1
|
|
|
|
|
3
|
|
27
|
|
|
|
|
|
|
: js_shorthand( $array ) |
28
|
|
|
|
|
|
|
; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
22
|
100
|
|
|
|
37
|
if( my $props = delete $object->{object} ) { |
32
|
2
|
|
|
|
|
3
|
$object->{type} = 'object'; |
33
|
2
|
|
|
|
|
3
|
$object->{properties} = $props; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# foo => { bar => $schema } |
37
|
22
|
|
|
|
|
28
|
for my $keyword ( qw/ definitions properties / ) { |
38
|
44
|
100
|
|
|
|
75
|
next unless $object->{$keyword}; |
39
|
4
|
|
|
|
|
4
|
$_ = js_shorthand($_) for values %{ $object->{$keyword} }; |
|
4
|
|
|
|
|
16
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# foo => [ @schemas ] |
43
|
22
|
|
|
|
|
26
|
for my $keyword ( qw/ anyOf allOf oneOf / ) { |
44
|
66
|
100
|
|
|
|
92
|
next unless $object->{$keyword}; |
45
|
|
|
|
|
|
|
$object->{$keyword} = [ |
46
|
3
|
|
|
|
|
6
|
map { js_shorthand($_) } $object->{$keyword}->@* |
|
3
|
|
|
|
|
6
|
|
47
|
|
|
|
|
|
|
]; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# foo => $schemas |
51
|
22
|
|
|
|
|
17
|
for my $keyword ( qw/ not / ) { |
52
|
22
|
100
|
|
|
|
40
|
next unless $object->{$keyword}; |
53
|
1
|
|
|
|
|
4
|
$object->{$keyword} = js_shorthand($object->{$keyword}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# required attribute |
57
|
22
|
100
|
|
|
|
28
|
if ( $object->{properties} ) { |
58
|
|
|
|
|
|
|
my @required = grep { |
59
|
|
|
|
|
|
|
delete $object->{properties}{$_}{required} |
60
|
3
|
|
|
|
|
6
|
} keys $object->{properties}->%*; |
|
3
|
|
|
|
|
30
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$object->{required} = [ |
63
|
3
|
100
|
|
|
|
11
|
eval { $object->{required}->@* }, |
|
1
|
|
|
|
|
12
|
|
64
|
|
|
|
|
|
|
@required |
65
|
|
|
|
|
|
|
] if @required; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
22
|
|
|
|
|
56
|
return $object; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |