The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Protocol::XMLRPC - Asynchronous, web framework agnostic XML-RPC implementation

SYNOPSIS

    my $xmlrpc = Protocol::XMLRPC->new(
        http_req_cb => sub {

            ...

            $cb->(..);
        }
    );

    $xmlrpc->call('http://example.com/xmlrpc' => 'plus' => [1, 2] => sub {
            my ($self, $method_response) = @_;

            if (!$method_response) {
                print "internal error\n";
            }
            elsif ($method_response->fault) {
                print 'error: ', $method_response->fault, "\n";
            }
            else {
                print $method_response->param->value, "\n";
            }
        }
    );

DESCRIPTION

Protocol::XMLRPC is asynchronous, web framework agnostic XML-RPC implementation. You provide callback subrouting for posting method request. You can use LWP, Mojo::Client etc for this purpose.

Perl doesn't have scalar types, because of this parameters types are guessed, but you can pass explicit type if guessing is wrong for you. Read more about parameter creation at Protocol::XMLRPC::ValueFactory.

ATTRIBUTES

http_req_cb

    my $xmlrpc = Protocol::XMLRPC->new(
        http_req_cb => sub {
            my ($self, $url, $headers, $body, $cb) = @_;

            ...

            $cb->($self, $status, $headers, $body);

A callback for sending request to the xmlrpc server. Don't forget that User-Agent and Host headers are required by XML-RPC specification. Reqeust method must be POST also.

Callback receives these parameters:

self

Protocol::XMLRPC instance.

url

Server url (for example 'http://example.com/xmlrpc').

body

Request body to send. Holds Protocol::XMLRPC::MethodCall string representation.

cb

Callback that must be called after response was received. Must be provided with Protocol::XMLRPC instance, response status and body.

METHODS

new

    my $xmlrpc = Protocol::XMLRPC->new(http_req_cb => sub { ... });

Creates Protocol::XMLRPC instance. Argument b<http_req_cb> is required.

call

    $xmlrpc->call(
        'http://example.com/xmlrpc' => 'plus' => [1, 2] => sub {
            my ($self, $method_response) = @_;

            ...
        }
    );

Creates Protocol::XMLRPC::MethodCall object with provided parameters and calls http_req_cb with url and body. Upon response parses and created Protocol::XMLRPC::MethodResponse object and calls provided callback.

Parameter are optional. But must be provided as an array reference. Parameters types are guessed (more about that in Protocol::XMLRPC::ValueFactory). If you must pass parameter which type cannot be easily guesed, for example you want to pass 1 as a string, you can pass value instance instead of a value.

    $xmlrpc->call(
        'http://example.com/xmlrpc' => 'getPost' =>
          [Protocol::XMLRPC::Value::String->new(1)] => sub {
            my ($self, $method_response) = @_;

            ...
        }
    );

DEVELOPMENT

Repository

    http://github.com/vti/protocol-xmlrpc/commits/master

AUTHOR

Viacheslav Tikhanovskii, vti@cpan.org.

COPYRIGHT

Copyright (C) 2009, Viacheslav Tikhanovskii.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl 5.10.