| 1 | package Tak::Role::Service; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use Moo::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | sub start_request { | ||||||||||||||
| 6 | 0 | ▶ | my ($self, $req, $type, @payload) = @_; | ||||||||||||
|
Subroutine
start_request: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 7 | 0 | ▶ | unless ($type) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 8 | 0 | $req->mistake(request_type => "No request type given"); | |||||||||||||
| 9 | 0 | return; | |||||||||||||
| 10 | } | ||||||||||||||
| 11 | 0 | ▶ | if (my $meth = $self->can("handle_${type}")) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 12 | 0 | my @result; | |||||||||||||
| 13 | 0 | ▶ | if (eval { @result = $self->$meth(@payload); 1 }) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 14 | 0 | $req->success(@result); | |||||||||||||
| 15 | } else { | ||||||||||||||
| 16 | 0 | ▶ | if (ref($@) eq 'ARRAY') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 17 | 0 | $req->result(@{$@}); | |||||||||||||
| 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 | ▶ | my ($self, $type, @payload) = @_; | ||||||||||||
|
Subroutine
receive: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 31 | 0 | ▶ | if (my $meth = $self->can("receive_${type}")) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | ▶ | sub clone_or_self { $_[0] } | ||||||||||||
|
Subroutine
clone_or_self: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 40 | |||||||||||||||
| 41 | 1 | 1; | |||||||||||||