has remote => (is => 'ro', required => 1);
sub inc_callback {
- sub { $self->maybe_load_module($_[1]) }
+ my ($self) = @_;
+ sub { return if our $In_Reentry; $self->maybe_load_module($_[1]) }
}
sub maybe_load_module {
my ($self, $module) = @_;
- my $result = $self->remote->blocking_request(source_for => $module);
- if (my $code = $result->{code}) {
+ local our $In_Reentry = 1;
+ my ($status, $code) = $self->remote->blocking_request(source_for => $module);
+ if ($status eq 'RESULT') {
open my $fh, '<', \$code;
return $fh;
}
--- /dev/null
+package Tak::ModuleSender;
+
+use IO::All;
+use Moo;
+
+sub handle_source_for {
+ my ($self, $module) = @_;
+ my $io = io->dir("$ENV{HOME}/perl5/lib/perl5")->catfile($module);
+ unless ($io->exists) {
+ return FAILURE => undef;
+ }
+ my $code = $io->all;
+ return RESULT => $code;
+}
+
+1;
use Tak::Router;
use IPC::Open2;
use Tak::Remote;
+use Tak::ModuleSender;
+use Tak::ServiceManager;
use Term::ReadLine;
my $pid = open2(my $out, my $in, $^X, qw(-Ilib takd))
my $router = Tak::Router->new(
channel => $channel,
+ local_request_handlers => {
+ MODULE_SENDER => Tak::ServiceManager->new(
+ service => Tak::ModuleSender->new
+ )
+ },
);
my $remote = Tak::Remote->new(
use Tak::JSONChannel;
use Tak::ServiceManager;
use Tak::EvalService;
+use Tak::ModuleLoader;
use Tak::Router;
+use Tak::Remote;
+
+open my $stdin, '<&', \*STDIN;
+open my $stdout, '>&', \*STDOUT;
my $channel = Tak::JSONChannel->new(
- read_fh => \*STDIN,
- write_fh => \*STDOUT
+ read_fh => $stdin,
+ write_fh => $stdout,
);
my $eval = Tak::ServiceManager->new(
}
);
+my $remote = Tak::Remote->new(
+ router => $router,
+ name => 'MODULE_SENDER'
+);
+
+my $loader = Tak::ModuleLoader->new(
+ remote => $remote
+);
+
+shift @INC;
+shift @INC while $INC[0] =~ /^\Q$ENV{HOME}/;
+
+unshift @INC, $loader->inc_callback;
+
$router->run;