Redis/Multi.pm

filter: Statementstmt 31.7% 20 / 63 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 40.0% 6 / 15 Podpod 33.3% 1 / 3 totaltotal 26.7% 27 / 101 CC 10 SCAR 18.5
CC
10
Cov
25%
__ANON__
12.0
__ANON__
12.0
DESTROY
12.0
CRAP 6.4
« Redis/Subscription.pm ↑ Summary Redis/Server/Connection.pm »
1 package Net::Async::Redis::Multi;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = '2.001'; # VERSION
7  
8 =head1 NAME
9  
10 Net::Async::Redis::Multi - represents multiple operations in a single Redis transaction
11  
12 =head1 DESCRIPTION
13  
14 Instances are generated by L<Net::Async::Redis/multi>.
15  
16 =cut
17  
18 7 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 sub new {
23 0 ▶ my ($class, %args) = @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
24 0 ▶ weaken($args{redis} // die 'Must be provided a Net::Async::Redis instance');
Condition0%0/2
$args{"redis"} // die("Must be provided a Net::Async::Redis instance")
l!l
00
MC/DC0%0/1
$args{"redis"} // die("Must be provided a Net::Async::Redis instance")
$args{"redis"}
Truth table0%0/2
A
A= $args{"redis"}
Aresult
11
00
25 0 bless \%args, $class;
26 }
27  
28 sub exec {
29 0 ▶ my ($self, $code) = @_;
Subroutine exec: not called CC=1 SCAR=6.9
Pod undocumented
30 0 $self->$code;
31 $self->redis->exec->then(sub {
32 0 ▶ my @reply = @{$_[0]};
Subroutine __ANON__: not called CC=3 SCAR=24.8
33 0 my $success = 0;
34 0 my $failure = 0;
35 0 ▶ while(my $queued = shift @{$self->{queued_requests}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $queued = shift @{$$self{"queued_requests"};}) 0 0 0
36 try {
37 0 my $reply = shift @reply;
38 0 ▶ $queued->done($reply) unless $queued->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $queued->is_ready 0 0 0
39 0 ++$success
40 0 } catch {
41 0 $log->warnf("Failure during transaction: %s", $@);
42 0 ++$failure
43 }
44 }
45 Future->done(
46 0 $success, $failure
47 )
48 }, sub {
49 0 ▶ my ($err, $category, @details) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
50 0 for my $queued (splice @{$self->{queued_requests}}) {
51 try {
52 0 ▶ $queued->fail("Transaction failed", redis => 'transaction_failure') unless $queued->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $queued->is_ready 0 0 0
53 0 } catch {
54 0 $log->warnf("Failure during transaction: %s", $@);
55 }
56 }
57 0 Future->fail($err, $category, @details);
58 0 })->retain
59 }
60  
61 =head2 redis
62  
63 Accessor for the L<Net::Async::Redis> instance.
64  
65 =cut
66  
67 0 ▶sub redis { shift->{redis} }
Subroutine redis: not called CC=1 SCAR=6.9
Pod documented
68  
69 sub AUTOLOAD {
70 0 ▶ my ($method) = our $AUTOLOAD =~ m{::([^:]+)$};
Subroutine AUTOLOAD: not called CC=2 SCAR=15.1
71 0 ▶ die "Unknown method $method" unless Net::Async::Redis::Commands->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless "Net::Async::Redis::Commands"->can($method) 0 0 0
72 my $code = sub {
73 0 ▶ my ($self, @args) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 local $self->redis->{_is_multi} = 1;
75 0 push @{$self->{queued_requests}}, my $f = $self->redis->$method(@args)->then(sub {
76 0 ▶ my ($resp) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
77 0 ▶ return $self->redis->future->set_label($method) if $resp eq 'QUEUED';
Branch: 1 branch
BranchTrueFalseTotal
if $resp eq "QUEUED" 0 0 0
78 0 Future->fail(@_)
79 0 });
80 0 $f
81 0 };
82 7 ▶ { no strict 'refs'; *$method = $code }
Subroutine BEGIN: called CC=1 SCAR=0.6
83 0 $code->(@_);
84 }
85  
86 sub DESTROY {
87 0 ▶ my ($self) = @_;
Subroutine DESTROY: not called CC=3 SCAR=24.8
88 0 ▶ return if ${^GLOBAL_PHASE} eq 'DESTRUCT' or not my $ev = $self->{queued_requests};
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" or not my $ev = $self->{"queued_requests"} 0 0 0
Condition0%0/3
${^GLOBAL_PHASE} eq "DESTRUCT" or not my $ev = $self->{"queued_requests"}
l!l&&r!l&&!r
000
MC/DC0%0/2
${^GLOBAL_PHASE} eq "DESTRUCT" or not my $ev = $self->{"queued_requests"}
${^GLOBAL_PHASE} eq "DESTRUCT" not my $ev = $self->{"queued_requests"}
Truth table0%0/3
A or not(B)
A= ${^GLOBAL_PHASE} eq "DESTRUCT"B= not my $ev = $self->{"queued_requests"}
ABresult
1X1
011
000
89 }
90  
91 7 1;
92  
93 __END__
« Redis/Subscription.pm ↑ Summary Redis/Server/Connection.pm »