package Tak::MetaService;
use Tak::WeakClient;
+use Log::Contextual qw(:log);
use Moo;
with 'Tak::Role::Service';
my ($self, $name, $class, %args) = @_;
(my $file = $class) =~ s/::/\//g;
require "${file}.pm";
+ my $router = $self->router;
if (my $expose = delete $args{expose}) {
- my $client = Tak::WeakClient->new(service => $self->router);
- foreach my $name (%$expose) {
- $args{$name} = $client->curry(@{$expose->{$name}});
+ foreach my $name (keys %$expose) {
+ if (my ($svc, @rest) = @{$expose->{$name}}) {
+ die "router has no service ${svc}"
+ unless my $service = $router->services->{$svc};
+ $args{$name} = Tak::Client->new(service => $service)
+ ->curry(@rest);
+ } else {
+ $args{$name} = Tak::WeakClient->new(service => $router);
+ }
}
}
my $new = $class->new(\%args);
- $self->router->register($name => $new);
+ $router->register($name => $new);
return "Registered ${name}";
}