summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/external.pm
diff options
context:
space:
mode:
authormartin f. krafft <madduck@madduck.net>2008-03-21 19:12:12 +0100
committerJoey Hess <joey@kodama.kitenet.net>2008-03-21 15:07:10 -0400
commite3624de63c799427fbd95fa5bbef9462f95912c6 (patch)
tree532425e6ec54e0d039091582f44782081353f8ef /IkiWiki/Plugin/external.pm
parent99fce0af0d4e99bc81ef7847bfbe77662763e805 (diff)
Allow external plugins to return no value
Instead of using the XML-RPC v2 extension <nil/>, which Perl's XML::RPC::Parser does not (yet) support (Joey's patch is pending), we agreed on a sentinel: {'null':''}, that is, a hash with a single key "null" pointing to the empty string. The Python proxy automatically converts None appropriately and raises an exception if a hook function should, by weird coincidence, attempt to return {'null':''}. Signed-off-by: martin f. krafft <madduck@madduck.net>
Diffstat (limited to 'IkiWiki/Plugin/external.pm')
-rw-r--r--IkiWiki/Plugin/external.pm25
1 files changed, 24 insertions, 1 deletions
diff --git a/IkiWiki/Plugin/external.pm b/IkiWiki/Plugin/external.pm
index 4c2e5d2fe..204442c1e 100644
--- a/IkiWiki/Plugin/external.pm
+++ b/IkiWiki/Plugin/external.pm
@@ -68,7 +68,22 @@ sub rpc_call ($$;@) { #{{{
return @{$value->value};
}
elsif ($value->isa('RPC::XML::struct')) {
- return %{$value->value};
+ my %hash=%{$value->value};
+
+ # XML-RPC v1 does not allow for
+ # nil/null/None/undef values to be
+ # transmitted, so until
+ # XML::RPC::Parser honours v2
+ # (<nil/>), external plugins send
+ # a hash with one key "null" pointing
+ # to an empty string.
+ if (exists $hash{null} &&
+ $hash{null} eq "" &&
+ int(keys(%hash)) == 1) {
+ return undef;
+ }
+
+ return %hash;
}
else {
return $value->value;
@@ -92,6 +107,14 @@ sub rpc_call ($$;@) { #{{{
error("XML RPC call error, unknown function: $name");
}
+ # XML-RPC v1 does not allow for nil/null/None/undef
+ # values to be transmitted, so until XML::RPC::Parser
+ # honours v2 (<nil/>), send a hash with one key "null"
+ # pointing to an empty string.
+ if (! defined $ret) {
+ $ret={"null" => ""};
+ }
+
my $string=eval { RPC::XML::response->new($ret)->as_string };
if ($@ && ref $ret) {
# One common reason for serialisation to