blib/lib/Async/Redis/Iterator.pm

filter: Statementstmt 33.3% 13 / 39 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 44.4% 4 / 9 Podpod 80.0% 4 / 5 totaltotal 24.1% 21 / 87 CC 13 SCAR 45.0
CC
13
Cov
20%
next
156.0
new
6.0
reset
2.0
CRAP 90.2
« blib/lib/Async/Redis/Subscription.pm ↑ Summary blib/lib/Async/Redis/Pipeline.pm »
1 package Async::Redis::Iterator;
2  
3 91 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 91 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 91 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 91 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
10 0 my ($class, %args) = @_;
11  
12 return bless {
13 redis => $args{redis},
14 command => $args{command} // 'SCAN',
15 key => $args{key}, # For HSCAN/SSCAN/ZSCAN
16 match => $args{match},
17 count => $args{count},
18 type => $args{type}, # For SCAN TYPE filter
19 0 ▶ cursor => 0,
Condition0%0/2
$args{"command"} // "SCAN"
l!l
00
MC/DC0%0/1
$args{"command"} // "SCAN"
$args{"command"}
Truth table0%0/2
A
A= $args{"command"}
Aresult
11
00
20 done => 0,
21 }, $class;
22 }
23  
24 0 ▶async sub next {
Subroutine next: not called CC=12 SCAR=50.5
Pod documented
25 0 my ($self) = @_;
26  
27 # Already exhausted
28 0 ▶ return undef if $self->{done};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done"} 0 0 0
29  
30 0 my @args;
31  
32 # Build command args based on scan type
33 0 ▶ if ($self->{command} eq 'SCAN') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'command'} eq 'SCAN') { } 0 0 0
34 0 @args = ($self->{cursor});
35 }
36 else {
37 # HSCAN, SSCAN, ZSCAN take key first, then cursor
38 0 @args = ($self->{key}, $self->{cursor});
39 }
40  
41 # Add MATCH pattern if specified
42 0 ▶ if (defined $self->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"match"}) 0 0 0
43 0 push @args, 'MATCH', $self->{match};
44 }
45  
46 # Add COUNT hint if specified
47 0 ▶ if (defined $self->{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"count"}) 0 0 0
48 0 push @args, 'COUNT', $self->{count};
49 }
50  
51 # Add TYPE filter for SCAN (Redis 6.0+)
52 0 ▶ if ($self->{command} eq 'SCAN' && defined $self->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"command"} eq "SCAN" and defined $self->{"type"}) 0 0 0
Condition0%0/3
$self->{"command"} eq "SCAN" and defined $self->{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"command"} eq "SCAN" and defined $self->{"type"}
$self->{"command"} eq "SCAN" defined $self->{"type"}
Truth table0%0/3
A and B
A= $self->{"command"} eq "SCAN"B= defined $self->{"type"}
ABresult
0X0
100
111
53 0 push @args, 'TYPE', $self->{type};
54 }
55  
56 # Execute scan command
57 0 my $result = await $self->{redis}->command($self->{command}, @args);
58  
59 # Result is [cursor, [elements...]]
60 0 my ($new_cursor, $elements) = @$result;
61  
62 # Update cursor
63 0 $self->{cursor} = $new_cursor;
64  
65 # Check if iteration complete (cursor returned to 0)
66 0 ▶ if ($new_cursor eq '0' || $new_cursor == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_cursor eq 0 or $new_cursor == 0) 0 0 0
Condition0%0/3
$new_cursor eq 0 or $new_cursor == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$new_cursor eq 0 or $new_cursor == 0
$new_cursor eq 0 $new_cursor == 0
Truth table0%0/3
A or B
A= $new_cursor eq 0B= $new_cursor == 0
ABresult
1X1
011
000
67 0 $self->{done} = 1;
68 }
69  
70 # Return batch (may be empty)
71 # Return undef only when done AND no elements in final batch
72 0 ▶ return $elements && @$elements ? $elements : ($self->{done} ? undef : []);
Branch: 2 branches
BranchTrueFalseTotal
$elements && @$elements ? : 0 0 0
$self->{'done'} ? : 0 0 0
Condition0%0/3
$elements and @$elements
!ll&&!rl&&r
000
MC/DC0%0/2
$elements and @$elements
$elements @$elements
Truth table0%0/3
A and B
A= $elementsB= @$elements
ABresult
0X0
100
111
73 91 }
74  
75 0 ▶sub reset {
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
76 0 my ($self) = @_;
77 0 $self->{cursor} = 0;
78 0 $self->{done} = 0;
79 }
80  
81 0 ▶sub cursor { shift->{cursor} }
Subroutine cursor: not called CC=1 SCAR=6.9
Pod documented
82 0 ▶sub done { shift->{done} }
Subroutine done: not called CC=1 SCAR=6.9
Pod documented
83  
84 91 1;
85  
86 __END__
« blib/lib/Async/Redis/Subscription.pm ↑ Summary blib/lib/Async/Redis/Pipeline.pm »