File Coverage

blib/lib/Async/Redis/Transaction.pm
Criterion Covered Total %
statement 11 29 37.9
branch 0 2 0.0
condition n/a
subroutine 4 9 44.4
pod 0 3 0.0
total 15 43 34.8


line stmt bran cond sub pod time code
1             package Async::Redis::Transaction;
2              
3 73     73   561 use strict;
  73         162  
  73         4438  
4 73     73   499 use warnings;
  73         165  
  73         5143  
5 73     73   1444 use 5.018;
  73         281  
6              
7 73     73   497 use Future::AsyncAwait;
  73         197  
  73         869  
8              
9             sub new {
10 0     0 0   my ($class, %args) = @_;
11             return bless {
12             redis => $args{redis},
13 0           commands => [],
14             }, $class;
15             }
16              
17             # Queue a command for execution in the transaction
18             # Returns a placeholder (the actual result comes from EXEC)
19             sub _queue_command {
20 0     0     my ($self, $cmd, @args) = @_;
21 0           push @{$self->{commands}}, [$cmd, @args];
  0            
22 0           return scalar(@{$self->{commands}}) - 1; # index of this command
  0            
23             }
24              
25             # Generate AUTOLOAD to capture any command call
26             our $AUTOLOAD;
27              
28             sub AUTOLOAD {
29 0     0     my $self = shift;
30 0           my $cmd = $AUTOLOAD;
31 0           $cmd =~ s/.*:://;
32 0 0         return if $cmd eq 'DESTROY';
33              
34             # Queue the command
35 0           $self->_queue_command(uc($cmd), @_);
36 0           return; # Transaction commands don't return Futures individually
37             }
38              
39             # Allow explicit command() calls too
40             sub command {
41 0     0 0   my ($self, $cmd, @args) = @_;
42 0           $self->_queue_command($cmd, @args);
43 0           return;
44             }
45              
46 0     0 0   sub commands { @{shift->{commands}} }
  0            
47              
48             1;
49              
50             __END__