line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tak::MetaService; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
361
|
use Tak::WeakClient; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use Log::Contextual qw(:log); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
1466
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Tak::Role::Service'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has router => (is => 'ro', required => 1, weak_ref => 1); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub handle_pid { |
12
|
0
|
|
|
0
|
0
|
|
return $$; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub handle_ensure { |
16
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
17
|
0
|
|
|
|
|
|
my ($name) = @_; |
18
|
0
|
0
|
|
|
|
|
return "Already have ${name}" if $self->router->services->{$name}; |
19
|
0
|
|
|
|
|
|
$self->handle_register(@_); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub handle_register { |
23
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $class, %args) = @_; |
24
|
0
|
|
|
|
|
|
(my $file = $class) =~ s/::/\//g; |
25
|
0
|
|
|
|
|
|
require "${file}.pm"; |
26
|
0
|
0
|
|
|
|
|
if (my $expose = delete $args{expose}) { |
27
|
0
|
|
|
|
|
|
%args = (%args, %{$self->_construct_exposed_clients($expose)}); |
|
0
|
|
|
|
|
|
|
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
|
|
|
0
|
|
|
my ($self, $expose) = @_; |
36
|
0
|
|
|
|
|
|
my $router = $self->router; |
37
|
0
|
|
|
|
|
|
my %client; |
38
|
0
|
|
|
|
|
|
foreach my $name (keys %$expose) { |
39
|
0
|
|
|
|
|
|
local $_ = $expose->{$name}; |
40
|
0
|
0
|
|
|
|
|
if (ref eq 'HASH') { |
|
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if (my ($svc, @rest) = @$_) { |
48
|
0
|
0
|
|
|
|
|
die "router has no service ${svc}" |
49
|
|
|
|
|
|
|
unless my $service = $router->services->{$svc}; |
50
|
0
|
0
|
|
|
|
|
my $client_class = ( |
51
|
|
|
|
|
|
|
Scalar::Util::isweak($router->services->{$svc}) |
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; |