| 1 | package JSON::Schema::AsType::Draft4::Types; | ||||||||||||||||||||||||||||
| 2 | 39 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 3 | 39 | $JSON::Schema::AsType::Draft4::Types::VERSION = '1.0.0'; | |||||||||||||||||||||||||||
| 4 | # ABSTRACT: JSON-schema v4 keywords as types | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 39 | ▶ | use 5.42.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 39 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 39 | ▶ | use Test::Deep::NoTest qw/ eq_deeply /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 39 | ▶ | use Math::BigFloat; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 39 | ▶ | use Hash::Merge qw/ merge /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 39 | ▶ | use Type::Utils -all; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 39 | ▶ | use Types::Standard qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | Str StrictNum HashRef ArrayRef | ||||||||||||||||||||||||||||
| 17 | Int | ||||||||||||||||||||||||||||
| 18 | Dict Slurpy Optional Any slurpy | ||||||||||||||||||||||||||||
| 19 | Tuple | ||||||||||||||||||||||||||||
| 20 | ConsumerOf | ||||||||||||||||||||||||||||
| 21 | InstanceOf | ||||||||||||||||||||||||||||
| 22 | 39 | /; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | use Type::Library | ||||||||||||||||||||||||||||
| 25 | 39 | ▶ | -base, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | -declare => qw( | ||||||||||||||||||||||||||||
| 27 | Minimum | ||||||||||||||||||||||||||||
| 28 | ExclusiveMinimum | ||||||||||||||||||||||||||||
| 29 | Maximum | ||||||||||||||||||||||||||||
| 30 | ExclusiveMaximum | ||||||||||||||||||||||||||||
| 31 | MultipleOf | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Null | ||||||||||||||||||||||||||||
| 34 | Boolean | ||||||||||||||||||||||||||||
| 35 | Array | ||||||||||||||||||||||||||||
| 36 | Object | ||||||||||||||||||||||||||||
| 37 | String | ||||||||||||||||||||||||||||
| 38 | Integer | ||||||||||||||||||||||||||||
| 39 | Pattern | ||||||||||||||||||||||||||||
| 40 | Number | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Required | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Not | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | OneOf | ||||||||||||||||||||||||||||
| 47 | AllOf | ||||||||||||||||||||||||||||
| 48 | AnyOf | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | MaxLength | ||||||||||||||||||||||||||||
| 51 | MinLength | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Items | ||||||||||||||||||||||||||||
| 54 | AdditionalItems | ||||||||||||||||||||||||||||
| 55 | MaxItems | ||||||||||||||||||||||||||||
| 56 | MinItems | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Properties | ||||||||||||||||||||||||||||
| 59 | PatternProperties | ||||||||||||||||||||||||||||
| 60 | AdditionalProperties | ||||||||||||||||||||||||||||
| 61 | MaxProperties | ||||||||||||||||||||||||||||
| 62 | MinProperties | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Dependencies | ||||||||||||||||||||||||||||
| 65 | Dependency | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Enum | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | UniqueItems | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Schema | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 39 | ); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 39 | ▶ | use List::MoreUtils qw/ all any zip none /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 39 | ▶ | use List::Util qw/ pairs pairmap reduce uniq /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 39 | ▶ | use List::AllUtils qw/ none uniq /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 39 | ▶ | use JSON qw/ to_json from_json /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 39 | ▶ | use JSON::Schema::AsType; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | 39 | ▶ | use JSON::Schema::AsType::Annotations; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | declare AdditionalProperties, | ||||||||||||||||||||||||||||
| 85 | 211 | ▶ | constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | 211 | my ( $known_properties, $type_or_boolean ) = @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 621 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 89 | 621 | ▶ | return 1 unless Object->check($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | my @add_keys = grep { | ||||||||||||||||||||||||||||
| 92 | 385 | my $key = $_; | |||||||||||||||||||||||||||
| 93 | 457 | ▶ | none { ref $_ ? $key =~ $_ : $key eq $_ } @$known_properties | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } keys %$_; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 385 | add_annotation( 'additionalProperties', @add_keys ); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 385 | ▶ | if ( eval { $type_or_boolean->can('check') } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 256 | my $obj = $_; | |||||||||||||||||||||||||||
| 100 | 256 | ▶ | return all { $type_or_boolean->check( $obj->{$_} ) } @add_keys; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 129 | ▶ | return not( @add_keys and not $type_or_boolean ); | ||||||||||||||||||||||||||
|
Condition100%3/3
@add_keys && !$type_or_boolean
MC/DC100%2/2
@add_keys && !$type_or_boolean
@add_keys
!$type_or_boolean
Truth table100%3/3
A && not(B)
A= @add_keysB= !$type_or_boolean
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 211 | }; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 256 | ▶ | declare UniqueItems, where { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 108 | 256 | ▶ | return 1 unless Array->check($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 237 | @$_ == uniq map { to_json $_, { allow_nonref => 1, canonical => 1 } } @$_ | |||||||||||||||||||||||||||
| 110 | 39 | }; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 39 | my $json = JSON->new->allow_nonref->canonical; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 92 | ▶ | declare Enum, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 115 | 92 | my @items = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1314 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 118 | 1314 | my $j = $_; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # TODO horrible corner case for the test suite, worth it? | ||||||||||||||||||||||||||||
| 121 | 1314 | ▶ | any { eq_deeply( $_, $j ) } @items; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 92 | }; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # Dependencies[ foo => $type, bar => [ 'baz' ] ] | ||||||||||||||||||||||||||||
| 126 | # TODO name of generated type should be better | ||||||||||||||||||||||||||||
| 127 | 8 | ▶ | declare Dependencies, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 128 | 8 | my %deps = @_; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 8 | ▶ | return reduce { $a & $b } pairmap { Dependency [ $a => $b ] } %deps; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 131 | 39 | }; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # Depencency[ foo => $type ] | ||||||||||||||||||||||||||||
| 134 | 14 | ▶ | declare Dependency, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | 14 | my ( $property, $dep ) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 92 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 138 | 92 | ▶ | return 1 unless Object->check($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 89 | ▶ | return 1 unless exists $_->{$property}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 26 | my $obj = $_; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 26 | ▶ | return all { exists $obj->{$_} } @$dep if ref $dep eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 13 | return $dep->check($_); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 14 | }; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 54 | ▶ | declare PatternProperties, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | 54 | my %props = @_; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 389 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 153 | 389 | ▶ | return 1 unless Object->check($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 288 | my $obj = $_; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 288 | my @keys; | |||||||||||||||||||||||||||
| 158 | 288 | for my $key ( keys %props ) { | |||||||||||||||||||||||||||
| 159 | 336 | push @keys, grep { /$key/ } keys %$obj; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 288 | add_annotation( 'patternProperties', @keys ); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 288 | for my $key ( keys %props ) { | |||||||||||||||||||||||||||
| 165 | return | ||||||||||||||||||||||||||||
| 166 | 211 | ▶ | unless all { $props{$key}->check( $obj->{$_} ) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 167 | 317 | ▶ | grep { /$key/ } keys %$_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 221 | return 1; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 54 | }; | |||||||||||||||||||||||||||
| 174 | 442 | ▶ | declare Properties, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 175 | 442 | my %types = @_; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 442 | ▶ | %types = pairmap { $a => Optional [$b] } %types; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | return ~HashRef # not an object, don't care | ||||||||||||||||||||||||||||
| 180 | | ( | ||||||||||||||||||||||||||||
| 181 | 36305 | ▶ | Dict [ %types, Slurpy [Any] ] & sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 182 | 36305 | my $value = $_; | |||||||||||||||||||||||||||
| 183 | add_annotation( 'properties', | ||||||||||||||||||||||||||||
| 184 | 36305 | grep { exists $value->{$_} } keys %types ); | |||||||||||||||||||||||||||
| 185 | 36305 | return 1; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 442 | ); | |||||||||||||||||||||||||||
| 188 | 39 | }; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 228 | ▶ | declare Items, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 191 | 228 | my $types = shift; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 228 | ▶ | if ( Boolean->check($types) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 3 | ▶ | return $types ? Any : sub { !@$_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | my $type = | ||||||||||||||||||||||||||||
| 198 | ref $types eq 'ARRAY' | ||||||||||||||||||||||||||||
| 199 | 225 | ▶ | ? Tuple [ ( map { Optional [$_] } @$types ), slurpy Any ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | : Tuple [ slurpy ArrayRef [$types] ]; | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | return ~ArrayRef | ( | ||||||||||||||||||||||||||||
| 203 | 10463 | ▶ | $type & sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 204 | 10463 | ▶ | if ( ref $types eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 2168 | add_annotation( 'items', 0 .. $types->$#* ); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||
| 208 | 8295 | add_annotation( 'items', 0 .. $_->$#* ); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 10463 | return 1; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 225 | ); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 39 | }; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 52 | ▶ | declare AdditionalItems, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=17.0
| |||||||||||||||||||||||||||||
| 217 | 52 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 52 | my $to_skip = shift; | |||||||||||||||||||||||||||
| 219 | 52 | my $schema = shift; | |||||||||||||||||||||||||||
| 220 | 317 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.6
| |||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 317 | ▶ | return unless ref eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 313 | my @additional = splice @$_, $to_skip; | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 313 | ▶ | if ( ref $schema eq 'JSON::PP::Boolean' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | my $verdict = @additional; | |||||||||||||||||||||||||||
| 227 | 0 | ▶ | $verdict = !$verdict unless $schema; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 0 | return $verdict; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 313 | ▶ | return all { $schema->check($_) } @additional; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 52 | } | |||||||||||||||||||||||||||
| 234 | else { | ||||||||||||||||||||||||||||
| 235 | 0 | my $size = shift; | |||||||||||||||||||||||||||
| 236 | 0 | ▶ | if ( ref $size eq 'JSON::PP::Boolean' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my $s = ref($_) eq 'ARRAY' ? @_ : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 0 | $DB::single = 1; | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | return !!$size ? $s : !$s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | 0 | } | |||||||||||||||||||||||||||
| 243 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 244 | 0 | ▶ | my $s = ref($_) eq 'ARRAY' ? @_ : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | 0 | $s <= $size; | |||||||||||||||||||||||||||
| 246 | 0 | }; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | 39 | }; | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 11 | ▶ | declare MaxLength, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 251 | 11 | my $length = shift; | |||||||||||||||||||||||||||
| 252 | 122 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 253 | 122 | ▶ | !String->check($_) or $length >= length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | 11 | }; | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 6 | ▶ | declare MinLength, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 258 | 6 | my $length = shift; | |||||||||||||||||||||||||||
| 259 | 115 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 260 | 115 | ▶ | !String->check($_) or $length <= length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | 6 | }; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 153 | ▶ | declare AllOf, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 265 | 153 | my @types = @_; | |||||||||||||||||||||||||||
| 266 | 425 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 267 | 425 | my $value = $_; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 425 | my $matched = 1; | |||||||||||||||||||||||||||
| 270 | 425 | my $scope = {}; | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 425 | for my $type (@types) { | |||||||||||||||||||||||||||
| 273 | 601 | my %scope; | |||||||||||||||||||||||||||
| 274 | return 0 unless annotation_scope( | ||||||||||||||||||||||||||||
| 275 | 601 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 276 | 601 | ▶ | return 0 unless $type->check($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 441 | $scope = annotation_merge($scope); | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 441 | return 1; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | 601 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 265 | annotation_merge($scope); | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 265 | return 1; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | 153 | }; | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 143 | ▶ | declare AnyOf, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 292 | 143 | my @types = @_; | |||||||||||||||||||||||||||
| 293 | 757 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 294 | 757 | my $value = $_; | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 757 | my $matched = 0; | |||||||||||||||||||||||||||
| 297 | 757 | my $scope = {}; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 757 | for my $type (@types) { | |||||||||||||||||||||||||||
| 300 | annotation_scope( | ||||||||||||||||||||||||||||
| 301 | 1488 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 302 | 1488 | ▶ | return unless $type->check($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 636 | $scope = annotation_merge($scope); | |||||||||||||||||||||||||||
| 305 | 636 | $matched = 1; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | 1488 | ); | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 757 | ▶ | if ($matched) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 589 | annotation_merge($scope); | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 757 | return $matched; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | 143 | }; | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 57 | ▶ | declare OneOf, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 319 | 57 | my @types = @_; | |||||||||||||||||||||||||||
| 320 | 277 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 321 | 277 | my $value = $_; | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 277 | my $matched = 0; | |||||||||||||||||||||||||||
| 324 | 277 | my $scope = {}; | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 277 | for my $type (@types) { | |||||||||||||||||||||||||||
| 327 | return 0 unless annotation_scope( | ||||||||||||||||||||||||||||
| 328 | 585 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 329 | 585 | ▶ | return 1 unless $type->check($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 261 | ▶ | return 0 if $matched; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 204 | $scope = annotation_merge($scope); | |||||||||||||||||||||||||||
| 334 | 204 | $matched = 1; | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 204 | return 1; | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | 585 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 220 | ▶ | if ($matched) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 147 | annotation_merge($scope); | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 220 | return $matched; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | 57 | }; | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 4 | ▶ | declare MaxProperties, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 351 | 4 | my $nbr = shift; | |||||||||||||||||||||||||||
| 352 | 4 | ▶ | sub { !Object->check($_) or $nbr >= keys %$_; },; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | 39 | }; | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 3 | ▶ | declare MinProperties, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 356 | 3 | my $nbr = shift; | |||||||||||||||||||||||||||
| 357 | 51 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 358 | 51 | ▶ | !Object->check($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | or $nbr <= scalar keys %$_; | ||||||||||||||||||||||||||||
| 360 | 3 | },; | |||||||||||||||||||||||||||
| 361 | 39 | }; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 51 | ▶ | declare Not, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 364 | 51 | my $type = shift; | |||||||||||||||||||||||||||
| 365 | 51 | ▶ | sub { not $type->check($_) },; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 366 | 39 | }; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | # ~Str or ~String? | ||||||||||||||||||||||||||||
| 369 | 13 | ▶ | declare Pattern, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 370 | 13 | my $regex = shift; | |||||||||||||||||||||||||||
| 371 | 13 | ▶ | sub { !String->check($_) or /$regex/ },; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 39 | }; | |||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 37540 | ▶ | declare Object => as HashRef, where sub { ref eq 'HASH' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 26 | ▶ | declare Required, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 377 | 26 | my @keys = @_; | |||||||||||||||||||||||||||
| 378 | 18493 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 379 | 18493 | ▶ | return 1 unless Object->check($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | 18454 | my $obj = $_; | |||||||||||||||||||||||||||
| 381 | 18454 | ▶ | all { exists $obj->{$_} } @keys; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | 26 | }; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 39 | declare Array => as ArrayRef; | |||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 1565 | ▶ | declare Boolean => where sub { ref =~ /JSON/ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | declare | ||||||||||||||||||||||||||||
| 390 | LaxNumber => as StrictNum, | ||||||||||||||||||||||||||||
| 391 | 4 | ▶ | where sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 392 | 4 | ▶ | return !( !defined || ref ); | ||||||||||||||||||||||||||
|
Condition33%1/3
!defined($_) || ref $_
MC/DC0%0/2
!defined($_) || ref $_
!defined($_)
ref $_
Truth table33%1/3
not(A) || B
A= !defined($_)B= ref $_
| |||||||||||||||||||||||||||||
| 393 | 39 | }; | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 73370 | ▶ | declare Number => where sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 396 | 73370 | ▶ | return 0 if !defined || ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $_ or ref $_
MC/DC100%2/2
not defined $_ or ref $_
not defined $_
ref $_
Truth table100%3/3
not(A) or B
A= not defined $_B= ref $_
| |||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 73326 | my $b_obj = B::svref_2object( \$_ ); | |||||||||||||||||||||||||||
| 399 | 73326 | my $flags = $b_obj->FLAGS; | |||||||||||||||||||||||||||
| 400 | 73326 | ▶ | return ( $flags & ( B::SVp_IOK | B::SVp_NOK ) | ||||||||||||||||||||||||||
|
Condition66%2/3
$flags & 12288 && !($flags & 16384)
MC/DC50%1/2
$flags & 12288 && !($flags & 16384)
$flags & 12288
!($flags & 16384)
Truth table66%2/3
A && not(B)
A= $flags & 12288B= !($flags & 16384)
| |||||||||||||||||||||||||||||
| 401 | and not( $flags & B::SVp_POK ) ); | ||||||||||||||||||||||||||||
| 402 | 39 | }; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | declare | ||||||||||||||||||||||||||||
| 405 | LaxInteger => as Int, | ||||||||||||||||||||||||||||
| 406 | 0 | ▶ | where sub { return !( !defined || ref ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
!defined($_) || ref $_
MC/DC0%0/2
!defined($_) || ref $_
!defined($_)
ref $_
Truth table0%0/3
not(A) || B
A= !defined($_)B= ref $_
| |||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 1245 | ▶ | declare Integer => where sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 409 | 1245 | ▶ | return 0 unless Int->check($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | # weeeird stuff stolen from JSON | ||||||||||||||||||||||||||||
| 412 | 880 | my $b_obj = B::svref_2object( \$_ ); | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 880 | my $flags = $b_obj->FLAGS; | |||||||||||||||||||||||||||
| 415 | 880 | ▶ | my $verdict = | ||||||||||||||||||||||||||
|
Condition66%2/3
$flags & 12288 && !($flags & 16384)
MC/DC50%1/2
$flags & 12288 && !($flags & 16384)
$flags & 12288
!($flags & 16384)
Truth table66%2/3
A && not(B)
A= $flags & 12288B= !($flags & 16384)
| |||||||||||||||||||||||||||||
| 416 | $flags & ( B::SVp_IOK | B::SVp_NOK ) && !( $flags & B::SVp_POK() ); | ||||||||||||||||||||||||||||
| 417 | 880 | return !!$verdict; | |||||||||||||||||||||||||||
| 418 | 39 | }; | |||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | declare | ||||||||||||||||||||||||||||
| 421 | LaxString => as Str, | ||||||||||||||||||||||||||||
| 422 | 6 | ▶ | where sub { return defined && not ref; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
Condition33%1/3
defined $_ && !ref($_)
MC/DC0%0/2
defined $_ && !ref($_)
defined $_
!ref($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !ref($_)
| |||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | declare | ||||||||||||||||||||||||||||
| 425 | String => as Str, | ||||||||||||||||||||||||||||
| 426 | 3939 | ▶ | where sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 427 | 3939 | ▶ | return 0 if !defined || ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $_ or ref $_
MC/DC0%0/2
not defined $_ or ref $_
not defined $_
ref $_
Truth table33%1/3
not(A) or B
A= not defined $_B= ref $_
| |||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 3939 | my $b_obj = B::svref_2object( \$_ ); | |||||||||||||||||||||||||||
| 430 | 3939 | my $flags = $b_obj->FLAGS; | |||||||||||||||||||||||||||
| 431 | 3939 | return ( $flags & B::SVp_POK ); | |||||||||||||||||||||||||||
| 432 | 39 | }; | |||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 281 | ▶ | declare Null => where sub { not defined }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 3 | ▶ | declare 'MaxItems', constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 437 | 3 | my $max = shift; | |||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 90 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 440 | 90 | ▶ | ref ne 'ARRAY' or @$_ <= $max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | 3 | }; | |||||||||||||||||||||||||||
| 442 | 39 | }; | |||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 7 | ▶ | declare 'MinItems', constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 445 | 7 | my $min = shift; | |||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 212 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 448 | 212 | ▶ | ref ne 'ARRAY' or @$_ >= $min; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 449 | 7 | }; | |||||||||||||||||||||||||||
| 450 | 39 | }; | |||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 8 | ▶ | declare 'MultipleOf', constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 453 | 8 | my $num = shift; | |||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 254 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 456 | 254 | ▶ | return 1 unless Number->check($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | 247 | my ( $q, $r ) = Math::BigFloat->new($_)->bdiv($num); | |||||||||||||||||||||||||||
| 458 | 247 | return !$r; | |||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | 8 | }; | |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 13 | ▶ | declare Minimum, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 463 | 13 | my $minimum = shift; | |||||||||||||||||||||||||||
| 464 | 281 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 465 | 281 | ▶ | !Number->check($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | or $_ >= $minimum; | ||||||||||||||||||||||||||||
| 467 | 13 | }; | |||||||||||||||||||||||||||
| 468 | 39 | }; | |||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 7 | ▶ | declare ExclusiveMinimum, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 471 | 7 | my $minimum = shift; | |||||||||||||||||||||||||||
| 472 | 24 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 473 | 24 | ▶ | !StrictNum->check($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 474 | or $_ > $minimum; | ||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | 7 | }; | |||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 6 | ▶ | declare Maximum, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 479 | 6 | my $max = shift; | |||||||||||||||||||||||||||
| 480 | 149 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 481 | 149 | ▶ | !StrictNum->check($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | or $_ <= $max; | ||||||||||||||||||||||||||||
| 483 | 6 | }; | |||||||||||||||||||||||||||
| 484 | 39 | }; | |||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 3 | ▶ | declare ExclusiveMaximum, constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 487 | 3 | my $max = shift; | |||||||||||||||||||||||||||
| 488 | 60 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 489 | 60 | ▶ | !StrictNum->check($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 490 | or $_ < $max; | ||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | 3 | }; | |||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 39 | declare Schema, as InstanceOf ['Type::Tiny']; | |||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 1 | ▶ | coerce Schema, from HashRef, via { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 497 | 1 | my $schema = JSON::Schema::AsType->new( draft => 4, schema => $_ ); | |||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | 1 | ▶ | if ( $schema->validate_schema ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 500 | 0 | die "not a valid draft4 json schema\n"; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | $schema->type | ||||||||||||||||||||||||||||
| 504 | 1 | }; | |||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 39 | 1; | |||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | __END__ | ||||||||||||||||||||||||||||