| 1 | package Tak::MetaService; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use Tak::WeakClient; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use Log::Contextual qw(:log); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | with 'Tak::Role::Service'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 1 | has router => (is => 'ro', required => 1, weak_ref => 1); | |||||||||||||
| 10 | |||||||||||||||
| 11 | sub handle_pid { | ||||||||||||||
| 12 | 0 | ▶ | return $$; | ||||||||||||
|
Subroutine
handle_pid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 13 | } | ||||||||||||||
| 14 | |||||||||||||||
| 15 | sub handle_ensure { | ||||||||||||||
| 16 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
handle_ensure: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 17 | 0 | my ($name) = @_; | |||||||||||||
| 18 | 0 | ▶ | return "Already have ${name}" if $self->router->services->{$name}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | 0 | $self->handle_register(@_); | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | sub handle_register { | ||||||||||||||
| 23 | 0 | ▶ | my ($self, $name, $class, %args) = @_; | ||||||||||||
|
Subroutine
handle_register: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 24 | 0 | (my $file = $class) =~ s/::/\//g; | |||||||||||||
| 25 | 0 | require "${file}.pm"; | |||||||||||||
| 26 | 0 | ▶ | if (my $expose = delete $args{expose}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 0 | %args = (%args, %{$self->_construct_exposed_clients($expose)}); | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | 0 | my $new = $class->new(\%args); | |||||||||||||
| 30 | 0 | $self->router->register($name => $new); | |||||||||||||
| 31 | 0 | return "Registered ${name}"; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | sub _construct_exposed_clients { | ||||||||||||||
| 35 | 0 | ▶ | my ($self, $expose) = @_; | ||||||||||||
|
Subroutine
_construct_exposed_clients: not called CC=7 SCAR=40.3
| |||||||||||||||
| 36 | 0 | my $router = $self->router; | |||||||||||||
| 37 | 0 | my %client; | |||||||||||||
| 38 | 0 | foreach my $name (keys %$expose) { | |||||||||||||
| 39 | 0 | local $_ = $expose->{$name}; | |||||||||||||
| 40 | 0 | ▶ | if (ref eq 'HASH') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 41 | 0 | $client{$name} = Tak::Client->new( | |||||||||||||
| 42 | service => Tak::Router->new( | ||||||||||||||
| 43 | services => $self->_construct_exposed_clients($_) | ||||||||||||||
| 44 | ) | ||||||||||||||
| 45 | ); | ||||||||||||||
| 46 | } elsif (ref eq 'ARRAY') { | ||||||||||||||
| 47 | 0 | ▶ | if (my ($svc, @rest) = @$_) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | die "router has no service ${svc}" | ||||||||||||||
| 49 | 0 | ▶ | unless my $service = $router->services->{$svc}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | my $client_class = ( | ||||||||||||||
| 51 | 0 | ▶ | Scalar::Util::isweak($router->services->{$svc}) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | ? 'Tak::WeakClient' | ||||||||||||||
| 53 | : 'Tak::Client' | ||||||||||||||
| 54 | ); | ||||||||||||||
| 55 | 0 | $client{$name} = $client_class->new(service => $service) | |||||||||||||
| 56 | ->curry(@rest); | ||||||||||||||
| 57 | } else { | ||||||||||||||
| 58 | 0 | $client{$name} = Tak::WeakClient->new(service => $router); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | } else { | ||||||||||||||
| 61 | 0 | die "expose key ${name} was ".ref; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | } | ||||||||||||||
| 64 | 0 | \%client; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 1 | 1; | |||||||||||||