Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

lilstevey (4628)

lilstevey
  (email not shown publicly)

Consumes:
  • Heinekin
  • Kro
  • Addlestones
  • Old Rosie
  • Thatchers
  • Strongbow
  • Erdinger
  • Guiness
  • Budvar
  • Leffe ( usually blond )
  • Various Real Ales when in premises suitable

Journal of lilstevey (4628)

Monday November 09, 2009
06:28 PM

more tentative perl6 hacking

[ #39867 ]

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:

  1. trying to make implementing a client as simple as passing a Role-As-Interface into some manner of magical constructor/repository.
  2. 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...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.