From: Matt S Trout Date: Wed, 6 Jun 2012 18:23:22 +0000 (+0000) Subject: add Object::Remote->connect X-Git-Tag: v0.001001~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=commitdiff_plain;h=4c17fea55a562db315a029e6bd67b7dbb028a8e9 add Object::Remote->connect --- diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index 6cfb9bb..8894cc7 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -6,7 +6,7 @@ use Module::Runtime qw(use_module); sub new::on { my ($class, $on, @args) = @_; - my $conn = use_module('Object::Remote::Connection')->new_from_spec($on); + my $conn = __PACKAGE__->connect($on); return $conn->new_remote(class => $class, args => \@args); } @@ -15,6 +15,11 @@ sub new { Object::Remote::Handle->new(@_)->proxy; } +sub connect { + my ($class, $to) = @_; + use_module('Object::Remote::Connection')->new_from_spec($to); +} + sub current_loop { our $Current_Loop ||= Object::Remote::MiniLoop->new } diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index 3e35d53..f466452 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -106,6 +106,13 @@ sub new_remote { )->proxy; } +sub connect { + my ($self, $to) = @_; + return await_future($self->send( + class_call => 'Object::Remote', 0, connect => $to + )); +} + sub get_remote_sub { my ($self, $sub) = @_; my ($pkg, $name) = $sub =~ m/^(.*)::([^:]+)$/; diff --git a/t/basic.t b/t/basic.t index 4529e55..0289dc0 100644 --- a/t/basic.t +++ b/t/basic.t @@ -2,21 +2,17 @@ use strictures 1; use Test::More; use Sys::Hostname qw(hostname); -use Object::Remote::Connector::Local; use Object::Remote; $ENV{PERL5LIB} = join( ':', ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : ()), qw(lib t/lib) ); -my $connection = Object::Remote::Connector::Local->new->connect; +my $connection = Object::Remote->connect('-'); #$Object::Remote::Connection::DEBUG = 1; -my $remote = Object::Remote->new( - connection => $connection, - class => 'ORTestClass' -); +my $remote = ORTestClass->new::on($connection); isnt($$, $remote->pid, 'Different pid on the other side');