From: Matt S Trout Date: Sun, 30 Oct 2011 04:01:18 +0000 (+0000) Subject: add meta service X-Git-Tag: v0.001001~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=857f4834b4de8b02ca9c0af4a3fabfbf21938e79;p=scpubgit%2FTak.git add meta service --- diff --git a/lib/Tak/JSONChannel.pm b/lib/Tak/JSONChannel.pm index 9716768..fd3e7b5 100644 --- a/lib/Tak/JSONChannel.pm +++ b/lib/Tak/JSONChannel.pm @@ -46,6 +46,7 @@ sub send { [ FAILURE => invalid_message => $@||'No data and no exception' ] ) ); + return; } $self->_raw_send($json); } diff --git a/lib/Tak/MetaService.pm b/lib/Tak/MetaService.pm new file mode 100644 index 0000000..b0b6af9 --- /dev/null +++ b/lib/Tak/MetaService.pm @@ -0,0 +1,16 @@ +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; diff --git a/lib/Tak/REPL.pm b/lib/Tak/REPL.pm index 1191c72..977c5b6 100644 --- a/lib/Tak/REPL.pm +++ b/lib/Tak/REPL.pm @@ -7,7 +7,14 @@ has world => (is => 'ro', required => 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; diff --git a/lib/Tak/Router.pm b/lib/Tak/Router.pm index 58b73bf..3e6853b 100644 --- a/lib/Tak/Router.pm +++ b/lib/Tak/Router.pm @@ -2,6 +2,7 @@ package Tak::Router; use Tak::Request; use Tak::ServiceManager; +use Tak::MetaService; use Moo; has channel => (is => 'ro', required => 1); @@ -16,6 +17,11 @@ sub next_serial { ++($_[0]->{last_serial}) } 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 { diff --git a/lib/Tak/World.pm b/lib/Tak/World.pm index 49db7ca..84d05a9 100644 --- a/lib/Tak/World.pm +++ b/lib/Tak/World.pm @@ -2,7 +2,6 @@ package Tak::World; use Tak::JSONChannel; use Tak::ServiceManager; -use Tak::EvalService; use Tak::ModuleLoader; use Tak::Router; use Tak::Remote; @@ -27,11 +26,9 @@ sub _build_router { 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( diff --git a/lib/Tak/WorldHandle.pm b/lib/Tak/WorldHandle.pm index 8549cc2..87877ab 100644 --- a/lib/Tak/WorldHandle.pm +++ b/lib/Tak/WorldHandle.pm @@ -46,7 +46,7 @@ sub _build_router { channel => $channel ); - $router->register(MODULE_SENDER => Tak::ModuleSender->new); + $router->register(module_sender => Tak::ModuleSender->new); return $router; } diff --git a/takd b/takd index e29e164..0f806ec 100644 --- a/takd +++ b/takd @@ -1,42 +1,4 @@ -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;