1Frontier::RPC2(3) User Contributed Perl Documentation Frontier::RPC2(3)
2
3
4
6 Frontier::RPC2 - encode/decode RPC2 format XML
7
9 use Frontier::RPC2;
10
11 $coder = Frontier::RPC2->new;
12
13 $xml_string = $coder->encode_call($method, @args);
14 $xml_string = $coder->encode_response($result);
15 $xml_string = $coder->encode_fault($code, $message);
16
17 $call = $coder->decode($xml_string);
18
19 $response_xml = $coder->serve($request_xml, $methods);
20
21 $boolean_object = $coder->boolean($boolean);
22 $date_time_object = $coder->date_time($date_time);
23 $base64_object = $coder->base64($base64);
24 $int_object = $coder->int(42);
25 $float_object = $coder->float(3.14159);
26 $string_object = $coder->string("Foo");
27
29 Frontier::RPC2 encodes and decodes XML RPC calls.
30
31 $coder = Frontier::RPC2->new( OPTIONS )
32 Create a new encoder/decoder. The following option is supported:
33
34 encoding
35 The XML encoding to be specified in the XML declaration of
36 encoded RPC requests or responses. Decoded results may have a
37 different encoding specified; XML::Parser will convert decoded
38 data to UTF-8. The default encoding is none, which uses XML
39 1.0's default of UTF-8. For example:
40
41 $server = Frontier::RPC2->new( 'encoding' => 'ISO-8859-1' );
42
43 use_objects
44 If set to a non-zero value will convert incoming <i4>, <float>,
45 and <string> values to objects instead of scalars. See int(),
46 float(), and string() below for more details.
47
48 $xml_string = $coder->encode_call($method, @args)
49 `"encode_call"' converts a method name and it's arguments into an
50 RPC2 `"methodCall"' element, returning the XML fragment.
51
52 $xml_string = $coder->encode_response($result)
53 `"encode_response"' converts the return value of a procedure into
54 an RPC2 `"methodResponse"' element containing the result, returning
55 the XML fragment.
56
57 $xml_string = $coder->encode_fault($code, $message)
58 `"encode_fault"' converts a fault code and message into an RPC2
59 `"methodResponse"' element containing a `"fault"' element,
60 returning the XML fragment.
61
62 $call = $coder->decode($xml_string)
63 `"decode"' converts an XML string containing an RPC2 `"methodCall"'
64 or `"methodResponse"' element into a hash containing three members,
65 `"type"', `"value"', and `"method_name"'. `"type"' is one of
66 `"call"', `"response"', or `"fault"'. `"value"' is array
67 containing the parameters or result of the RPC. For a `"call"'
68 type, `"value"' contains call's parameters and `"method_name"'
69 contains the method being called. For a `"response"' type, the
70 `"value"' array contains call's result. For a `"fault"' type, the
71 `"value"' array contains a hash with the two members `"faultCode"'
72 and `"faultMessage"'.
73
74 $response_xml = $coder->serve($request_xml, $methods)
75 `"serve"' decodes `$request_xml', looks up the called method name
76 in the `$methods' hash and calls it, and then encodes and returns
77 the response as XML.
78
79 $boolean_object = $coder->boolean($boolean);
80 $date_time_object = $coder->date_time($date_time);
81 $base64_object = $coder->base64($base64);
82 These methods create and return XML-RPC-specific datatypes that can
83 be passed to the encoder. The decoder may also return these
84 datatypes. The corresponding package names (for use with
85 `"ref()"', for example) are `"Frontier::RPC2::Boolean"',
86 `"Frontier::RPC2::DateTime::ISO8601"', and
87 `"Frontier::RPC2::Base64"'.
88
89 You can change and retrieve the value of boolean, date/time, and
90 base64 data using the `"value"' method of those objects, i.e.:
91
92 $boolean = $boolean_object->value;
93
94 $boolean_object->value(1);
95
96 Note: `"base64()"' does not encode or decode base64 data for you,
97 you must use MIME::Base64 or similar module for that.
98
99 $int_object = $coder->int(42);
100 $float_object = $coder->float(3.14159);
101 $string_object = $coder->string("Foo");
102 By default, you may pass ordinary Perl values (scalars) to be
103 encoded. RPC2 automatically converts them to XML-RPC types if they
104 look like an integer, float, or as a string. This assumption
105 causes problems when you want to pass a string that looks like
106 "0096", RPC2 will convert that to an <i4> because it looks like an
107 integer. With these methods, you could now create a string object
108 like this:
109
110 $part_num = $coder->string("0096");
111
112 and be confident that it will be passed as an XML-RPC string. You
113 can change and retrieve values from objects using value() as
114 described above.
115
117 perl(1), Frontier::Daemon(3), Frontier::Client(3)
118
119 <http://www.scripting.com/frontier5/xml/code/rpc.html>
120
122 Ken MacLeod <ken@bitsko.slc.ut.us>
123
124
125
126perl v5.32.0 2020-07-28 Frontier::RPC2(3)