From: Matt S Trout Date: Mon, 4 Jun 2012 16:49:55 +0000 (+0000) Subject: invert new::on logic to make remoting saner X-Git-Tag: v0.001001~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e144d525c19bc4488952e4cea0ea0fe47a8db133;p=scpubgit%2FObject-Remote.git invert new::on logic to make remoting saner --- diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index 47f2906..6cfb9bb 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -2,14 +2,12 @@ package Object::Remote; use Object::Remote::MiniLoop; use Object::Remote::Handle; +use Module::Runtime qw(use_module); sub new::on { my ($class, $on, @args) = @_; - Object::Remote::Handle->new( - connection => $on, - class => $class, - args => \@args - )->proxy; + my $conn = use_module('Object::Remote::Connection')->new_from_spec($on); + return $conn->new_remote(class => $class, args => \@args); } sub new { diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index 291b554..a5ad302 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -92,12 +92,20 @@ BEGIN { sub new_from_spec { my ($class, $spec) = @_; + return $spec if blessed $spec; foreach my $poss (do { our @Guess }) { if (my $obj = $poss->($spec)) { return $obj } } die "Couldn't figure out what to do with ${spec}"; } +sub new_remote { + my ($self, @args) = @_; + Object::Remote::Handle->new( + connection => $self, @args + )->proxy; +} + sub register_remote { my ($self, $remote) = @_; weaken($self->remote_objects_by_id->{$remote->id} = $remote);