Ideally, if we read a TOML file and write it back out again, we get a
semantically equivalent TOML file. Here we improve the situation
for smallish deciaml integers.
We check for values that round trip from string through a perl integer
and back to the same string; if they do, return that integer rather
than the string.
The main point of this check is to avoid losing information if the
value is too large to fit into a Perl integer, which might be only
32-bit.
This technique is not perfect: it can't cope with hex, octal or
binary, or with larger values that would need bignums. But it is an
improvement and probably the best that can be done without
unreasonable effort.
=item inflate_integer
TOML integers are 64 bit and may not match the size of the compiled perl's
=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.
+internal integer type. By default, integers other than smallish
+decimal 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{
my $parser = TOML::Tiny->new(
inflate_integer => sub{
=item inflate_integer
TOML integers are 64 bit and may not match the size of the compiled perl's
=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.
+internal integer type. By default, integers other than smallish
+decimal 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{
my $parser = TOML::Tiny->new(
inflate_integer => sub{
sub tokenize_integer {
$_[1] =~ tr/_+//d;
sub tokenize_integer {
$_[1] =~ tr/_+//d;
+ $_[1] !~ m/^0[xob]/ && $_[1] + 0 eq $_[0] ? $_[1] + 0 : "$_[1]"