Mark Overmeer > XML-Compile-RPC-0.17 > XML::Compile::RPC::Util

Download:
XML-Compile-RPC-0.17.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.17   Source  

NAME ^

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

INHERITANCE ^

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

DESCRIPTION ^

SYNOPSYS ^

 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;

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(RPC-ARRAY)

Remove all array information except the values fron 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.17, built on September 12, 2013. Website: http://perl.overmeer.net/xml-compile/

Other distributions in this suite: XML::Compile, XML::Compile::SOAP, XML::Compile::SOAP12, XML::Compile::SOAP::Daemon, XML::Compile::SOAP::WSA, XML::Compile::C14N, XML::Compile::WSS, XML::Compile::WSS::Signature, XML::Compile::Tester, XML::Compile::Cache, XML::Compile::Dumper, XML::Compile::RPC, XML::Rewrite and XML::LibXML::Simple.

Please post questions or ideas to the mailinglist at http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile . For live contact with other developers, visit the #xml-compile channel on irc.perl.org.

LICENSE ^

Copyrights 2009-2013 by [Mark Overmeer]. 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://www.perl.com/perl/misc/Artistic.html

syntax highlighting: