[ FAILURE => invalid_message => $@||'No data and no exception' ]
)
);
+ return;
}
$self->_raw_send($json);
}
--- /dev/null
+package Tak::MetaService;
+
+use Moo;
+
+has router => (is => 'ro', required => 1, weak_ref => 1);
+
+sub handle_register {
+ my ($self, $name, $class, @args) = @_;
+ (my $file = $class) =~ s/::/\//g;
+ require "${file}.pm";
+ my $new = $class->new(@args);
+ $self->router->register($name => $new);
+ return SUCCESS => "Registered ${name}";
+}
+
+1;
has remote => (is => 'lazy');
-sub _build_remote { shift->world->remote_for('EVAL') }
+sub _build_remote {
+ my ($self) = @_;
+ my $world = $self->world;
+ $world->remote_for('meta')->blocking_request(
+ register => eval => 'Tak::EvalService'
+ );
+ $world->remote_for('eval')
+}
sub run {
my $remote = $_[0]->remote;
use Tak::Request;
use Tak::ServiceManager;
+use Tak::MetaService;
use Moo;
has channel => (is => 'ro', required => 1);
has requests_sent => (is => 'ro', default => sub { {} });
+sub BUILD {
+ my ($self) = @_;
+ $self->register(meta => Tak::MetaService->new(router => $self));
+}
+
sub run { shift->run_until }
sub run_until {
use Tak::JSONChannel;
use Tak::ServiceManager;
-use Tak::EvalService;
use Tak::ModuleLoader;
use Tak::Router;
use Tak::Remote;
channel => $channel
);
- $router->register(EVAL => Tak::EvalService->new);
-
my $remote = Tak::Remote->new(
router => $router,
- name => 'MODULE_SENDER'
+ name => 'module_sender'
);
my $loader = Tak::ModuleLoader->new(
channel => $channel
);
- $router->register(MODULE_SENDER => Tak::ModuleSender->new);
+ $router->register(module_sender => Tak::ModuleSender->new);
return $router;
}
-use strictures 1;
-use Tak::JSONChannel;
-use Tak::ServiceManager;
-use Tak::EvalService;
-use Tak::ModuleLoader;
-use Tak::Router;
-use Tak::Remote;
+use lib 'lib';
+use Tak::World;
-open my $stdin, '<&', \*STDIN;
-open my $stdout, '>&', \*STDOUT;
-
-my $channel = Tak::JSONChannel->new(
- read_fh => $stdin,
- write_fh => $stdout,
-);
-
-my $eval = Tak::ServiceManager->new(
- service => Tak::EvalService->new
-);
-
-my $router = Tak::Router->new(
- channel => $channel,
- local_request_handlers => {
- EVAL => $eval
- }
-);
-
-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;
+Tak::World->new_from_stdio->run;