| 1 | package Myriad::Storage; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 6 | ▶ | use Myriad::Class class => ''; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 6 | our $VERSION = '1.001'; # VERSION | |||||||||||||||||||
| 6 | 6 | our $AUTHORITY = 'cpan:DERIV'; # AUTHORITY | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =encoding utf8 | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | Myriad::Storage - microservice Storage abstraction | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | my $storage = Myriad::Storage->new(); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 6 | ▶ | use Myriad::Role::Storage; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 6 | ▶ | use Myriad::Exception::Builder category => 'storage'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =head1 Exceptions | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head2 UnknownTransport | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | RPC transport does not exist. | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 6 | declare_exception UnknownTransport => ( | |||||||||||||||||||
| 37 | message => 'Unknown transport' | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 6 | our $STORAGE; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 5 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=21.2
| |||||||||||||||||||||
| 43 | 5 | my ($class, @args) = @_; | |||||||||||||||||||
| 44 | 5 | ▶ | if(@args) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | my ($varname) = (@args, '$storage'); | |||||||||||||||||||
| 46 | 0 | ▶ | $varname = $1 if $varname =~ /^\$(\w+)$/ | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$varname =~ /^\$(\w+)$/u or die 'invalid variable name ' . $varname
MC/DC0%0/1
$varname =~ /^\$(\w+)$/u or die 'invalid variable name ' . $varname
$varname =~ /^\$(\w+)$/u
Truth table0%0/2
A
A= $varname =~ /^\$(\w+)$/u
| |||||||||||||||||||||
| 47 | or die 'invalid variable name ' . $varname; | ||||||||||||||||||||
| 48 | 0 | my $caller = caller; | |||||||||||||||||||
| 49 | { | ||||||||||||||||||||
| 50 | 0 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||
| 51 | 0 | *{"${caller}::${varname}"} = weaken(\$STORAGE); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 57 | 0 | my ($class, %args) = @_; | |||||||||||||||||||
| 58 | 0 | my $transport = delete $args{transport}; | |||||||||||||||||||
| 59 | 0 | weaken(my $myriad = delete $args{myriad}); | |||||||||||||||||||
| 60 | # Passing args individually looks tedious but this is to avoid | ||||||||||||||||||||
| 61 | # L<IO::Async::Notifier> exception when it doesn't recognize the key. | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | ▶ | if ($transport eq 'redis') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 64 | 0 | require Myriad::Storage::Implementation::Redis; | |||||||||||||||||||
| 65 | 0 | $STORAGE = Myriad::Storage::Implementation::Redis->new( | |||||||||||||||||||
| 66 | redis => $myriad->redis_transport, | ||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||
| 68 | ▶ | } 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"
| |||||||||||||||||||||
| 69 | 0 | require Myriad::Storage::Implementation::Memory; | |||||||||||||||||||
| 70 | 0 | $STORAGE = Myriad::Storage::Implementation::Memory->new(); | |||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||
| 72 | 0 | Myriad::Exception::Storage::UnKnownTransport->throw(); | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | return $STORAGE; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 6 | 1; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||