lib/Myriad/Service/Remote.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« lib/Myriad/Service/Implementation.pm ↑ Summary lib/Myriad/RPC/Client/Implementation/Memory.pm »
1 package Myriad::Service::Remote;
2  
3 our $VERSION = '1.001'; # VERSION
4 our $AUTHORITY = 'cpan:DERIV'; # AUTHORITY
5  
6 =encoding utf8
7  
8 =head1 NAME
9  
10 Myriad::Service::Remote - abstraction to access other services over the network.
11  
12 =head1 SYNOPSIS
13  
14 my $remote_service = $api->service_by_name('service');
15 await $remote_service->call_api('some_method', %args);
16  
17 =head1 DESCRIPTION
18  
19 =cut
20  
21 14 ▶use Myriad::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 0 ▶use Myriad::Service::Storage::Remote;
Subroutine BEGIN: called CC=1 SCAR=2.6
23  
24 has $myriad;
25 has $service_name;
26 has $local_service_name;
27 has $storage;
28  
29 BUILD(%args) {
30 weaken($myriad = delete $args{myriad});
31 $service_name = delete $args{service_name} // die 'need a service name';
32 $local_service_name = delete $args{local_service_name};
33 $storage = Myriad::Service::Storage::Remote->new(
34 prefix => $service_name,
35 storage => $myriad->storage,
36 local_service_name => $local_service_name
37 );
38 }
39  
40 method service_name { $service_name }
41  
42 =head2 storage
43  
44 Returns a L<Myriad::Service::Storage::Remote> instance to access
45 the remote service public storage.
46  
47 =cut
48  
49 method storage { $storage }
50  
51 =head2 call_rpc
52  
53 Call a method on the remote service.
54  
55 it takes
56  
57 =over 4
58  
59 =item * C<rpc> - The remote method names.
60  
61 =item * C<args> - A hash of the method arguments.
62  
63 =back
64  
65 =cut
66  
67 async method call_rpc ($rpc, %args) {
68 await $myriad->rpc_client->call_rpc($service_name, $rpc, %args);
69 }
70  
71 =head2 subscribe
72  
73  
74 Please use the C<Receiver> attribute in Myriad.
75  
76 This method is implemented for the sake of compatibility with
77 the framework specs.
78  
79 it subscribes to a channel in the remote service.
80  
81 =cut
82  
83 async method subscribe ($channel, $client = "remote_service") {
84 my $sink = $myriad->ryu->sink;
85 await $myriad->subscription->create_from_sink(
86 sink => $sink,
87 service => $service_name,
88 client => $client,
89 channel => $channel,
90 );
91 return $sink->source;
92 }
93  
94 1;
95  
« lib/Myriad/Service/Implementation.pm ↑ Summary lib/Myriad/RPC/Client/Implementation/Memory.pm »