Create xml-rpc listeners for normal cgi processes
use Frontier::Responder; my $res = Frontier::Responder->new( methods => { add => sub{ $_[0] + $_[1] }, cat => sub{ $_[0] . $_[1] }, }, ); print $res->answer;
Use Frontier::Responder whenever you need to create an XML-RPC listener using a standard \s-1CGI\s0 interface. To be effective, a script using this class will often have to be put a directory from which a web server is authorized to execute \s-1CGI\s0 programs. An XML-RPC listener using this library will be implementing the \s-1API\s0 of a particular XML-RPC application. Each remote procedure listed in the \s-1API\s0 of the user defined application will correspond to a hash key that is defined in the \*(C`new\*(C' method of a Frontier::Responder object. This is exactly the way Frontier::Daemon works as well. In order to process the request and get the response, the \*(C`answer\*(C' method is needed. Its return value is \s-1XML\s0 ready for printing.
For those new to XML-RPC, here is a brief description of this protocol. XML-RPC is a way to execute functions on a different machine. Both the client's request and listeners response are wrapped up in \s-1XML\s0 and sent over \s-1HTTP\s0. Because the XML-RPC conversation is in \s-1XML\s0, the implementation languages of the server (here called a listener), and the client can be different. This can be a powerful and simple way to have very different platforms work together without acrimony. Implicit in the use of XML-RPC is a contract or \s-1API\s0 that an XML-RPC listener implements and an XML-RPC client calls. The \s-1API\s0 needs to list not only the various procedures that can be called, but also the XML-RPC datatypes expected for input and output. Remember that although Perl is permissive about datatyping, other languages are not. Unforuntately, the XML-RPC spec doesn't say how to document the \s-1API\s0. It is recomended that the author of a Perl XML-RPC listener should at least use \s-1POD\s0 to explain the \s-1API\s0. This allows for the programmatic generation of a clean web page.
This is the class constructor. As is traditional, it returns a blessed reference to a Frontier::Responder object. It expects arguments to be given like a hash (Perl's named parameter mechanism). To be effective, populate the \*(C`methods\*(C' parameter with a hashref that has \s-1API\s0 procedure names as keys and subroutine references as values. See the \s-1SYNOPSIS\s0 for a sample usage.
In order to parse the request and execute the procedure, this method must be called. It returns a \s-1XML\s0 string that contains the procedure's response. In a typical \s-1CGI\s0 program, this string will simply be printed to \s-1STDOUT\s0.
perl\|(1), Frontier::RPC2\|(3)
<http://www.scripting.com/frontier5/xml/code/rpc.html>
Ken MacLeod <[email protected]> wrote the underlying \s-1RPC\s0 library.
Joe Johnston <[email protected]> wrote an adaptation of the Frontier::Daemon class to create this \s-1CGI\s0 XML-RPC listener class.