From: Matt S Trout Date: Thu, 31 May 2012 20:01:54 +0000 (+0000) Subject: make module_sender parameterisable X-Git-Tag: v0.001001~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=03f41c0ee0921cff184d8be618505b1a25f30025;p=scpubgit%2FObject-Remote.git make module_sender parameterisable --- diff --git a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm index 84b2988..62d0153 100644 --- a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm +++ b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm @@ -8,17 +8,22 @@ use Moo::Role; with 'Object::Remote::Role::Connector'; -around connect => sub { - my ($orig, $self) = (shift, shift); - my $conn = $self->$orig(@_); +has module_sender => (is => 'lazy'); + +sub _build_module_sender { my ($hook) = grep {blessed($_) && $_->isa('Object::Remote::ModuleLoader::Hook') } @INC; - my $sender = $hook ? $hook->sender : Object::Remote::ModuleSender->new; + return $hook ? $hook->sender : Object::Remote::ModuleSender->new; +} + +around connect => sub { + my ($orig, $self) = (shift, shift); + my $conn = $self->$orig(@_); Object::Remote::Handle->new( connection => $conn, class => 'Object::Remote::ModuleLoader', - args => { module_sender => $sender } + args => { module_sender => $self->module_sender } )->disarm_free; return $conn; }; diff --git a/t/sender.t b/t/sender.t index 02eb0d8..d8b58e2 100644 --- a/t/sender.t +++ b/t/sender.t @@ -9,17 +9,13 @@ $ENV{PERL5LIB} = join( ':', ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : ()), qw(lib) ); -my $connection = Object::Remote::Connector::Local->new->connect; - my $ms = Object::Remote::ModuleSender->new( dir_list => [ 't/lib' ] ); -my $ml = Object::Remote->new( - connection => $connection, - class => 'Object::Remote::ModuleLoader', - args => { module_sender => $ms }, -); +my $connection = Object::Remote::Connector::Local->new( + module_sender => $ms, + )->connect; my $counter = Object::Remote->new( connection => $connection,