lib/Myriad/Storage.pm

filter: Statementstmt 54.2% 19 / 35 Branchbran 12.5% 1 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 43.1% 25 / 58 CC 7 SCAR 22.8
CC
7
Cov
42%
new
20.0
import
8.3
BEGIN
1.0
CRAP 9.8
« lib/Myriad/Subscription.pm ↑ Summary lib/Myriad/RPC/Client.pm »
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
BranchTrueFalseTotal
if (@args) 0 5 5
45 0 my ($varname) = (@args, '$storage');
46 0 ▶ $varname = $1 if $varname =~ /^\$(\w+)$/
Branch: 1 branch
BranchTrueFalseTotal
if $varname =~ /^\$(\w+)$/u or die 'invalid variable name ' . $varname 0 0 0
Condition0%0/2
$varname =~ /^\$(\w+)$/u or die 'invalid variable name ' . $varname
l!l
00
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
Aresult
11
00
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
BranchTrueFalseTotal
if ($transport eq 'redis') { } 0 0 0
elsif ($transport eq 'memory' or $transport eq 'perl') { } 0 0 0
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"
l!l&&r!l&&!r
000
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"
ABresult
1X1
011
000
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__
« lib/Myriad/Subscription.pm ↑ Summary lib/Myriad/RPC/Client.pm »