PlRPC
view release on metacpan or search on metacpan
lib/RPC/PlServer.pm view on Meta::CPAN
(delete $self->{'handles'}->{$handle}) || die "No such object: $handle";
();
}
sub CallMethod ($$$@) {
my($self, $handle, $method, @args) = @_;
my($ref, $object);
my $call_by_instance;
{
my $lock = lock($Net::Daemon::RegExpLock)
if $Net::Daemon::RegExpLock && $self->{'mode'} eq 'threads';
$call_by_instance = ($handle =~ /=\w+\(0x/);
}
if ($call_by_instance) {
# Looks like a call by instance
$object = $self->UseHandle($handle);
$ref = ref($object);
} else {
# Call by class
$ref = $object = $handle;
}
if ($self->{'methods'}) {
my $class = $self->{'methods'}->{$ref};
if (!$class || !$class->{$method}) {
die "Not permitted for method $method of class $ref";
}
}
$object->$method(@args);
}
1;
__END__
=head1 NAME
RPC::PlServer - Perl extension for writing PlRPC servers
=head1 SYNOPSIS
# Create a subclass of RPC::PlServer
use RPC::PlServer;
package MyServer;
$MyServer::VERSION = '0.01';
@MyServer::ISA = qw(RPC::PlServer);
# Overwrite the Run() method to handle a single connection
sub Run {
my $self = shift;
my $socket = $self->{'socket'};
}
# Create an instance of the MyServer class
package main;
my $server = MyServer->new({'localport' => '1234'}, \@ARGV);
# Bind the server to its port to make it actually running
$server->Bind();
=head1 DESCRIPTION
PlRPC (Perl RPC) is a package for implementing servers and clients that
are written in Perl entirely. The name is borrowed from Sun's RPC
(Remote Procedure Call), but it could as well be RMI like Java's "Remote
Method Interface), because PlRPC gives you the complete power of Perl's
OO framework in a very simple manner.
RPC::PlServer is the package used on the server side, and you guess what
RPC::PlClient is for. Both share the package RPC::PlServer::Comm for
communication purposes. See L<PlRPC::Client(3)> and L<RPC::PlServer::Comm>
for these parts.
PlRPC works by defining a set of methods that may be executed by the client.
For example, the server might offer a method "multiply" to the client. Now
the clients method call
@result = $client->multiply($a, $b);
will be immediately mapped to a method call
@result = $server->multiply($a, $b);
on the server. The arguments and results will be transferred to or from
the server automagically. (This magic has a name in Perl: It's the
Storable module, my thanks to Raphael Manfredi for this excellent
package.) Simple, eh? :-)
The RPC::PlServer and RPC::PlClient are abstract servers and clients: You
have to derive your own classes from it.
=head2 Additional options
The RPC::PlServer inherits all of Net::Daemon's options and attributes
and adds the following:
=over 8
=item I<cipher>
The attribute value is an instance of Crypt::DES, Crypt::IDEA or any
other class with the same API for block encryption. If you supply
such an attribute, the traffic between client and server will be
encrypted using this option.
=item I<maxmessage> (B<--maxmessage=size>)
The size of messages exchanged between client and server is restricted,
in order to omit denial of service attacks. By default the limit is
65536 bytes.
=item users
This is an attribute of the client object used for Permit/Deny rules
( run in 3.329 seconds using v1.01-cache-2.11-cpan-364913b4093 )