A little more work. Following some wise words in masak's journal about starting simple, I decided to take further tentative tiptoes
further towards my target of a transparent Role-As-Interface based RMI system
by first of all just hacking together a call from client to server.
Following a visit to the lovely people on #perl6 I got a pointer to the
perl6 test suite which, when
read with the synopsis & apocalypse documents, seems to give a reasonable set
of reference documents.
Anyway, squeezing this around other commitments, I hacked LWP::Simple and HTTP::Daemon
around a little, and created the following files:
-
testclient.pl
-
use v6;
use RmiClient;
my $r = RmiClient.new(url => "http://localhost:8888/");
say $r.proxy("Greet");
-
RmiClient.pm
-
use v6;
use LWP::Simple;
class RmiClient
{
has $url;
method proxy( $method )
{
my $s = LWP::Simple.get($url~$method); # "http://localhost:8080/"
my ($r1,@r2) = split(/\n\n/,$s);
my $r2 = join '\n\n',@r2;
return $r2;
}
}
1;
Thats the client side of this simple test, now onto the server side.
- testserver.pl
-
use v6;
use Adapter;
use TestClass;
my $tc = TestClass.new();
my $a = Adapter.new( clzz => $tc );
$a.startServer();
-
Adapter.pm
-
use v6;
use HTTP::Daemon;
use TestClass;
class Adapter
{
has TestClass $clzz;
method startServer()
{
my HTTP::Daemon $d .= new;
say "see {$d.url}";
while my HTTP::Daemon::ClientConn $c = $d.accept {
while my HTTP::Request $r = $c.get_request {
if $r.method eq 'GET' {
$c.send_response($clzz.Greet());
}
else {
$c.send_error('RC_FORBIDDEN');
}
warn "{$r.method} {$r.url.path}";
}
}
}
}
-
TestClass.pm
-
use v6;
class TestClass
{
method Greet()
{
return "Hello World";
}
}
That is quite filthy, but a start. Next up is one of two things:
- trying to make implementing a client
as simple as passing a Role-As-Interface into some manner of magical constructor/repository.
-
Passing a Role-As-Interface and implementing class into some manner of thingy on the server
that exposes methods defined in the Role-As-Interface and implements them using said class.
These "simple" steps may possibly include a tour round some other areas, including a look at serialisation, dependency injections, singletons... Still only one way to eat an elephant...