| 1 | package Myriad::RPC::Client; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.001'; # VERSION | |||||||||||||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:DERIV'; # AUTHORITY | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =encoding utf8 | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Myriad::RPC::Client - microservice RPC client abstraction | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | my $client = $myriad->rpc_client; | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | ▶ | no indirect qw(fatal); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 1 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | ▶ | use Myriad::Exception::Builder category => 'rpc_client'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head2 Exceptions | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head2 RPCFailed | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | The RPC call has been performed correctly but the results are an error. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | declare_exception RPCFailed => (message => 'Your operation failed'); | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head2 UnknownTransport | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | RPC transport does not exist. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | declare_exception UnknownTransport => ( | |||||||||||||||||||
| 49 | message => 'Unknown transport' | ||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 53 | 0 | my ($class, %args) = @_; | |||||||||||||||||||
| 54 | 0 | my $transport = delete $args{transport}; | |||||||||||||||||||
| 55 | 0 | weaken(my $myriad = delete $args{myriad}); | |||||||||||||||||||
| 56 | # Passing args individually looks tedious but this is to avoid | ||||||||||||||||||||
| 57 | # L<IO::Async::Notifier> exception when it doesn't recognize the key. | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | if ($transport eq 'redis') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 60 | 0 | require Myriad::RPC::Client::Implementation::Redis; | |||||||||||||||||||
| 61 | 0 | return Myriad::RPC::Client::Implementation::Redis->new( | |||||||||||||||||||
| 62 | redis => $myriad->redis_transport, | ||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||
| 64 | ▶ | } elsif ($transport eq 'memory' or $transport eq 'perl') { | |||||||||||||||||||
|
Condition0%0/3
$transport eq "memory" or $transport eq "perl"
MC/DC0%0/2
$transport eq "memory" or $transport eq "perl"
$transport eq "memory"
$transport eq "perl"
Truth table0%0/3
A or B
A= $transport eq "memory"B= $transport eq "perl"
| |||||||||||||||||||||
| 65 | 0 | require Myriad::RPC::Client::Implementation::Memory; | |||||||||||||||||||
| 66 | 0 | return Myriad::RPC::Client::Implementation::Memory->new( | |||||||||||||||||||
| 67 | transport => $myriad->memory_transport | ||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||
| 70 | 0 | Myriad::Exception::RPC::Client::UnknownTransport->throw(); | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 1 | 1; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =head1 AUTHOR | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | Deriv Group Services Ltd. C<< DERIV@cpan.org >>. | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | See L<Myriad/CONTRIBUTORS> for full details. | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head1 LICENSE | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | Copyright Deriv Group Services Ltd 2020-2022. Licensed under the same terms as Perl itself. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||