Re: [Fwd: Module namespace request: Event::RPC]
[email protected] (Jörn Reder) Sun, 13 Mar 2005 13:46:19 +0100
| Newsgroups | perl.loop |
|---|---|
| Message-ID | <[email protected]> |
------------=_1110717979-31726-7
Content-Type: text/plain; charset="iso-8859-15"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Joshua N Pritikin wrote:
> Hrm, sounds interesting.
>=20
> So what does Event::RPC do exactly? Can you post a summary?
Yep, here it is:
--snip--
Summary of Event::RPC
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Event::RPC consists of a server and a client library. The server exports
a list of modules and methods, which are allowed to be called over the=20
network. More specific it acts as a proxy for objects created on the=20
server side (on demand of the connected clients) which handles client=20
side methods calls with transport of method arguments and return values.
The server side object proxy handles refcounting and destruction of=20
objects created by clients properly. Objects as method parameters and=20
return values are handled as well.
For the client the whole thing is totally transparent - once connected=20
to the server it doesn't know whether it calls methods on local or=20
remote objects.
This is a simple example to make clear how this works:
Server:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
use strict;
use Event::RPC::Server;
main: {
#-- Create a Server instance and declare the
#-- exported interface
my $server =3D Event::RPC::Server->new (
name =3D> "test daemon",
port =3D> 5555,
classes =3D> {
'Event::RPC::Test' =3D> {
new =3D> '_constructor', # Class constructor
set_data =3D> 1, # and 'normal' methods...
get_data =3D> 1,
hello =3D> 1,
},
},
);
#-- Start the server resp. the Event loop.
$server->start;
}
#-- A simple test class
package Event::RPC::Test;
sub get_data { shift->{data} }
sub set_data { shift->{data} =3D $_[1] }
sub new {
my $class =3D shift;
my %par =3D @_;
my ($data) =3D $par{'data'};
my $self =3D bless { data =3D> $data };
return $self;
}
sub hello {
my $self =3D shift;
return "I have this data: '".$self->get_data."'";
}
Client:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
use strict;
use Event::RPC::Client;
main: {
#-- This connects to the server, requests the exported
#-- interfaces and establishes proxy methods
#-- in the correspondent packages.
my $client =3D Event::RPC::Client->connect (
server =3D> "localhost",
port =3D> 5555,
error_cb =3D> sub { print "An RPC error occured\n"; exit },
);
#-- From now on the call to Event::RPC::Test->new is handled
#-- transparently by Event::RPC::Client
my $object =3D Event::RPC::Test->new (
data =3D> "some test data" x 5
);
#-- and method calls as well...
print "hello=3D".$object->hello,"\n";
$object->set_data ("changed data");
print "data=3D".$object->get_data."\n";
#-- disconnection is handled by the destructor of $client=09
}
--snip--
Regards,
Joern
--=20
Think before you code. And while you're doing it probably won't hurt. ;)
------------=_1110717979-31726-7
Content-Type: application/pgp-signature
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQBCNDYb2hNi0Chc9HMRA3vgAJoCvZvbjmE/l7tU8t+OpxMlBdIuTACgzATw
dbUwvaNBZn5DBooR8l3Y7gg=
=/Tv0
-----END PGP SIGNATURE-----
------------=_1110717979-31726-7--