{{$NEXT}}
+-Remove automatic inflation of numerical types using Math::Big(Int|Float);
+ this may now be done with inflate_integer and inflate_float
0.02 2020-01-17
-Add MANIFEST.SKIP to prevent dzil from including author scripts
=head1 VERSION
-version 0.02
+version 0.03
=head1 SYNOPSIS
},
);
+=item inflate_integer
+
+TOML integers are 64 bit and may not match the size of the compiled perl's
+internal integer type. By default, integers are left as-is as perl strings
+which may be upgraded as needed by the caller.
+
+ my $parser = TOML::Tiny->new(
+ inflate_integer => sub{
+ use bignum;
+ return 0 + shift;
+ }
+ );
+
+=item inflate_float
+
+TOML floats are 64 bit and may not match the size of the compiled perl's
+internal float type. By default, integers are left as-is as perl strings which
+may be upgraded as needed by the caller.
+
+ my $parser = TOML::Tiny->new(
+ inflate_float => sub{
+ use bignum;
+ return 0 + shift;
+ }
+ );
+
=item strict_arrays
C<TOML v5> specified homogenous arrays. This has since been removed and will no
requires 'Data::Dumper' => '0';
requires 'DateTime::Format::RFC3339' => '0';
requires 'Exporter' => '0';
-requires 'Math::BigInt' => '>= 1.999718';
requires 'Scalar::Util' => '>= 1.14';
recommends 'Types::Serialiser' => 0;
on test => sub{
requires 'Data::Dumper' => '0';
requires 'DateTime::Format::RFC3339' => '0';
+ requires 'Math::BigInt' => '>= 1.999718';
requires 'TOML::Parser' => '0';
requires 'Test2::V0' => '0';
requires 'Test::Pod' => '0';
},
);
+=item inflate_integer
+
+TOML integers are 64 bit and may not match the size of the compiled perl's
+internal integer type. By default, integers are left as-is as perl strings
+which may be upgraded as needed by the caller.
+
+ my $parser = TOML::Tiny->new(
+ inflate_integer => sub{
+ use bignum;
+ return 0 + shift;
+ }
+ );
+
+=item inflate_float
+
+TOML floats are 64 bit and may not match the size of the compiled perl's
+internal float type. By default, integers are left as-is as perl strings which
+may be upgraded as needed by the caller.
+
+ my $parser = TOML::Tiny->new(
+ inflate_float => sub{
+ use bignum;
+ return 0 + shift;
+ }
+ );
+
=item strict_arrays
C<TOML v5> specified homogenous arrays. This has since been removed and will no
sub new {
my ($class, %param) = @_;
bless{
+ inflate_integer => $param{inflate_integer} || sub{ shift },
+ inflate_float => $param{inflate_float} || sub{ shift },
+ inflate_number => $param{inflate_number} || sub{ shift },
inflate_datetime => $param{inflate_datetime} || sub{ shift },
inflate_boolean => $param{inflate_boolean} || sub{ shift eq 'true' ? $TRUE : $FALSE },
strict_arrays => $param{strict_arrays},
my $token = shift // $self->next_token;
for ($token->{type}) {
- when ('float') {
- use bignum;
- return $token->{value} + 0;
- }
-
- when ('integer') {
- for (my $n = $token->{value}) {
- use bigint;
-
- when ($Oct) {
- $n =~ s/^0o/0/; # convert to perl's octal format
- return oct $n;
- }
-
- when ($Bin) {
- return oct $n;
- }
-
- when ($Hex) {
- return hex $n;
- }
-
- default{
- return $n + 0;
- }
- }
- }
-
return $token->{value} when 'string';
+ return $self->{inflate_float}->($token->{value}) when 'float';
+ return $self->{inflate_integer}->($token->{value}) when 'integer';
return $self->{inflate_boolean}->($token->{value}) when 'bool';
return $self->{inflate_datetime}->($token->{value}) when 'datetime';
return $self->parse_inline_table when 'inline_table';
my $type;
for (ref $value) {
- $type = 'array' when /ARRAY/;
- $type = 'table' when /HASH/;
- $type = 'float' when /Math::BigFloat/;
- $type = 'integer' when /Math::BigInt/;
- $type = 'bool' when /JSON::PP::Boolean/;
+ $type = 'array' when 'ARRAY';
+ $type = 'table' when 'HASH';
+
+ # Do a little heuristic guess-work
+ $type = 'float' when /Float/;
+ $type = 'integer' when /Int/;
+ $type = 'bool' when /Boolean/;
when ('') {
for ($value) {
- $type = 'bool' when /$Boolean/;
- $type = 'float' when /$Float/;
- $type = 'integer' when /$Integer/;
- $type = 'datetime' when /$DateTime/;
+ $type = 'bool' when /$Boolean/;
+ $type = 'float' when /$Float/;
+ $type = 'integer' when /$Integer/;
+ $type = 'datetime' when /$DateTime/;
default{ $type = 'string' };
}
}
use Data::Dumper;
use DateTime::Format::RFC3339;
-use Math::BigFloat;
use Scalar::Util qw(looks_like_number);
use TOML::Tiny::Grammar;
use TOML::Tiny::Util qw(is_strict_array);