Subject: | RPC-XML encodes any string into RPC::XML::double that looks like a decimal |
Date: | Fri, 8 Apr 2016 20:07:56 +0200 |
To: | bug-RPC-XML [...] rt.cpan.org |
From: | Markus Wernig <markus [...] wernig.net> |
Hi all
RPC-XML version: 0.77
Perl version: 5.20.1
OS: Gentoo Linux
I found the following behaviour in RPC-XML:
Whenever a variable that looks like a decimal is prepared into an
RPC::XML::* class for sending to the server, it gets encoded as a
RPC::XML::double. There seems to be no way to prevent this.
Sample code:
use Data::Dumper;
use RPC::XML;
use RPC::XML::Client;
my $value = "123.4";
my $hash = {
MyValue => "$val"
};
my $parsed = RPC::XML::struct->new($hash);
print "parsed: " . Dumper($parsed);
This results in something like
parsed: $VAR1 = bless( {
'MyValue' => bless( do{\(my $o = '123.4')}, 'RPC::XML::double' )
}, 'RPC::XML::struct' );
On the receiving end, the value is then decoded and passed to the
application as
{
MyValue => '123.40000000000000568434'
}
This is perfectly fine for real decimals, which can be rounded on the
server before using them.
But what if the value was not intended as a decimal, but as a literal
string? In my case, there are object identifiers (documents, references
etc.) that are versioned in the format $major.$minor, with both $major
and $minor being numbers, and I cannot simply round them back to a
meaningful value after receiving them on the server, as version 123.4 is
quite different from version 123.40.
I think there should be a way to override the autodetection of those
data types, or maybe there is another solution?
Thanks for looking into this.
Kind regards
Markus
--
Markus Wernig
Unix/Network Security Engineer
PGP: 8E82E4DC
-----------------------------------------
http://xfer.ch - http://markus.wernig.net
-----------------------------------------