RPC::XML - A set of classes for core data, message and XML handling
use RPC::XML;
$req = RPC::XML::request->new('fetch_prime_factors', RPC::XML::int->new(985120528)); ... $resp = RPC::XML::Parser->new()->parse(STREAM); if (ref($resp)) { return $resp->value->value; } else { die $resp; }
The RPC::XML package is a reference implementation of the XML-RPC standard. As a reference implementation, it is geared more towards clarity and readability than efficiency.
The package provides a set of classes for creating values to pass to the constructors for requests and responses. These are lightweight objects, most of which are implemented as tied scalars so as to associate specific type information with the value. Classes are also provided for requests, responses, faults (errors) and a parser based on the the XML::Parser manpage package from CPAN.
This module does not actually provide any transport implementation or server basis. For these, see the RPC::XML::Client manpage and the RPC::XML::Server manpage, respectively.
At present, only two functions are available for import. They must be
explicitly imported as part of the use
statement, or with a direct call to
import
:
time2iso8601([$time])
$time
(which defaults to calling the
built-in time
if not present) to a ISO 8601 string in the UTC time
zone. This is a convenience function for occassions when the return value
needs to be of the dateTime.iso8601 type, but the value on hand is the
return from the time
built-in.
smart_encode(@args)
fault
, the ISO
time value, base-64 data, etc., the program must still explicitly encode it.
However, this routine will hopefully simplify things a little bit for a
majority of the usage cases.
The classes provided by this module are broken into two groups: datatype classes and message classes.
The following data classes are provided by this library. Each of these provide at least the set of methods below. Note that these classes are designed to create throw-away objects. There is currently no mechanism for changing the value stored within one of these object after the constructor returns. It is assumed that a new object would be created, instead.
The common methods to all data classes are:
new($value)
array
and
struct
objects.
datetime_iso8601
comes back
as dateTime.iso8601
.
The classes themselves are:
int
class. Note that services written in strictly-typed
languages such as C, C++ or Java may consider the i4
and int
types as
distinct and different.
<
,
>
and &
characters, which are XML-escaped during object creation,
and then reverted when the value
method is called.
0
, no
, false
, 1
, yes
, true
.
dateTime.iso8601
type. The specification
for ISO 8601 may be found elsewhere. No processing is done to the data.
value
method returns decoded data,
and the as_string
method encodes it before stringification.
value
returns an array reference of native Perl types. If a
non-null value is passed as an argument to value()
, then the array
reference will contain datatype objects (a shallow rather than deep copy).
value
method returns a hash table reference, with native Perl types in the values.
Key order is not preserved. Key strings are not encoded for special XML
characters, so the use of such (<
, >
, etc.) is discouraged. If a
non-null value is passed as an argument to value()
, then the hash
reference will contain the datatype objects rather than native Perl data (a
shallow vs. deep copy, as with the array type above).
faultCode
and faultString
.
As a matter of convenience, since the contents of a RPC::XML::fault structure are specifically defined, the constructor may be called with exactly two arguments, the first of which will be taken as the code, and the second as the string. They will be converted to RPC::XML types automatically and stored by the pre-defined key names.
Also as a matter of convenience, the fault class provides the following accessor methods for directly retrieving the integer code and error string from a fault object:
Both names should be self-explanatory. The values returned are Perl values, not RPC::XML class instances.
The message classes are used both for constructing messages for outgoing communication as well as representing the parsed contents of a received message. Both implement the following methods:
smart_encode
routine
described earlier.
The two message-object classes are:
new
and as_string
):
new
and
as_string
):
value
method return value and testing it, but is
provided for clarity and simplicity.
All constructors return undef
upon failure, with the error message available
in the package-global variable $RPC::XML::ERROR
.
This began as a reference implementation in which clarity of process and readability of the code took precedence over general efficiency. It is now being maintained as production code, but may still have parts that could be written more efficiently.
The XML-RPC standard is Copyright (c) 1998-2001, UserLand Software, Inc. See <http://www.xmlrpc.com> for more information about the XML-RPC specification.
This module is licensed under the terms of the Artistic License that covers Perl. See <http://language.perl.com/misc/Artistic.html> for the license itself.
the RPC::XML::Client manpage, the RPC::XML::Server manpage, the RPC::XML::Parser manpage, the XML::Parser manpage
Randy J. Ray <rjray@blackperl.com>