NAME

XML::Compile::RPC::Util - XML-RPC convenience functions

INHERITANCE

XML::Compile::RPC::Util
  is a Exporter

SYNOPSIS

use XML::Compile::RPC::Util;

my $h  = struct_to_hash $d->{struct};
my @r  = struct_to_rows $d->{struct};
my $d  = struct_from_rows @r;
my $d  = struct_from_hash int => %h;

my @a  = rpcarray_values $d->{array};
my $d  = rpcarray_from int => @a;

my $rc = fault_code $d->{fault};
my ($rc, $rcmsg) = fault_code $d->{fault};

my $d  = fault_from $rc, $msg;

DESCRIPTION

Functions

Struct

struct_from_hash($type, HASH)

Only usable when all key-value pairs are of the same type, usually string. The keys are included alphabetically.

example:

my $data = struct_from_hash int => { begin => 3, end => 5 };
struct_from_rows($row, $row, ...)

Each $row is an ARRAY which contains member name, member type, and member value. Returned is a structure.

example:

$d = struct_from_rows [symbol => string => 'RHAT']
                    , [limit => double => 2.25];
print Dumper $d;

prints:

{ struct => { member =>
   [ { name => 'symbol', value => {string => 'RHAT' }}
   , { name => 'limit', value => {double => 2.25} }
   ] }};

which will become in XML

<struct>
  <member>
    <name>symbol</name>
    <value><string>RHAT</string></value>
  </member>
  <member>
    <name>limit</name>
    <value><double>2.25</double></value>
  </member>
</struct>
struct_to_hash($struct)

Returns a HASH containing the structure information. The order of the keys and type of the values is lost. When keys appear more than once, only the last one is kept.

example:

if(my $s = $d->{struct})
{   my $h = struct_to_hash $s;
    print "$h->{limit}\n";
}
struct_to_rows($struct)

Returns a LIST of all the members of the structure. Each element of the returned LIST is an ARRAY with contains three fields: member name, member type and member value.

example:

if(my $s = $d->{struct})
{   my @rows = struct_to_rows $s;
    foreach my $row (@rows)
    {   my ($key, $type, $value) = @$row;
        print "$key: $value ($type)\n";
    }
}

Array

rpcarray_from($type, LIST)

Construct an rpc-array structure from a LIST of values. These values must all have the same type.

example:

my $d = rpcarray_from int => @a;
rpcarray_values(ARRAY)

Remove all array information except the values from an rpc-ARRAY structure. Actually, only the type information is lost: the other components of the complex XML structure are overhead.

example:

if(my $a = $d->{array})
{   my @v = rpcarray_values $a;
}

Faults

fault_code($data)

In LIST context, it returns both the integer faultCode as the corresponding faultString. In SCALAR context, only the code.

When the faultCode is 0, the value of -1 will be returned. Some servers (like ExistDB 1.4) accidentally forget to set a good numeric value.

example:

if(my $f = $d->{fault})
{    my ($rc, $rcmsg) = fault_code $f;
     my $rc = fault_code $f;
}
fault_from(CODE, STRING)

Construct a fault structure from an error code and the related error $string.

example:

my $d = fault_from 42,'no answer';

SEE ALSO

This module is part of XML-Compile-RPC distribution version 0.20, built on January 15, 2020. Website: http://perl.overmeer.net/xml-compile/

LICENSE

Copyrights 2009-2020 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/