my ($self, $name, $class, %args) = @_;
(my $file = $class) =~ s/::/\//g;
require "${file}.pm";
- my $router = $self->router;
if (my $expose = delete $args{expose}) {
- foreach my $name (keys %$expose) {
- if (my ($svc, @rest) = @{$expose->{$name}}) {
+ %args = (%args, %{$self->_construct_exposed_clients($expose)});
+ }
+ my $new = $class->new(\%args);
+ $self->router->register($name => $new);
+ return "Registered ${name}";
+}
+
+sub _construct_exposed_clients {
+ my ($self, $expose) = @_;
+ my $router = $self->router;
+ my %client;
+ foreach my $name (keys %$expose) {
+ local $_ = $expose->{$name};
+ if (ref eq 'HASH') {
+ $client{$name} = Tak::Client->new(
+ service => Tak::Router->new(
+ services => $self->_construct_exposed_clients($_)
+ )
+ );
+ } elsif (ref eq 'ARRAY') {
+ if (my ($svc, @rest) = @$_) {
die "router has no service ${svc}"
unless my $service = $router->services->{$svc};
my $client_class = (
? 'Tak::WeakClient'
: 'Tak::Client'
);
- $args{$name} = $client_class->new(service => $service)
- ->curry(@rest);
+ $client{$name} = $client_class->new(service => $service)
+ ->curry(@rest);
} else {
- $args{$name} = Tak::WeakClient->new(service => $router);
+ $client{$name} = Tak::WeakClient->new(service => $router);
}
+ } else {
+ die "expose key ${name} was ".ref;
}
}
- my $new = $class->new(\%args);
- $router->register($name => $new);
- return "Registered ${name}";
+ \%client;
}
1;