lib/Myriad/Service/Storage/Remote.pm

filter: Statementstmt 68.4% 13 / 19 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 57.1% 4 / 7 Podpod n/a totaltotal 58.6% 17 / 29 CC 3 SCAR 8.9
CC
3
Cov
62%
__ANON__
6.0
BEGIN
3.2
__ANON__
2.0
CRAP 2.4
« lib/Myriad/Service/Storage.pm ↑ Summary lib/Myriad/Exception/General.pm »
1 package Myriad::Service::Storage::Remote;
2  
3 15 ▶use Myriad::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 our $VERSION = '1.001'; # VERSION
6 our $AUTHORITY = 'cpan:DERIV'; # AUTHORITY
7  
8 =encoding utf8
9  
10 =head1 NAME
11  
12 Myriad::Service::Storage::Remote - abstraction to access other services storage.
13  
14 =head1 SYNOPSIS
15  
16 my $storage = $api->service_by_name('service')->storage;
17 await $storage->get('some_key');
18  
19 =head1 DESCRIPTION
20  
21 =cut
22  
23 15 ▶use Myriad::Role::Storage;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 15 ▶use Metrics::Any qw($metrics);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 15 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=11.6
28  
29 15 $metrics->make_timer(time_elapsed =>
30 name => [qw(myriad storage remote)],
31 description => 'Time taken to process remote storage request',
32 labels => [qw(method status service)],
33 );
34  
35 15 my $meta = Object::Pad::MOP::Class->for_class('Myriad::Service::Storage::Remote');
36  
37 15 for my $method (@Myriad::Role::Storage::READ_METHODS) {
38 0 ▶ $meta->add_method($method, sub {
Subroutine orderedset_member_count: not called CC=1 SCAR=6.9
Subroutine hash_count: not called CC=1 SCAR=6.9
39 0 my ($self, $key, @rest) = @_;
40 0 ▶ return $self->storage->$method($self->apply_prefix($key), @rest)->on_ready(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
41 0 my $f = shift;
42 0 ▶ $metrics->report_timer(time_elapsed =>
Condition0%0/2
$f->elapsed // 0
l!l
00
MC/DC0%0/1
$f->elapsed // 0
$f->elapsed
Truth table0%0/2
A
A= $f->elapsed
Aresult
11
00
43 $f->elapsed // 0, {method => $method, status => $f->state, service => $self->local_service_name});
44 0 });
45 165 });
46 }
47 }
48  
49  
50 has $prefix;
51 has $storage;
52 has $local_service_name;
53 method storage { $storage };
54 method local_service_name { $local_service_name // 'local' };
55  
56 BUILD (%args) {
57 my $service_prefix = delete $args{prefix} // die 'need a prefix';
58 $prefix = "service.$service_prefix";
59 $storage = delete $args{storage} // die 'need a storage instance';
60 $local_service_name = delete $args{local_service_name};
61 }
62  
63 =head2 apply_prefix
64  
65 Maps the requested key into the service's keyspace
66 so we can pass it over to the generic storage layer.
67  
68 Takes the following parameters:
69  
70 =over 4
71  
72 =item * C<$k> - the key
73  
74 =back
75  
76 Returns the modified key.
77  
78 =cut
79  
80 method apply_prefix ($k) {
81 return $prefix . '/' . $k;
82 }
83  
84 1;
85  
86 =head1 AUTHOR
87  
88 Deriv Group Services Ltd. C<< DERIV@cpan.org >>.
89  
90 See L<Myriad/CONTRIBUTORS> for full details.
91  
92 =head1 LICENSE
93  
94 Copyright Deriv Group Services Ltd 2020-2022. Licensed under the same terms as Perl itself.
95  
96  
« lib/Myriad/Service/Storage.pm ↑ Summary lib/Myriad/Exception/General.pm »