Skip Menu |
 

This queue is for tickets about the RPC-XML CPAN distribution.

Report information
The Basics
Id: 34132
Status: resolved
Priority: 0/
Queue: RPC-XML

People
Owner: rjray [...] blackperl.com
Requestors: joey [...] kitenet.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 0.65



Subject: support for the nil extension
Download (untitled) / with headers
text/plain 584b
Lots of RPC-XML libraries support an extension for a nil data type (corresponding to undef). The extension is documented here: <http://ontosys.com/xml-rpc/extensions.php> For example, python supports it via an "allow_none" flag, and I think the RPC-Xmlrpc_c module supports it by default. I would really like to be able to use this in my XML::RPC using program, so I wrote the attached patch. I parameterised it so that nil is only emitted or parsed once $RPC::XML::ALLOW_NIL is set. I understand that there might be a release coming up. Please consider adding this to the release.
Subject: nil.patch
Download nil.patch
text/x-diff 3.6k
diff -ur old/librpc-xml-perl-0.59/lib/RPC/XML/Parser.pm librpc-xml-perl-0.59/lib/RPC/XML/Parser.pm --- old/librpc-xml-perl-0.59/lib/RPC/XML/Parser.pm 2006-06-04 03:44:41.000000000 -0400 +++ librpc-xml-perl-0.59/lib/RPC/XML/Parser.pm 2008-03-16 13:34:06.000000000 -0400 @@ -205,7 +205,7 @@ { push(@{$robj->{stack}}, TAG2TOKEN->{$elem}); } - elsif (VALIDTYPES->{$elem}) + elsif (VALIDTYPES->{$elem} || ($elem eq 'nil' && $RPC::XML::ALLOW_NIL)) { # All datatypes are represented on the stack by this generic token push(@{$robj->{stack}}, DATATYPE); @@ -283,7 +283,7 @@ $op = pop(@{$robj->{stack}}); # Decide what to do from here - if (VALIDTYPES->{$elem}) + if (VALIDTYPES->{$elem} || ($elem eq 'nil' && $RPC::XML::ALLOW_NIL)) { # This is the closing tag of one of the data-types. $class = $elem; diff -ur old/librpc-xml-perl-0.59/lib/RPC/XML.pm librpc-xml-perl-0.59/lib/RPC/XML.pm --- old/librpc-xml-perl-0.59/lib/RPC/XML.pm 2006-06-30 03:36:29.000000000 -0400 +++ librpc-xml-perl-0.59/lib/RPC/XML.pm 2008-03-16 13:39:27.000000000 -0400 @@ -28,7 +28,8 @@ use 5.005; use strict; use vars qw(@EXPORT @EXPORT_OK %EXPORT_TAGS @ISA $VERSION $ERROR - %xmlmap $xmlre $ENCODING $FORCE_STRING_ENCODING); + %xmlmap $xmlre $ENCODING $FORCE_STRING_ENCODING + $ALLOW_NIL); use subs qw(time2iso8601 smart_encode bytelength); # The following is cribbed from SOAP::Lite, tidied up to suit my tastes @@ -57,6 +58,9 @@ # force strings? $FORCE_STRING_ENCODING = 0; + + # allow use of the nonstandard nil type? + $ALLOW_NIL = 0; } require Exporter; @@ -121,7 +125,14 @@ { if (!defined $_) { - $type = RPC::XML::string->new(''); + if (! $ALLOW_NIL) + { + $type = RPC::XML::string->new(''); + } + else + { + $type = RPC::XML::nil->new(); + } } elsif (ref $_) { @@ -403,6 +414,39 @@ ############################################################################### # +# Package: RPC::XML::nil +# +# Description: The "nil" type-class extension +# +############################################################################### +package RPC::XML::nil; + +use strict; +use vars qw(@ISA); + +@ISA = qw(RPC::XML::simple_type); + +# no value need be passed to this method +sub new +{ + my $class = shift; + my $value = undef; + + if (! $RPC::XML::ALLOW_NIL) { + die "\$RPC::XML::ALLOW_NIL must be set for RPC::XML::nil objects to be supported"; + } + + bless \$value, $class; +} + +# serialsation is trivial.. +sub as_string +{ + "<nil/>"; +} + +############################################################################### +# # Package: RPC::XML::array # # Description: This class encapsulates the array data type. Each element @@ -1464,6 +1508,15 @@ Creates an instance of the XML-RPC C<dateTime.iso8601> type. The specification for ISO 8601 may be found elsewhere. No processing is done to the data. +=item RPC::XML::nil + +Creates a nil value. The value returned will always be undef. No value +needs to be passed when calling the constructor. + +Note that nil is an extension to B<XML-RPC>, which is not supported by all +implementations. $ALLOW_NIL must be set before objects of this type can be +constructed. + =item RPC::XML::base64 Creates an object that encapsulates a chunk of data that will be treated as @@ -1658,6 +1711,11 @@ Defaults to C<false>. +=item $ALLOW_NIL + +By default, the XML-RPC nil extension is not supported. Set to allow +use of nil values, which will be represented as perl undef values. + =back =head1 CAVEATS
Download (untitled) / with headers
text/plain 583b
Based on the documentation you reference in the URL, I will add this at a future point (not the release I am currently working on, as I will want to make sure I have this properly supported with docs and tests). Most likely I will aim for the next release after the one I am hoping to release today(-ish). I also have a pending request for an "I8/INT8" datatype, which I may or may not roll into this ticket. (There's no actual ticket open for it at the moment.) I have a patch from someone, but it doesn't fit with other changes to RPC::XML I've made recently (and it has no tests).
Download (untitled) / with headers
text/plain 214b
Oops, I do in fact have an open ticket for the i8 tag: http://rt.cpan.org/Ticket/Display.html?id=30354 Neither are being marked as dependent on the other, but I wanted to correct my comment in the previous update.
Download (untitled) / with headers
text/plain 199b
Just wondered if there was any update on when this patch might make it into a release? It'd be extremely useful esp as the other perl xmlrpc modules don't seem to support the nil extension Thanks
Download (untitled) / with headers
text/plain 681b
I was hoping to finish my full-on encoding support, but day-job duties are slowing me down. I've committed some band-aid encoding fixes, and I'm integrating your patch now. I'm adding some additional documentation and functionality (like a RPC_NIL shortcut function), and will add some tests to cover it as well. At that point, I have one other RT ticket for which I've been provided a patch that I want to integrate. Once I have that, I'll cut a 0.65 release and upload it. -- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Randy J. Ray Silicon Valley Scale Modelers: http://www.svsm.org rjray@blackperl.com randy.j.ray@gmail.com
Download (untitled) / with headers
text/plain 205b
-- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Randy J. Ray Silicon Valley Scale Modelers: http://www.svsm.org rjray@blackperl.com randy.j.ray@gmail.com


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.