line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tak::Role::Service; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9966
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub start_request { |
6
|
0
|
|
|
0
|
0
|
|
my ($self, $req, $type, @payload) = @_; |
7
|
0
|
0
|
|
|
|
|
unless ($type) { |
8
|
0
|
|
|
|
|
|
$req->mistake(request_type => "No request type given"); |
9
|
0
|
|
|
|
|
|
return; |
10
|
|
|
|
|
|
|
} |
11
|
0
|
0
|
|
|
|
|
if (my $meth = $self->can("handle_${type}")) { |
|
|
0
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my @result; |
13
|
0
|
0
|
|
|
|
|
if (eval { @result = $self->$meth(@payload); 1 }) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
$req->success(@result); |
15
|
|
|
|
|
|
|
} else { |
16
|
0
|
0
|
|
|
|
|
if (ref($@) eq 'ARRAY') { |
17
|
0
|
|
|
|
|
|
$req->result(@{$@}); |
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
} else { |
19
|
0
|
|
|
|
|
|
$req->failure(exception => $@); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} elsif ($meth = $self->can("start_${type}_request")) { |
23
|
0
|
|
|
|
|
|
$self->$meth($req => @payload); |
24
|
|
|
|
|
|
|
} else { |
25
|
0
|
|
|
|
|
|
$req->mistake(request_type => "Unknown request type ${type}"); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub receive { |
30
|
0
|
|
|
0
|
0
|
|
my ($self, $type, @payload) = @_; |
31
|
0
|
0
|
|
|
|
|
if (my $meth = $self->can("receive_${type}")) { |
32
|
0
|
|
|
|
|
|
$self->$meth(@payload); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# This assumes that by default either services are not stateful |
37
|
|
|
|
|
|
|
# or do want to have persistent state. It's notably overriden by Router. |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
0
|
|
sub clone_or_self { $_[0] } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |