4 use Scalar::Util qw(weaken);
5 use Log::Contextual qw(:log);
8 has services => (is => 'ro', default => sub { {} });
12 $self->register(meta => Tak::MetaService->new(router => $self));
16 my ($self, $req, $target, @payload) = @_;
17 return $req->mistake("Reached router with no target")
19 return $req->failure("Reached router with invalid target ${target}")
20 unless my $next = $self->services->{$target};
21 $next->start_request($req, @payload);
25 my ($self, $target, @payload) = @_;
26 return unless $target;
27 log_debug { "Message received for ${target}" };
28 return log_info { "Discarded message to ${target}" }
29 unless my $next = $self->services->{$target};
30 $next->receive(@payload);
34 my ($self, $name, $service) = @_;
35 $self->services->{$name} = $service;
39 my ($self, $name, $service) = @_;
40 weaken($self->services->{$name} = $service);
44 my ($self, $name) = @_;
45 delete $self->services->{$name}
50 (ref $self)->new(services => { %{$self->services} });