| 1 | package Tak::Router; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Tak::MetaService; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Scalar::Util qw(weaken); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Log::Contextual qw(:log); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | has services => (is => 'ro', default => sub { {} }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 9 | |||||||||||
| 10 | sub BUILD { | ||||||||||
| 11 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 12 | 0 | $self->register(meta => Tak::MetaService->new(router => $self)); | |||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | sub start_request { | ||||||||||
| 16 | 0 | ▶ | my ($self, $req, $target, @payload) = @_; | ||||||||
|
Subroutine
start_request: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 17 | 0 | ▶ | return $req->mistake("Reached router with no target") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | unless $target; | ||||||||||
| 19 | return $req->failure("Reached router with invalid target ${target}") | ||||||||||
| 20 | 0 | ▶ | unless my $next = $self->services->{$target}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 0 | $next->start_request($req, @payload); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub receive { | ||||||||||
| 25 | 0 | ▶ | my ($self, $target, @payload) = @_; | ||||||||
|
Subroutine
receive: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 26 | 0 | ▶ | return unless $target; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | log_debug { "Message received for ${target}" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 28 | 0 | ▶ | return log_info { "Discarded message to ${target}" } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 0 | ▶ | unless my $next = $self->services->{$target}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | $next->receive(@payload); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | sub register { | ||||||||||
| 34 | 0 | ▶ | my ($self, $name, $service) = @_; | ||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 35 | 0 | $self->services->{$name} = $service; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub register_weak { | ||||||||||
| 39 | 0 | ▶ | my ($self, $name, $service) = @_; | ||||||||
|
Subroutine
register_weak: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 40 | 0 | weaken($self->services->{$name} = $service); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | sub deregister { | ||||||||||
| 44 | 0 | ▶ | my ($self, $name) = @_; | ||||||||
|
Subroutine
deregister: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 45 | 0 | delete $self->services->{$name} | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | sub clone_or_self { | ||||||||||
| 49 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
clone_or_self: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 50 | 0 | (ref $self)->new(services => { %{$self->services} }); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 1 | 1; | |||||||||