RPC-XML
view release on metacpan or search on metacpan
lib/RPC/XML/Server.pm view on Meta::CPAN
=head2 How Procedures Are Called
When a routine is called via the server dispatcher, it is called with the
arguments that the client request passed. Depending on whether the routine is
considered a "function", a "procedure" or a "method", there may be an extra
argument at the head of the list. The extra argument is present when the
routine being dispatched is part of a B<RPC::XML::Method> object. The extra
argument is a reference to a B<RPC::XML::Server> object (or a subclass
thereof). This is derived from a hash reference, and will include these special
keys:
=over 4
=item method_name
This is the name by which the method was called in the client. Most of the
time, this will probably be consistent for all calls to the server-side
method. But it does not have to be, hence the passing of the value.
=item signature
This is the signature that was used, when dispatching. Perl has a liberal
view of lists and scalars, so it is not always clear what arguments the client
specifically has in mind when calling the method. The signature is an array
reference containing one or more datatypes, each a simple string. The first
of the datatypes specifies the expected return type. The remainder (if any)
refer to the arguments themselves.
=item peerfamily
This is the address family, C<AF_INET> or C<AF_INET6>, of a network address of
the client that has connected and made the current request. It is required
for unpacking C<peeraddr> properly.
=item peeraddr
This is the address part of a packed B<SOCKADDR_IN> or B<SOCKADDR_IN6>
structure, as returned by L<Socket/pack_sockaddr_in> or
L<Socket/pack_sockaddr_in6>, which contains the address of the client that has
connected and made the current request. This is provided "raw" in case you
need it. While you could re-create it from C<peerhost>, it is readily
available in both this server environment and the B<Apache::RPC::Server>
environment and thus included for convenience. Apply L<Socket/inet_ntop> to
C<peerfamily> and this value to obtain textual representation of the address.
=item peerhost
This is the address of the remote (client) end of the socket, in C<x.x.x.x>
(dotted-quad) format. If you wish to look up the clients host-name, you
can use this to do so or utilize the encoded structure above directly.
=item peerport
This is the port of the remote (client) end of the socket, taken from the
B<SOCKADDR_IN> structure.
=item request
The L<HTTP::Request|HTTP::Request> object for this request. Can be used to read
HTTP headers sent by the client (C<X-Forwarded-For> for your access checks, for
example).
=back
Those keys should only be referenced within method code itself, as they are
not set on the server object outside of that context.
Note that by passing the server object reference first, method-classed
routines are essentially expected to behave as actual methods of the server
class, as opposed to ordinary functions. Of course, they can also discard the
initial argument completely.
The routines should not make (excessive) use of global variables, for obvious
reasons. When the routines are loaded from XPL files, the code is created as a
closure that forces execution in the B<RPC::XML::Procedure> package (unless the
XPL specifies a namespace, see L<RPC::XML::Procedure|RPC::XML::Procedure>). If
the code element of a procedure/method is passed in as a direct code reference
by one of the other syntaxes allowed by the constructor, the package may well
be different. Thus, routines should strive to be as localized as possible,
independent of specific namespaces. If a group of routines are expected to work
in close concert, each should explicitly set the namespace with a C<package>
declaration as the first statement within the routines themselves.
=head2 The Default Methods Provided
The following methods are provided with this package, and are the ones
installed on newly-created server objects unless told not to. These are
identified by their published names, as they are compiled internally as
anonymous subroutines and thus cannot be called directly:
=over 4
=item B<system.identity>
Returns a B<string> value identifying the server name, version, and possibly a
capability level. Takes no arguments.
=item B<system.introspection>
Returns a series of B<struct> objects that give overview documentation of one
or more of the published methods. It may be called with a B<string>
identifying a single routine, in which case the return value is a
B<struct>. It may be called with an B<array> of B<string> values, in which
case an B<array> of B<struct> values, one per element in, is returned. Lastly,
it may be called with no input parameters, in which case all published
routines are documented. Note that routines may be configured to be hidden
from such introspection queries.
=item B<system.listMethods>
Returns a list of the published methods or a subset of them as an B<array> of
B<string> values. If called with no parameters, returns all (non-hidden)
method names. If called with a single B<string> pattern, returns only those
names that contain the string as a substring of their name (case-sensitive,
and this is I<not> a regular expression evaluation).
=item B<system.methodHelp>
Takes either a single method name as a B<string>, or a series of them as an
B<array> of B<string>. The return value is the help text for the method, as
( run in 0.465 second using v1.01-cache-2.11-cpan-39bf76dae61 )