X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote.pm;h=485821d47c46551b29f40b4024d279923c325627;hp=cd3a36489ba39a5f205c8222f69e8cf495c88be0;hb=624b459bafc411773708e674cf54e1971eb4d231;hpb=2065b08ba567dbf8c8370b69e3f5b2aa145efe23 diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index cd3a364..485821d 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -1,60 +1,33 @@ 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 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 current_loop { - our $Current_Loop ||= Object::Remote::MiniLoop->new +sub new::on { + my ($class, $on, @args) = @_; + my $conn = __PACKAGE__->connect($on); + return $conn->remote_object(class => $class, args => \@args); } -sub call { - my ($self, $method, @args) = @_; - $self->_await($self->connection->send(call => $self->id, $method, @args)); +sub can::on { + my ($class, $on, $name) = @_; + my $conn = __PACKAGE__->connect($on); + return $conn->remote_sub(join('::', $class, $name)); } -sub call_discard { - my ($self, $method, @args) = @_; - $self->connection->send_discard(call => $self->id, $method, @args); +sub new { + shift; + Object::Remote::Handle->new(@_)->proxy; } -sub _await { - my ($self, $future) = @_; - my $loop = $self->current_loop; - $future->on_ready(sub { $loop->stop }); - $loop->run; - $future->get; +sub connect { + my ($class, $to) = @_; + use_module('Object::Remote::Connection')->new_from_spec($to); } -sub DEMOLISH { - my ($self, $gd) = @_; - return if $gd; - $self->connection->send_free($self->id); +sub current_loop { + our $Current_Loop ||= Object::Remote::MiniLoop->new } 1;