sub to_toml {
my $data = shift;
my %param = @_;
- my @buff;
+ my @buff_assign;
+ my @buff_tables;
for (ref $data) {
when ('HASH') {
for my $k (grep{ ref($data->{$_}) !~ /HASH|ARRAY/ } sort keys %$data) {
my $key = to_toml_key($k);
my $val = to_toml($data->{$k}, %param);
- push @buff, "$key=$val";
+ push @buff_assign, "$key=$val";
}
# For values which are arrays, generate inline arrays for non-table
# Empty table
if (!@{$data->{$k}}) {
my $key = to_toml_key($k);
- push @buff, "$key=[]";
+ push @buff_assign, "$key=[]";
next ARRAY;
}
if (@inline) {
my $key = to_toml_key($k);
my $val = to_toml(\@inline, %param);
- push @buff, "$key=$val";
+ push @buff_assign, "$key=$val";
}
# Table values become an array-of-tables
push @KEYS, $k;
for (@table_array) {
- push @buff, '', '[[' . join('.', map{ to_toml_key($_) } @KEYS) . ']]';
- push @buff, to_toml($_);
+ push @buff_tables, '', '[[' . join('.', map{ to_toml_key($_) } @KEYS) . ']]';
+ push @buff_tables, to_toml($_);
}
pop @KEYS;
if (!keys(%{$data->{$k}})) {
# Empty table
my $key = to_toml_key($k);
- push @buff, "$key={}";
+ push @buff_assign, "$key={}";
} else {
# Generate [table]
push @KEYS, $k;
- push @buff, '', '[' . join('.', map{ to_toml_key($_) } @KEYS) . ']';
- push @buff, to_toml($data->{$k}, %param);
+ push @buff_tables, '', '[' . join('.', map{ to_toml_key($_) } @KEYS) . ']';
+ push @buff_tables, to_toml($data->{$k}, %param);
pop @KEYS;
}
}
die "toml: found heterogenous array, but strict_arrays is set ($err)\n" unless $ok;
}
- push @buff, '[' . join(', ', map{ to_toml($_, %param) } @$data) . ']';
+ push @buff_tables, '[' . join(', ', map{ to_toml($_, %param) } @$data) . ']';
}
when ('SCALAR') {
} elsif ($$_ eq '0') {
return 'false';
} else {
- push @buff, to_toml($$_, %param);
+ push @buff_assign, to_toml($$_, %param);
}
}
}
}
- join "\n", @buff;
+ join "\n", @buff_assign, @buff_tables;
}
sub to_toml_key {