The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

RPC::Object - A lightweight implementation for remote procedure calls

SYNOPSIS

On server

  use RPC::Object::Broker;
  $b = $RPC::Object::Broker->get_instance($port, @preload_modules);
  $b->start();

On client

  use RPC::Object;
  $o = RPC::Object->new("$host:$port", 'method_a', 'TestModule');
  my $ans1 = $o->method_b($arg1, $arg2);
  my @ans2 = $o->method_c($arg3, $arg4);

  # or access the global instance
  $o2 = RPC::Object->get_instance("$host:$port", 'method_x', 'TestModule2');

TestModule

  package TestModule;
  use threads;
  ...
  sub method_a {
      my $class = shift;
      my $self : shared;
      ...
      return bless $self, $class;
  }

  sub method_b {
      ...
  }
  ...

TestModule2

  package TestModule2;
  use threads;
  ...
  {
     my $instance : share;
     sub method_x {
         ...
         return $instance;
     }
  }
  ...

Please see more examples in the test scripts.

DESCRIPTON

RPC::Object is designed to be very simple and only works between Perl codes, This makes its implementation only need some core Perl modules, e.g. IO and Storable.

Other approaches like SOAP or XML-RPC are too heavy for simple tasks.

Thread awareness

All modules and objects invoked by RPC::Object should aware the multi-threaded envrionment.

Constructor and Destructor

The Module could name its constructor any meaningful name. it do not have to be new, or create, etc...

To release an object, use RPC::Object::rpc_object_release, e.g.

  $o = RPC::Object->new("$host:$port", 'method_a', 'TestModule');
  $o->rpc_object_release();

Global instance

There are two ways to allocate and access global instances: a) use the preload module list to load the module at server side, and use the RPC::Object::new() method; b) use the RPC::Object::get_instance() method. The performance of method a may be better as modules are only loaded once.

AUTHORS

Jianyuan Wu <jwu@cpan.org>

COPYRIGHT

Copyright 2006 by Jianyuan Wu <jwu@cpan.org>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.