Redis/Cluster/Multi.pm

filter: Statementstmt 44.7% 30 / 67 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 56.2% 9 / 16 Podpod 33.3% 1 / 3 totaltotal 36.3% 40 / 110 CC 10 SCAR 20.0
CC
10
Cov
35%
DESTROY
20.0
new
12.0
exec
12.0
CRAP 7.4
« Redis/Subscription.pm ↑ Summary Redis/Commands.pm »
1 package Net::Async::Redis::Cluster::Multi;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '6.006'; # 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 4 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Syntax::Keyword::Dynamically;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use Scalar::Util qw(weaken blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use Sub::Util qw(set_subname);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
27 0 my ($class, %args) = @_;
28 0 ▶ $args{queued_requests} //= [];
Condition0%0/2
$args{"queued_requests"} //= []
l!l
00
MC/DC0%0/1
$args{"queued_requests"} //= []
$args{"queued_requests"}
Truth table0%0/2
A
A= $args{"queued_requests"}
Aresult
11
00
29 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
30 0 bless \%args, $class;
31 }
32  
33 0 ▶async sub exec {
Subroutine exec: not called CC=3 SCAR=24.8
Pod undocumented
34 0 my ($self, $code) = @_;
35  
36 try {
37 0 my $f = $self->$code;
38 0 ▶ $f->retain if blessed($f) and $f->isa('Future');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($f) and $f->isa("Future") 0 0 0
Condition0%0/3
builtin::blessed($f) and $f->isa("Future")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($f) and $f->isa("Future")
builtin::blessed($f) $f->isa("Future")
Truth table0%0/3
A and B
A= builtin::blessed($f)B= $f->isa("Future")
ABresult
0X0
100
111
39 0 return 0;
40 0 } catch {
41 0 my $err = $@;
42 0 $log->errorf('Failed to complete multi - %s', $err);
43 0 die $@;
44 }
45 4 }
46  
47 =head2 redis
48  
49 Accessor for the L<Net::Async::Redis> instance.
50  
51 =cut
52  
53 0 ▶sub redis { shift->{redis} }
Subroutine redis: not called CC=1 SCAR=6.9
Pod documented
54  
55 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=15.3
56 0 my ($method) = our $AUTOLOAD =~ m{::([^:]+)$};
57  
58 # We only need to check this once
59 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
60  
61 0 ▶ my $code = async sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
62 0 my ($self, @args) = @_;
63 0 my $f = $self->redis->future->set_label($method);
64 0 push @{$self->{queued_requests}}, $f;
65 0 my $node = await $self->redis->find_node($method => @args);
66 0 ▶ my $multi = $self->{multi}{$node->id} or die 'node not found - ' . $node;
Branch: 1 branch
BranchTrueFalseTotal
my $multi = $$self{"multi"}{$node->id} or die 'node not found - ' . $node 0 0 0
67 0 return await $multi->$method(@args);
68 0 };
69 0 set_subname $method => $code;
70 0 ▶ { no strict 'refs'; *$method = sub { $code->(@_)->retain } }
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
71 0 $code->(@_)->retain;
72 }
73  
74 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
75 0 my ($self) = @_;
76 0 ▶ return if ${^GLOBAL_PHASE} eq 'DESTRUCT' or not $self->{queued_requests};
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" or not $$self{"queued_requests"} 0 0 0
Condition0%0/3
${^GLOBAL_PHASE} eq "DESTRUCT" or not $$self{"queued_requests"}
l!l&&r!l&&!r
000
MC/DC0%0/2
${^GLOBAL_PHASE} eq "DESTRUCT" or not $$self{"queued_requests"}
${^GLOBAL_PHASE} eq "DESTRUCT" not $$self{"queued_requests"}
Truth table0%0/3
A or not(B)
A= ${^GLOBAL_PHASE} eq "DESTRUCT"B= not $$self{"queued_requests"}
ABresult
1X1
011
000
77  
78 0 for my $queued (splice @{$self->{queued_requests}}) {
79 try {
80 0 $queued->cancel;
81 0 } catch {
82 0 $log->warnf("Failure during cleanup: %s", $@);
83 }
84 }
85 }
86  
87 4 1;
88  
89 __END__
« Redis/Subscription.pm ↑ Summary Redis/Commands.pm »