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 2 3 66.6
total 17 43 39.5


line stmt bran cond sub pod time code
1             package Async::Redis::Transaction;
2              
3 91     91   486 use strict;
  91         136  
  91         3216  
4 91     91   319 use warnings;
  91         136  
  91         4184  
5 91     91   1210 use 5.018;
  91         238  
6              
7 91     91   342 use Future::AsyncAwait;
  91         119  
  91         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 1   my ($self, $cmd, @args) = @_;
42 0           $self->_queue_command($cmd, @args);
43 0           return;
44             }
45              
46 0     0 1   sub commands { @{shift->{commands}} }
  0            
47              
48             1;
49              
50             __END__