Mark A. Hershberger

NAME

POE::Component::Server::XMLRPC - publish POE event handlers via XMLRPC over HTTP

SYNOPSIS

  use POE;
  use POE::Component::Server::XMLRPC;

  POE::Component::Server::XMLRPC->new( alias => "xmlrpc", port  => 32080 );

  POE::Session->create
    ( inline_states =>
      { _start => \&setup_service,
        _stop  => \&shutdown_service,
        sum_things => \&do_sum,
      }
    );

  $poe_kernel->run;
  exit 0;

  sub setup_service {
    my $kernel = $_[KERNEL];
    $kernel->alias_set("service");
    $kernel->post( xmlrpc => publish => service => "sum_things" );
  }

  sub shutdown_service {
    $_[KERNEL]->post( xmlrpc => rescind => service => "sum_things" );
  }

  sub do_sum {
    my $transaction = $_[ARG0];
    my $params = $transaction->params();
    my $sum = 0;
    for(@{$params}) {
      $sum += $_;
    }
    $transaction->return("Thanks.  Sum is: $sum");
  }

DESCRIPTION

POE::Component::Server::XMLRPC is a bolt-on component that can publish a event handlers via XMLRPC over HTTP.

There are four steps to enabling your programs to support XMLRPC requests. First you must load the component. Then you must instantiate it. Each POE::Component::Server::XMLRPC instance requires an alias to accept messages with and a port to bind itself to. Finally, your program should posts a "publish" events to the server for each event handler it wishes to expose.

  use POE::Component::Server::XMLRPC
  POE::Component::Server::XMLRPC->new( alias => "xmlrpc", port  => 32080 );
  $kernel->post( xmlrpc => publish => session_alias => "methodName" );

Later you can make events private again.

  $kernel->post( xmlrpc => rescind => session_alias => "methodName" );

Finally you must write the XMLRPC request handler. XMLRPC handlers receive a single parameter, ARG0, which contains a XMLRPC transaction object. The object has two methods: params(), which returns a reference to the XMLRPC parameters; and return(), which returns its parameters to the client as a XMLRPC response.

  sum_things => sub {
    my $transaction = $_[ARG0];
    my $params = $transaction->params();
    my $sum = 0;
    while (@{$params})
      $sum += $value;
    }
    $transaction->return("Thanks.  Sum is: $sum");
  }

And here is a sample XMLRPC::Lite client. It should work with the server in the SYNOPSIS.

  #!/usr/bin/perl

  use warnings;
  use strict;

  use XMLRPC::Lite;

  print XMLRPC::Lite
    -> proxy('http://poe.dynodns.net:32080/?session=sum_server')
    -> sum_things(8,6,7,5,3,0,9)
    -> result
    ;
  pring "\n";

BUGS

This project is a modified version of POE::Component::Server::SOAP by Rocco Caputo. Of that, he writes:

  This project was created over the course of two days, which attests to
  the ease of writing new POE components.  However, I did not learn XMLRPC
  in depth, so I am probably not doing things the best they could.

Thanks to his code, I've managed to create this module in one day (on only my second day of using POE). There's gotta be bugs here. Please use http://rt.cpan.org/ to report them.

SEE ALSO

The examples directory that came with this component.

XMLRPC::Lite POE::Component::Server::SOAP POE::Component::Server::HTTP POE

AUTHOR & COPYRIGHTS

POE::Component::Server::XMLRPC is Copyright 2002 by Mark A. Hershberger. All rights are reserved. POE::Component::Server::XMLRPC is free software; you may redistribute it and/or modify it under the same terms as Perl itself.