Package: librpc-xml-perl
Version: 0.59-2
Severity: normal
Tags: patch

RPC-XML has the limitation that there is no support for the nil type,
which corresponds to perl's undef, python's None, and C's NULL. There is
an extension that defines this simple type, at
<http://ontosys.com/xml-rpc/extensions.php>

Many other RPC-XML libraries support this at least optionally. For
example, in python, there is an allow_none flag. The RPC-Xmlrpc_c perl
module (not packaged) supports nil. 

I needed it in RPC::XML, so I developed the attached patch. I took care
to not have it emit or parse "<nil/>" unless $RPC::XML::ALLOW_NIL is set
to 1.

Please consider applying this patch, and encoruaging upstream to do so
as well.

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-1-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages librpc-xml-perl depends on:
ii  libwww-perl                   5.808-1    WWW client/server library for Perl
ii  libxml-parser-perl            2.36-1     Perl module for parsing XML files
ii  perl                          5.8.8-12   Larry Wall's Practical Extraction 

librpc-xml-perl recommends no packages.

-- no debconf information

-- 
see shy jo
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);
+
[EMAIL PROTECTED] = 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

Attachment: signature.asc
Description: Digital signature

Reply via email to