File Coverage

blib/lib/Tak/ConnectionService.pm
Criterion Covered Total %
statement 9 18 50.0
branch n/a
condition n/a
subroutine 3 6 50.0
pod 0 3 0.0
total 12 27 44.4


line stmt bran cond sub pod time code
1             package Tak::ConnectionService;
2              
3 1     1   980 use Tak::ConnectionReceiver;
  1         3  
  1         30  
4 1     1   461 use Tak::JSONChannel;
  1         3  
  1         25  
5 1     1   6 use Moo;
  1         2  
  1         4  
6              
7             has receiver => (is => 'ro', writer => '_set_receiver');
8              
9             has channel => (is => 'ro', writer => '_set_channel');
10              
11             sub BUILD {
12 0     0 0   my ($self, $args) = @_;
13             my $channel = $self->_set_channel(
14 0           Tak::JSONChannel->new(map +($_ => $args->{$_}), qw(read_fh write_fh))
15             );
16             my $receiver = $self->_set_receiver(
17             Tak::ConnectionReceiver->new(
18             channel => $channel, service => $args->{listening_service},
19             on_close => $args->{on_close},
20             )
21 0           );
22             }
23              
24             sub start_request {
25 0     0 0   my ($self, $req, @payload) = @_;
26 0           $self->receiver->requests->{my $tag = "$req"} = $req;
27 0           my $meta = { progress => !!$req->on_progress };
28 0           $self->channel->write_message(request => $tag => $meta => @payload);
29             }
30              
31             sub receive {
32 0     0 0   my ($self, @payload) = @_;
33 0           $self->channel->write_message(message => @payload);
34             }
35              
36             1;