File Coverage

blib/lib/Tak/ObjectClient.pm
Criterion Covered Total %
statement 6 30 20.0
branch 0 6 0.0
condition n/a
subroutine 2 8 25.0
pod n/a
total 8 44 18.1


line stmt bran cond sub pod time code
1             package Tak::ObjectClient;
2              
3 1     1   1696 use Tak::ObjectProxy;
  1         3  
  1         30  
4 1     1   7 use Moo;
  1         2  
  1         7  
5              
6             with 'Tak::Role::ObjectMangling';
7              
8             has remote => (is => 'ro', required => 1);
9              
10             has object_service => (is => 'lazy');
11              
12             sub _build_object_service {
13 0     0     my ($self) = @_;
14 0           my $remote = $self->remote;
15 0           $remote->ensure(object_service => 'Tak::ObjectService');
16 0           $remote->curry('object_service');
17             }
18              
19             sub proxy_method_call {
20 0     0     my ($self, @call) = @_;
21 0           my $client = $self->object_service;
22 0           my $ready = $self->encode_objects(\@call);
23 0           my $context = wantarray;
24 0           my $res = $client->do(call_method => $context => $ready);
25 0           my $unpacked = $self->decode_objects($res);
26 0 0         if ($context) {
    0          
27 0           return @$unpacked;
28             } elsif (defined $context) {
29 0           return $unpacked->[0];
30             } else {
31 0           return;
32             }
33             }
34              
35             sub proxy_death {
36 0     0     my ($self, $proxy) = @_;
37 0           $self->client->do(remove_object => $proxy->{tag});
38             }
39              
40             sub inflate {
41 0     0     my ($self, $tag) = @_;
42 0           bless({ client => $self, tag => $tag }, 'Tak::ObjectProxy');
43             }
44              
45             sub deflate {
46 0     0     my ($self, $obj) = @_;
47 0 0         unless (ref($obj) eq 'Tak::ObjectProxy') {
48 0           die "Can't deflate non-proxied object ${obj}";
49             }
50 0           return +{ __proxied_object__ => $obj->{tag} };
51             }
52              
53             sub new_object {
54 0     0     my ($self, $class, @args) = @_;
55 0           $self->proxy_method_call($class, 'new', @args);
56             }
57              
58             1;