RegExp(3)
NAME
RPC::XML - A set of classes for core data, message and XML handling
SYNOPSIS
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;
}
DESCRIPTION
The RPC::XML package is an implementation of the XML-RPC standard.
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 asso-
ciate specific type information with the value. Classes are also pro-
vided for requests, responses, faults (errors) and a parser based on
the XML::Parser package from CPAN.
This module does not actually provide any transport implementation or
server basis. For these, see RPC::XML::Client and RPC::XML::Server,
respectively.
EXPORTABLE FUNCTIONS
At present, three simple 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])
Convert the integer time value in $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)
Converts the passed-in arguments to datatype objects. Any that are
already encoded as such are passed through unchanged. The routine
is called recursively on hash and array references. Note that this
routine can only deduce a certain degree of detail about the values
passed. Boolean values will be wrongly encoded as integers. Pretty
much anything not specifically recognizable will get encoded as a
string object. Thus, for types such as "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.
bytelength([$string])
Returns the length of the string passed in, in bytes rather than
characters. In Perl prior to 5.6.0 when there was little or no
Unicode support, this has no difference from the "length" function.
if the bytes pragme is available, then the length measured is raw
bytes, even when faced with multi-byte characters. If no argument
is passed in, operates on $_.
In addition to these three, the following "helper" functions are also
available. They may be imported explicitly, or via a tag of ":types":
RPC_BOOLEAN RPC_INT RPC_I4 RPC_DOUBLE RPC_DATETIME_ISO8601
RPC_BASE64 RPC_STRING
Each creates a data object of the appropriate type from a single value.
They are merely short-hand for calling the constructors of the data
classes directly.
All of the above (helpers and the first three functions) may be
imported via the tag ":all".
CLASSES
The classes provided by this module are broken into two groups:
datatype classes and message classes.
Data 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 con-
structor returns. It is assumed that a new object would be created,
instead.
The common methods to all data classes are:
new($value)
Constructor. The value passed in is the value to be encapsulated in
the new object.
value
Returns the value kept in the object. Processes recursively for
"array" and "struct" objects.
as_string
Returns the value as a XML-RPC fragment, with the proper tags, etc.
serialize($filehandle)
Send the stringified rendition of the data to the given file han-
dle. This allows messages with arbitrarily-large Base-64 data
within them to be sent without having to hold the entire message
within process memory.
length
Returns the length, in bytes, of the object when serialized into
XML. This is used by the client and server classes to calculate
message length.
type
Returns the type of data being stored in an object. The type
matches the XML-RPC specification, so the normalized form "date-
time_iso8601" comes back as "dateTime.iso8601".
is_fault
All types except the fault class return false for this. This is to
allow consistent testing of return values for fault status, without
checking for a hash reference with specific keys defined.
The classes themselves are:
RPC::XML::int
Creates an integer value. Constructor expects the integer value as
an argument.
RPC::XML::i4
This is like the "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.
RPC::XML::double
Creates a floating-point value.
RPC::XML::string
Creates an arbitrary string. No special encoding is done to the
string (aside from XML document encoding, covered later) with the
exception of the "<", ">" and "&" characters, which are XML-escaped
during object creation, and then reverted when the "value" method
is called.
RPC::XML::boolean
Creates a boolean value. The value returned will always be either
of 1 or 0, for true or false, respectively. When calling the con-
structor, the program may specify any of: 0, "no", "false", 1,
"yes", "true".
RPC::XML::datetime_iso8601
Creates an instance of the XML-RPC "dateTime.iso8601" type. The
specification for ISO 8601 may be found elsewhere. No processing is
done to the data.
RPC::XML::base64
Creates an object that encapsulates a chunk of data that will be
treated as base-64 for transport purposes. The value may be passed
in as either a string or as a scalar reference. Additionally, a
second (optional) parameter may be passed, that if true identifies
the data as already base-64 encoded. If so, the data is decoded
before storage. The "value" method returns decoded data, and the
"as_string" method encodes it before stringification.
Alternately, the constructor may be given an open filehandle argu-
ment instead of direct data. When this is the case, the data is
never read into memory in its entirety, unless the "value" or
"as_string" methods are called. This allows the manipulation of
arbitrarily-large Base-64-encoded data chunks. In these cases, the
flag (optional second argument) is still relevant, but the data is
not pre-decoded if it currently exists in an encoded form. It is
only decoded as needed. Note that the filehandle passed must be
open for reading, at least. It will not be written to, but it will
be read from. The position within the file will be preserved
between operations.
Because of this, this class supports a special method called
"to_file", that takes one argument. The argument may be either an
open, writable filehandle or a string. If it is a string, "to_file"
will attempt to open it as a file and write the decoded data to it.
If the argument is a an open filehandle, the data will be written
to it without any pre- or post-adjustment of the handle position
(nor will it be closed upon completion). This differs from the
"serialize" method in that it always writes the decoded data (where
the other always writes encoded data), and in that the XML opening
and closing tags are not written. The return value of "to_file" is
the size of the data written in bytes.
RPC::XML::array
Creates an array object. The constructor takes zero or more data-
type instances as arguments, which are inserted into the array in
the order specified. "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).
RPC::XML::struct
Creates a struct object, the analogy of a hash table in Perl. The
keys are ordinary strings, and the values must all be data-type
objects. The "value" method returns a hash table reference, with
native Perl types in the values. Key order is not preserved. Key
strings are now encoded for special XML characters, so the use of
such ("<", ">", etc.) should be transparent to the user. 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).
When creating RPC::XML::struct objects, there are two ways to pass
the content in for the new object: Either an existing hash refer-
ence may be passed, or a series of key/value pairs may be passed.
If a reference is passed, the existing data is copied (the refer-
ence is not re-blessed), with the values encoded into new objects
as needed.
RPC::XML::fault
A fault object is a special case of the struct object that checks
to ensure that there are two keys, "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 fol-
lowing accessor methods for directly retrieving the integer code
and error string from a fault object:
code
string
Both names should be self-explanatory. The values returned are Perl
values, not RPC::XML class instances.
Message Classes
The message classes are used both for constructing messages for outgo-
ing communication as well as representing the parsed contents of a
received message. Both implement the following methods:
new This is the constructor method for the two message classes. The
response class may have only a single value (as a response is cur-
rently limited to a single return value), and requests may have as
many arguments as appropriate. In both cases, the arguments are
passed to the exported "smart_encode" routine described earlier.
as_string
Returns the message object expressed as an XML document. The docu-
ment will be lacking in linebreaks and indention, as it is not tar-
geted for human reading.
serialize($filehandle)
Serialize the message to the given file-handle. This avoids creat-
ing the entire XML message within memory, which may be relevant if
there is especially-large Base-64 data within the message.
length
Returns the total size of the message in bytes, used by the client
and server classes to set the Content-Length header.
The two message-object classes are:
RPC::XML::request
This creates a request object. A request object expects the first
argument to be the name of the remote routine being called, and all
remaining arguments are the arguments to that routine. Request
objects have the following methods (besides "new" and "as_string"):
name
The name of the remote routine that the request will call.
args
Returns a list reference with the arguments that will be
passed. No arguments will result in a reference to an empty
list.
RPC::XML::response
The response object is much like the request object in most ways.
It may take only one argument, as that is all the specification
allows for in a response. Responses have the following methods (in
addition to "new" and "as_string"):
value
The value the response is returning. It will be a RPC::XML
data-type.
is_fault
A boolean test whether or not the response is signalling a
fault. This is the same as taking the "value" method return
value and testing it, but is provided for clarity and simplic-
ity.
DIAGNOSTICS
All constructors (in all data classes) return "undef" upon failure,
with the error message available in the package-global variable
$RPC::XML::ERROR.
GLOBAL VARIABLES
The following global variables may be changed to control certain behav-
ior of the library. All variables listed below may be imported into the
application namespace when you "use" RPC::XML:
$ENCODING
This variable controls the character-set encoding reported in out-
going XML messages. It defaults to "us-ascii", but may be set to
any value recognized by XML parsers.
$FORCE_STRING_ENCODING
By default, "smart_encode" uses heuristics to determine what encod-
ing is required for a data type. For example, 123 would be encoded
as "int", where 3.14 would be encoded as "double". In some situa-
tions it may be handy to turn off all these heuristics, and force
encoding of "string" on all data types encountered during encoding.
Setting this flag to "true" will do just that.
Defaults to "false".
CAVEATS
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.
CREDITS
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.
LICENSE
This module is licensed under the terms of the Artistic License that
covers Perl. See <http://www.opensource.org/licenses/artis-
tic-license.php> for the license itself.
SEE ALSO
RPC::XML::Client, RPC::XML::Server, RPC::XML::Parser, XML::Parser
AUTHOR
Randy J. Ray <rjray@blackperl.com>
perl v5.8.8 2006-02-18 RPC::XML(3)
See also RPC::XML::Client(3)
See also RPC::XML::Function(3)
See also RPC::XML::Method(3)
See also RPC::XML::Parser(3)
See also RPC::XML::Procedure(3)
See also RPC::XML::Server(3)
See also XML::Checker(3)
See also XML::Checker::Parser(3)
See also XML::DOM(3)
See also XML::DOM::AttDef(3)
See also XML::DOM::AttlistDecl(3)
See also XML::DOM::Attr(3)
See also XML::DOM::CDATASection(3)
See also XML::DOM::CharacterData(3)
See also XML::DOM::Comment(3)
See also XML::DOM::DOMImplementation(3)
See also XML::DOM::Document(3)
See also XML::DOM::DocumentFragment(3)
See also XML::DOM::DocumentType(3)
See also XML::DOM::Element(3)
See also XML::DOM::ElementDecl(3)
See also XML::DOM::Entity(3)
See also XML::DOM::EntityReference(3)
See also XML::DOM::NamedNodeMap(3)
See also XML::DOM::Node(3)
See also XML::DOM::NodeList(3)
See also XML::DOM::Notation(3)
See also XML::DOM::Parser(3)
See also XML::DOM::PerlSAX(3)
See also XML::DOM::ProcessingInstruction(3)
See also XML::DOM::Text(3)
See also XML::DOM::ValParser(3)
See also XML::DOM::XMLDecl(3)
See also XML::DOM::XPath(3)
See also XML::Dumper(3)
See also XML::ESISParser(3)
See also XML::Encoding(3)
See also XML::Filter::BufferText(3)
See also XML::Filter::DetectWS(3)
See also XML::Filter::Reindent(3)
See also XML::Filter::SAXT(3)
See also XML::Generator(3)
See also XML::Generator::DBI(3)
See also XML::Generator::DOM(3)
See also XML::Generator::PerlData(3)
See also XML::Grove(3)
See also XML::Grove::AsCanonXML(3)
See also XML::Grove::AsString(3)
See also XML::Grove::Builder(3)
See also XML::Grove::Factory(3)
See also XML::Grove::IDs(3)
See also XML::Grove::Path(3)
See also XML::Grove::PerlSAX(3)
See also XML::Grove::Sub(3)
See also XML::Grove::Subst(3)
See also XML::Grove::XPointer(3)
See also XML::Handler::BuildDOM(3)
See also XML::Handler::CanonXMLWriter(3)
See also XML::Handler::Composer(3)
See also XML::Handler::PrintEvents(3)
See also XML::Handler::Sample(3)
See also XML::Handler::Subs(3)
See also XML::Handler::XMLWriter(3)
See also XML::Handler::YAWriter(3)
See also XML::LibXML(3)
See also XML::LibXML::Attr(3)
See also XML::LibXML::Boolean(3)
See also XML::LibXML::CDATASection(3)
See also XML::LibXML::Comment(3)
See also XML::LibXML::Common(3)
See also XML::LibXML::DOM(3)
See also XML::LibXML::Document(3)
See also XML::LibXML::DocumentFragment(3)
See also XML::LibXML::Dtd(3)
See also XML::LibXML::Element(3)
See also XML::LibXML::InputCallback(3)
See also XML::LibXML::Literal(3)
See also XML::LibXML::Namespace(3)
See also XML::LibXML::Node(3)
See also XML::LibXML::NodeList(3)
See also XML::LibXML::Number(3)
See also XML::LibXML::PI(3)
See also XML::LibXML::Parser(3)
See also XML::LibXML::Reader(3)
See also XML::LibXML::RelaxNG(3)
See also XML::LibXML::SAX(3)
See also XML::LibXML::SAX::Builder(3)
See also XML::LibXML::SAX::Generator(3)
See also XML::LibXML::Schema(3)
See also XML::LibXML::Text(3)
See also XML::LibXML::XPathContext(3)
See also XML::LibXSLT(3)
See also XML::NamespaceSupport(3)
See also XML::Parser(3)
See also XML::Parser::Expat(3)
See also XML::Parser::Lite(3)
See also XML::Parser::PerlSAX(3)
See also XML::Parser::Style::Debug(3)
See also XML::Parser::Style::Objects(3)
See also XML::Parser::Style::Stream(3)
See also XML::Parser::Style::Subs(3)
See also XML::Parser::Style::Tree(3)
See also XML::PatAct::ActionTempl(3)
See also XML::PatAct::Amsterdam(3)
See also XML::PatAct::MatchName(3)
See also XML::PatAct::PatternTempl(3)
See also XML::PatAct::ToObjects(3)
See also XML::Perl2SAX(3)
See also XML::RegExp(3)
See also XML::SAX(3)
See also XML::SAX2Perl(3)
See also XML::SAX::Base(3)
See also XML::SAX::DocumentLocator(3)
See also XML::SAX::Exception(3)
See also XML::SAX::Expat(3)
See also XML::SAX::Intro(3)
See also XML::SAX::ParserFactory(3)
See also XML::SAX::PurePerl(3)
See also XML::SAX::PurePerl::Reader(3)
See also XML::SAX::Writer(3)
See also XML::SAX::Writer::XML(3)
See also XML::Sablotron(3)
See also XML::Sablotron::DOM(3)
See also XML::Sablotron::DOM::DOMHandler(3)
See also XML::Sablotron::SAXBuilder(3)
See also XML::Sablotron::Situation::DOMHandlerDispatcher(3)
See also XML::Simple(3)
See also XML::Twig(3)
See also XML::UM(3)
See also XML::Writer(3)
See also XML::Writer::String(3)
See also XML::XPath(3)
See also XML::XPath::Boolean(3)
See also XML::XPath::Builder(3)
See also XML::XPath::Literal(3)
See also XML::XPath::Node(3)
See also XML::XPath::NodeSet(3)
See also XML::XPath::Number(3)
See also XML::XPath::PerlSAX(3)
See also XML::XPath::XMLParser(3)
See also XML::XPathEngine(3)
See also XML::XPathEngine::Boolean(3)
See also XML::XPathEngine::Literal(3)
See also XML::XPathEngine::NodeSet(3)
See also XML::XPathEngine::Number(3)
See also XML::XQL(3)
See also XML::XQL::DOM(3)
See also XML::XQL::Date(3)
See also XML::XQL::Query(3)
See also XML::XQL::Tutorial(3)
See also XML::XSLT(3)
Man(1) output converted with
man2html