FAQ
Hi,

A new member of my ever growing XML::Compile family. I am working on
a high-level eXistDB (pure XML database) interface which uses XML-RPC
(not SOAP-RPC). This implementation follows the strict XML::Compile
style and rules.

There is no official schema for XML-RPC, but someone gave me a good
starting-point. The real implementation based on that schema took only
about 20 lines of code. But some more lines were spent to solve type
incompatibilities and offer powerful helper routines to avoid typing
deeply nest HASHes by hand.

** Basic interface

my $rpc = XML::Compile::RPC::Client->new(destination => $service_uri);

Passing two simple parameters:

my ($rc, $answer) = $rpc->call('getQuote', string => 'IBM', int => '5');

Same via autoload:

my ($rc, $answer) = $rpc->getQuote(string => 'IBM', int => '5');

Passing parameters as HASH-like "structs":

my $data = struct_from_hash string => { symbol => 'IBM' };
my ($rc, $answer) = $rpc->call('getQuote', $data);
my ($rc, $answer) = $rpc->call(getQuote => $data);
my ($rc, $answer) = $rpc->getQuote($data);

With various helper functions.

** Abstraction

My advice: if you have to use XML-RPC, first create an abstraction
layer like this:

package My::Service;
use base 'XML::Compile::RPC::Client';

sub getQuote($)
{ my ($self, $symbol) = @_;
my $params = struct_from_hash string => { symbol => $symbol };
my ($rc, $data) = $self->call(getQuote => $params);
$rc==0 or die "error: $data ($rc)";
# now simplify $data
$data;
}

Now, the main program runs like this:

my $service = My::Service->new(destination => $uri);
my $price = $service->getQuote('IBM');


** Comparison

The M<XML::RPC> module uses the M<XML::TreePP> XML parser and parameter type
guessing, where XML::Compile::RPC uses strict typed and validated XML
via XML::LibXML: smaller chance on unexpected behavior.

M<XML::RPC::Fast> is compatible with XML::RPC, but uses M<XML::LibXML> which
is faster and safer. It implements "manually" what M<XML::Compile> offers
for free in XML::Compile::RPC. Getting the types of the parameters right
is difficult for other things than strings and numbers.

Finally, M<RPC::XML> makes you handle parameters as object: create a typed
object for each passed value. It offers a standard method signatures to
simplify that task.

There are many ways to do it.
--
Regards,

MarkOv

------------------------------------------------------------------------
Mark Overmeer MSc MARKOV Solutions
Mark@Overmeer.net solutions@overmeer.net
http://Mark.Overmeer.net http://solutions.overmeer.net

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupxml-compile @
postedOct 24, '09 at 8:35p
activeOct 24, '09 at 8:35p
posts1
users1
websiteperl.overmeer.net...

1 user in discussion

Mark Overmeer: 1 post

People

Translate

site design / logo © 2022 Grokbase