@@ -465,11 +465,10 @@ sub _eval_keyword_multipleOf ($data, $schema, $state) {
465
465
and do { $data = 0+$data ; 1 });
466
466
467
467
# if either value is a float, use the bignum library for the calculation
468
- if (ref ($data ) =~ / ^Math::Big(?:Int|Float)$ /
469
- or ref ($schema -> {multipleOf }) =~ / ^Math::Big(?:Int|Float)$ /
468
+ if (is_bignum($data ) or is_bignum($schema -> {multipleOf })
470
469
or get_type($data ) eq ' number' or get_type($schema -> {multipleOf }) eq ' number' ) {
471
- $data = ref ($data ) =~ / ^Math::Big(?:Int|Float) $ / ? $data -> copy : Math::BigFloat-> new($data );
472
- my $divisor = ref ($schema -> {multipleOf }) =~ / ^Math::Big(?:Int|Float) $ / ? $schema -> {multipleOf } : Math::BigFloat-> new($schema -> {multipleOf });
470
+ $data = is_bignum ($data ) ? $data -> copy : Math::BigFloat-> new($data );
471
+ my $divisor = is_bignum ($schema -> {multipleOf }) ? $schema -> {multipleOf } : Math::BigFloat-> new($schema -> {multipleOf });
473
472
my ($quotient , $remainder ) = $data -> bdiv($divisor );
474
473
return E($state , ' overflow while calculating quotient' ) if $quotient -> is_inf;
475
474
return 1 if $remainder == 0;
@@ -1070,12 +1069,12 @@ sub is_type ($type, $value) {
1070
1069
}
1071
1070
1072
1071
if ($type eq ' number' ) {
1073
- return ref ($value ) =~ / ^Math::Big(?:Int|Float) $ /
1072
+ return is_bignum ($value )
1074
1073
|| !($flags & B::SVf_POK) && ($flags & (B::SVf_IOK | B::SVf_NOK));
1075
1074
}
1076
1075
1077
1076
if ($type eq ' integer' ) {
1078
- return ref ($value ) =~ / ^Math::Big(?:Int|Float) $ / && $value -> is_int
1077
+ return is_bignum ($value ) && $value -> is_int
1079
1078
|| !($flags & B::SVf_POK) && ($flags & (B::SVf_IOK | B::SVf_NOK)) && int ($value ) == $value ;
1080
1079
}
1081
1080
}
@@ -1093,7 +1092,7 @@ sub get_type ($value) {
1093
1092
return ' array' if is_plain_arrayref($value );
1094
1093
return ' boolean' if is_bool($value );
1095
1094
1096
- return ref ($value ) =~ / ^Math::Big(?:Int|Float) $ / ? ($value -> is_int ? ' integer' : ' number' )
1095
+ return is_bignum ($value ) ? ($value -> is_int ? ' integer' : ' number' )
1097
1096
: (blessed($value ) ? ' ' : ' reference to ' ).ref ($value )
1098
1097
if is_ref($value );
1099
1098
@@ -1114,6 +1113,10 @@ sub is_bool ($value) {
1114
1113
or $value -> isa(' JSON::XS::Boolean' ));
1115
1114
}
1116
1115
1116
+ sub is_bignum ($value ) {
1117
+ ref ($value ) =~ / ^Math::Big(?:Int|Float)$ / ;
1118
+ }
1119
+
1117
1120
# compares two arbitrary data payloads for equality, as per
1118
1121
# https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.4.2.2
1119
1122
# if provided with a state hashref, any differences are recorded within
@@ -1286,7 +1289,7 @@ sub assert_array_schemas ($schema, $state) {
1286
1289
1287
1290
sub sprintf_num ($value ) {
1288
1291
# use original value as stored in the NV, without losing precision
1289
- ref ($value ) =~ / ^Math::Big(?:Int|Float) $ / ? $value -> bstr : sprintf (' %s' , $value );
1292
+ is_bignum ($value ) ? $value -> bstr : sprintf (' %s' , $value );
1290
1293
}
1291
1294
1292
1295
1;
@@ -1322,7 +1325,7 @@ validator, supporting the most popular keywords.
1322
1325
1323
1326
=head1 FUNCTIONS
1324
1327
1325
- =for Pod::Coverage is_type get_type is_bool is_equal is_elements_unique jsonp canonical_uri E abort
1328
+ =for Pod::Coverage is_type get_type is_bool is_bignum is_equal is_elements_unique jsonp canonical_uri E abort
1326
1329
assert_keyword_type assert_pattern assert_uri assert_non_negative_integer assert_array_schemas
1327
1330
new assert_uri_reference sprintf_num
1328
1331
0 commit comments