Tak/ConnectionReceiver.pm

filter: Statementstmt 42.8% 18 / 42 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 26.6% 4 / 15 Podpod 0.0% 0 / 7 totaltotal 32.3% 22 / 68 SCAR 16.2
CC
3
Cov
39%
receive_request
12.0
BUILD
2.0
__ANON__
2.0
CRAP 5.0
« Tak/Result.pm ↑ Summary Tak/ModuleLoader/Hook.pm »
1 package Tak::ConnectionReceiver;
2  
3 1 ▶use Tak::Request;
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 1 with 'Tak::Role::Service';
9  
10 0 ▶has requests => (is => 'ro', default => sub { {} });
Subroutine __ANON__: not called CC=1 SCAR=1.2
11  
12 1 has channel => (is => 'ro', required => 1);
13  
14 1 has service => (is => 'ro', required => 1);
15  
16 1 has on_close => (is => 'ro', required => 1);
17  
18 sub BUILD {
19 0 ▶ weaken(my $self = shift);
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
20 0 my $channel = $self->channel;
21 Tak->loop->watch_io(
22 handle => $channel->read_fh,
23 on_read_ready => sub {
24 0 ▶ $channel->read_messages(sub { $self->receive(@_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 }
26 0 );
27 }
28  
29 sub DEMOLISH {
30 0 ▶ Tak->loop->unwatch_io(
Subroutine DEMOLISH: not called CC=1 SCAR=6.9
Pod undocumented
31 handle => $_[0]->channel->read_fh,
32 on_read_ready => 1,
33 );
34 }
35  
36 sub receive_request {
37 0 ▶ my ($self, $tag, $meta, @payload) = @_;
Subroutine receive_request: not called CC=3 SCAR=24.8
Pod undocumented
38 0 my $channel = $self->channel;
39 0 ▶ unless (ref($meta) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $meta eq "HASH") 0 0 0
40 0 $channel->write_message(mistake => $tag => 'meta value not a hashref');
41 0 return;
42 }
43 my $req = Tak::Request->new(
44 ($meta->{progress}
45 0 ▶ ? (on_progress => sub { $channel->write_message(progress => $tag => @_) })
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 : ()),
47 0 ▶ on_result => sub { $channel->write_message(result => $tag => $_[0]->flatten) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'progress'} ? : 0 0 0
49 0 $self->service->start_request($req => @payload);
50 }
51  
52 sub receive_progress {
53 0 ▶ my ($self, $tag, @payload) = @_;
Subroutine receive_progress: not called CC=1 SCAR=6.9
Pod undocumented
54 0 $self->requests->{$tag}->progress(@payload);
55 }
56  
57 sub receive_result {
58 0 ▶ my ($self, $tag, @payload) = @_;
Subroutine receive_result: not called CC=1 SCAR=6.9
Pod undocumented
59 0 (delete $self->requests->{$tag})->result(@payload);
60 }
61  
62 sub receive_message {
63 0 ▶ my ($self, @payload) = @_;
Subroutine receive_message: not called CC=1 SCAR=6.9
Pod undocumented
64 0 $self->service->receive(@payload);
65 }
66  
67 sub receive_close {
68 0 ▶ my ($self, @payload) = @_;
Subroutine receive_close: not called CC=1 SCAR=6.9
Pod undocumented
69 0 $self->on_close->(@payload);
70 }
71  
72 1 1;
« Tak/Result.pm ↑ Summary Tak/ModuleLoader/Hook.pm »