X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote.pm;h=6cfb9bbef1f18c24d3f1760b1bb061dd637d8a83;hb=c6fe6fbd88a05e860ecdc8942cb86940915172ed;hp=cd3a36489ba39a5f205c8222f69e8cf495c88be0;hpb=2065b08ba567dbf8c8370b69e3f5b2aa145efe23;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index cd3a364..6cfb9bb 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -1,60 +1,22 @@ 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'); - -sub proxy { - bless({ remote => $_[0], method => 'call' }, 'Object::Remote::Proxy'); +sub new::on { + my ($class, $on, @args) = @_; + my $conn = use_module('Object::Remote::Connection')->new_from_spec($on); + return $conn->new_remote(class => $class, args => \@args); } -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 new { + shift; + Object::Remote::Handle->new(@_)->proxy; } sub current_loop { our $Current_Loop ||= Object::Remote::MiniLoop->new } -sub call { - my ($self, $method, @args) = @_; - $self->_await($self->connection->send(call => $self->id, $method, @args)); -} - -sub call_discard { - my ($self, $method, @args) = @_; - $self->connection->send_discard(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;