SYNOPSIS

 use Frontier::RPC2;

 $coder = Frontier::RPC2->new;

 $xml_string = $coder->encode_call($method, @args);
 $xml_string = $coder->encode_response($result);
 $xml_string = $coder->encode_fault($code, $message);

 $call = $coder->decode($xml_string);

 $response_xml = $coder->serve($request_xml, $methods);

 $boolean_object = $coder->boolean($boolean);
 $date_time_object = $coder->date_time($date_time);
 $base64_object = $coder->base64($base64);
 $int_object = $coder->int(42);
 $float_object = $coder->float(3.14159);
 $string_object = $coder->string("Foo");

DESCRIPTION

Frontier::RPC2 encodes and decodes \s-1XML\s0 \s-1RPC\s0 calls. Create a new encoder/decoder. The following option is supported:

encoding

The \s-1XML\s0 encoding to be specified in the \s-1XML\s0 declaration of encoded \s-1RPC\s0 requests or responses. Decoded results may have a different encoding specified; XML::Parser will convert decoded data to \s-1UTF-8\s0. The default encoding is none, which uses \s-1XML\s0 1.0's default of \s-1UTF-8\s0. For example: $server = Frontier::RPC2->new( 'encoding' => 'ISO-8859-1' );

use_objects

If set to a non-zero value will convert incoming <i4>, <float>, and <string> values to objects instead of scalars. See int(), float(), and string() below for more details.

`\*(C`encode_call\*(C'' converts a method name and it's arguments into an \s-1RPC2\s0 `\*(C`methodCall\*(C'' element, returning the \s-1XML\s0 fragment. `\*(C`encode_response\*(C'' converts the return value of a procedure into an \s-1RPC2\s0 `\*(C`methodResponse\*(C'' element containing the result, returning the \s-1XML\s0 fragment. `\*(C`encode_fault\*(C'' converts a fault code and message into an \s-1RPC2\s0 `\*(C`methodResponse\*(C'' element containing a `\*(C`fault\*(C'' element, returning the \s-1XML\s0 fragment. `\*(C`decode\*(C'' converts an \s-1XML\s0 string containing an \s-1RPC2\s0 `\*(C`methodCall\*(C'' or `\*(C`methodResponse\*(C'' element into a hash containing three members, `\*(C`type\*(C'', `\*(C`value\*(C'', and `\*(C`method_name\*(C''. `\*(C`type\*(C'' is one of `\*(C`call\*(C'', `\*(C`response\*(C'', or `\*(C`fault\*(C''. `\*(C`value\*(C'' is array containing the parameters or result of the \s-1RPC\s0. For a `\*(C`call\*(C'' type, `\*(C`value\*(C'' contains call's parameters and `\*(C`method_name\*(C'' contains the method being called. For a `\*(C`response\*(C'' type, the `\*(C`value\*(C'' array contains call's result. For a `\*(C`fault\*(C'' type, the `\*(C`value\*(C'' array contains a hash with the two members `\*(C`faultCode\*(C'' and `\*(C`faultMessage\*(C''. `\*(C`serve\*(C'' decodes `$request_xml', looks up the called method name in the `$methods' hash and calls it, and then encodes and returns the response as \s-1XML\s0. These methods create and return XML-RPC-specific datatypes that can be passed to the encoder. The decoder may also return these datatypes. The corresponding package names (for use with `\*(C`ref()\*(C'', for example) are `\*(C`Frontier::RPC2::Boolean\*(C'', `\*(C`Frontier::RPC2::DateTime::ISO8601\*(C'', and `\*(C`Frontier::RPC2::Base64\*(C''. You can change and retrieve the value of boolean, date/time, and base64 data using the `\*(C`value\*(C'' method of those objects, i.e.: $boolean = $boolean_object->value;

$boolean_object->value(1); Note: `\*(C`base64()\*(C'' does not encode or decode base64 data for you, you must use MIME::Base64 or similar module for that. By default, you may pass ordinary Perl values (scalars) to be encoded. \s-1RPC2\s0 automatically converts them to XML-RPC types if they look like an integer, float, or as a string. This assumption causes problems when you want to pass a string that looks like \*(L"0096\*(R", \s-1RPC2\s0 will convert that to an <i4> because it looks like an integer. With these methods, you could now create a string object like this: $part_num = $coder->string("0096"); and be confident that it will be passed as an XML-RPC string. You can change and retrieve values from objects using value() as described above.

RELATED TO Frontier::RPC2…

perl\|(1), Frontier::Daemon\|(3), Frontier::Client\|(3)

<http://www.scripting.com/frontier5/xml/code/rpc.html>

AUTHOR

Ken MacLeod <[email protected]>