Subject: | SuppressEmpty with XMLout should skip undef values |
SuppressEmpty with XMLout doesn't appear to change how undef values are output. They're always output as an empty tag. I have not found a way to change this behavior other than by removing undefs from the data to be output. Am I missing something? Am I dumb? A "yes" to either of those questions is perfectly fine by me.
The documentation says:
----
The option also controls what XMLout() does with undefined values. Setting the option to undef causes undefined values to be output as empty elements (rather than empty attributes), it also suppresses the generation of warnings about undefined values.
----
However I'm unable to figure out how to make empty attributes from undef values.
Test cases:
------------------------
#!/usr/bin/perl
use strict;
use XML::Simple;
use Test::More qw(no_plan);
use Data::Dumper;
my $struct = {
foo => '',
bar => undef,
};
# I'm guessing at what proper behavior should be. To me these values make
# sense, but I'll take whatever works and is documented.
# fails:
my $case1 = XMLout($struct,SuppressEmpty => 1);
ok($case1 =~ !m#<bar>#,"empty element for undef value shouldn't be created with SuppressEmpty => 1");
# fails:
my $case2 = XMLout($struct,SuppressEmpty => '');
ok($case2 =~ !m#<bar>#,"empty element for undef value shouldn't be created with SuppressEmpty => ''");
# passes:
my $case3 = XMLout($struct,SuppressEmpty => undef);
ok($case3 =~ m#<bar>#,"empty element for undef value should be created SuppressEmpty => undef");
# passes:
my $case4 = XMLout($struct);
ok($case4 =~ m#<bar>#,"empty element for undef value should be created with no args");