| 1 | package Myriad::RPC; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | our $VERSION = '1.001'; # VERSION | |||||||||||||||||||
| 7 | 3 | our $AUTHORITY = 'cpan:DERIV'; # AUTHORITY | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =encoding utf8 | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Myriad::RPC - microservice RPC abstraction | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | my $rpc = $myriad->rpc; | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 3 | ▶ | no indirect qw(fatal); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 3 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 3 | ▶ | use Myriad::Exception::Builder category => 'rpc'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head1 Exceptions | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head2 InvalidRequest | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | Returned when there is issue parsing the request, or if the request parameters are incomplete. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 3 | declare_exception InvalidRequest => ( | |||||||||||||||||||
| 41 | message => 'Invalid request' | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =head2 MethodNotFound | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | Returned if the requested method is not recognized by the service. | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 3 | declare_exception MethodNotFound => ( | |||||||||||||||||||
| 51 | message => 'Method not found' | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head2 Timeout | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | Returned when there is an external timeout or the request deadline is already passed. | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 3 | declare_exception Timeout => ( | |||||||||||||||||||
| 61 | message => 'Timeout' | ||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =head2 BadEncoding | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | Returned when the service is unable to decode/encode the request correctly. | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 3 | declare_exception BadEncoding => ( | |||||||||||||||||||
| 71 | message => 'Bad encoding' | ||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head2 UnknownTransport | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | RPC transport does not exist. | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 3 | declare_exception UnknownTransport => ( | |||||||||||||||||||
| 81 | message => 'Unknown transport' | ||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =head1 METHODS | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 89 | 0 | my ($class, %args) = @_; | |||||||||||||||||||
| 90 | 0 | my $transport = delete $args{transport}; | |||||||||||||||||||
| 91 | 0 | weaken(my $myriad = delete $args{myriad}); | |||||||||||||||||||
| 92 | # Passing args individually looks tedious but this is to avoid | ||||||||||||||||||||
| 93 | # L<IO::Async::Notifier> exception when it doesn't recognize the key. | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | if ($transport eq 'redis') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 96 | 0 | require Myriad::RPC::Implementation::Redis; | |||||||||||||||||||
| 97 | 0 | return Myriad::RPC::Implementation::Redis->new( | |||||||||||||||||||
| 98 | redis => $myriad->redis_transport, | ||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||
| 100 | ▶ | } 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"
| |||||||||||||||||||||
| 101 | 0 | require Myriad::RPC::Implementation::Memory; | |||||||||||||||||||
| 102 | 0 | return Myriad::RPC::Implementation::Memory->new( | |||||||||||||||||||
| 103 | transport => $myriad->memory_transport, | ||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||
| 106 | 0 | Myriad::Exception::RPC::UnknownTransport->throw; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 3 | 1; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||