X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote.pm;h=fc6e9557643fae60f0fb00d17a9039ee5161d9f4;hb=3687a42d0f4ac20dfd2cb31cb76cf9866ee63f14;hp=326a3a580034389fe1f7f8ae6184372e3f4f90ec;hpb=9e72f0cf54e92bccdba71eb75037f1cfe4f69f36;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index 326a3a5..fc6e955 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -1,57 +1,27 @@ package Object::Remote; use Object::Remote::MiniLoop; -use Object::Remote::Proxy; -use Scalar::Util qw(weaken); -use Moo; +use Object::Remote::Handle; +use Module::Runtime qw(use_module); -has connection => (is => 'ro', required => 1); - -has id => (is => 'rwp'); - -has proxy => (is => 'lazy', weak_ref => 1); +sub new::on { + my ($class, $on, @args) = @_; + my $conn = __PACKAGE__->connect($on); + return $conn->remote_object(class => $class, args => \@args); +} -sub _build_proxy { - bless({ handle => $_[0] }, 'Object::Remote::Proxy'); +sub new { + shift; + Object::Remote::Handle->new(@_)->proxy; } -sub BUILD { - my ($self, $args) = @_; - unless ($self->id) { - die "No id supplied and no class either" unless $args->{class}; - $self->_set_id( - $self->_await( - $self->connection->send( - class_call => $args->{class}, - $args->{constructor}||'new', @{$args->{args}||[]} - ) - ) - ); - } - $self->connection->register_remote($self); +sub connect { + my ($class, $to) = @_; + use_module('Object::Remote::Connection')->new_from_spec($to); } sub current_loop { our $Current_Loop ||= Object::Remote::MiniLoop->new } -sub call { - my ($self, $id, $method, @args) = @_; - $self->_await($self->connection->send(call => $self->id, $method, @args)); -} - -sub _await { - my ($self, $future) = @_; - my $loop = $self->current_loop; - $future->on_ready(sub { $loop->stop }); - $loop->run; - $future->get; -} - -sub DEMOLISH { - my ($self, $gd) = @_; - return if $gd; - $self->connection->send_free($self->id); -} - 1;