| 1 | package Async::Redis::Script; | ||||||||||||
| 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 | 91 | ▶ | use Digest::SHA qw(sha1_hex); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 11 | 0 | my ($class, %args) = @_; | |||||||||||
| 12 | |||||||||||||
| 13 | 0 | my $script = $args{script}; | |||||||||||
| 14 | 0 | ▶ | die "Script code required" unless defined $script; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 15 | |||||||||||||
| 16 | return bless { | ||||||||||||
| 17 | redis => $args{redis}, | ||||||||||||
| 18 | script => $script, | ||||||||||||
| 19 | sha => lc(sha1_hex($script)), | ||||||||||||
| 20 | name => $args{name}, | ||||||||||||
| 21 | num_keys => $args{num_keys} // 'dynamic', | ||||||||||||
| 22 | description => $args{description}, | ||||||||||||
| 23 | 0 | ▶ | }, $class; | ||||||||||
|
Condition0%0/2
$args{"num_keys"} // "dynamic"
MC/DC0%0/1
$args{"num_keys"} // "dynamic"
$args{"num_keys"}
Truth table0%0/2
A
A= $args{"num_keys"}
| |||||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | # Accessors | ||||||||||||
| 27 | 0 | ▶ | sub sha { shift->{sha} } | ||||||||||
|
Subroutine
sha: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 28 | 0 | ▶ | sub script { shift->{script} } | ||||||||||
|
Subroutine
script: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 29 | 0 | ▶ | sub name { shift->{name} } | ||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 30 | 0 | ▶ | sub num_keys { shift->{num_keys} } | ||||||||||
|
Subroutine
num_keys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 31 | 0 | ▶ | sub description { shift->{description} } | ||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 32 | 0 | ▶ | sub redis { shift->{redis} } | ||||||||||
|
Subroutine
redis: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 33 | |||||||||||||
| 34 | # Preferred entry point: run with explicit keys and args arrays | ||||||||||||
| 35 | # Usage: $script->run(\@keys, \@args) | ||||||||||||
| 36 | 0 | ▶ | async sub run { | ||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 37 | 0 | my ($self, $keys_aref, $args_aref) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | $keys_aref //= []; | ||||||||||
|
Condition0%0/2
$keys_aref //= []
MC/DC0%0/1
$keys_aref //= []
$keys_aref
Truth table0%0/2
A
A= $keys_aref
| |||||||||||||
| 40 | 0 | ▶ | $args_aref //= []; | ||||||||||
|
Condition0%0/2
$args_aref //= []
MC/DC0%0/1
$args_aref //= []
$args_aref
Truth table0%0/2
A
A= $args_aref
| |||||||||||||
| 41 | |||||||||||||
| 42 | 0 | my $numkeys = scalar @$keys_aref; | |||||||||||
| 43 | 0 | return await $self->call_with_keys($numkeys, @$keys_aref, @$args_aref); | |||||||||||
| 44 | 91 | } | |||||||||||
| 45 | |||||||||||||
| 46 | # Run on a specific connection (for pipeline/pool support) | ||||||||||||
| 47 | # Usage: $script->run_on($redis, \@keys, \@args) | ||||||||||||
| 48 | 0 | ▶ | async sub run_on { | ||||||||||
|
Subroutine
run_on: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 49 | 0 | my ($self, $redis, $keys_aref, $args_aref) = @_; | |||||||||||
| 50 | |||||||||||||
| 51 | 0 | ▶ | $keys_aref //= []; | ||||||||||
|
Condition0%0/2
$keys_aref //= []
MC/DC0%0/1
$keys_aref //= []
$keys_aref
Truth table0%0/2
A
A= $keys_aref
| |||||||||||||
| 52 | 0 | ▶ | $args_aref //= []; | ||||||||||
|
Condition0%0/2
$args_aref //= []
MC/DC0%0/1
$args_aref //= []
$args_aref
Truth table0%0/2
A
A= $args_aref
| |||||||||||||
| 53 | |||||||||||||
| 54 | 0 | my $numkeys = scalar @$keys_aref; | |||||||||||
| 55 | |||||||||||||
| 56 | return await $redis->evalsha_or_eval( | ||||||||||||
| 57 | $self->{sha}, | ||||||||||||
| 58 | $self->{script}, | ||||||||||||
| 59 | 0 | $numkeys, | |||||||||||
| 60 | @$keys_aref, | ||||||||||||
| 61 | @$args_aref, | ||||||||||||
| 62 | ); | ||||||||||||
| 63 | 91 | } | |||||||||||
| 64 | |||||||||||||
| 65 | # Legacy: call with automatic key count detection | ||||||||||||
| 66 | # Usage: $script->call('arg1', 'arg2') | ||||||||||||
| 67 | # Assumes all args are ARGV (no KEYS) | ||||||||||||
| 68 | 0 | ▶ | async sub call { | ||||||||||
|
Subroutine
call: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 69 | 0 | my ($self, @args) = @_; | |||||||||||
| 70 | 0 | return await $self->call_with_keys(0, @args); | |||||||||||
| 71 | 91 | } | |||||||||||
| 72 | |||||||||||||
| 73 | # Legacy: call with explicit key count | ||||||||||||
| 74 | # Usage: $script->call_with_keys($numkeys, @keys, @args) | ||||||||||||
| 75 | 0 | ▶ | async sub call_with_keys { | ||||||||||
|
Subroutine
call_with_keys: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 76 | 0 | my ($self, $numkeys, @keys_and_args) = @_; | |||||||||||
| 77 | |||||||||||||
| 78 | my $redis = $self->{redis} | ||||||||||||
| 79 | 0 | ▶ | or die "No Redis connection - use run_on() or pass redis to constructor"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | |||||||||||||
| 81 | return await $redis->evalsha_or_eval( | ||||||||||||
| 82 | $self->{sha}, | ||||||||||||
| 83 | $self->{script}, | ||||||||||||
| 84 | 0 | $numkeys, | |||||||||||
| 85 | @keys_and_args, | ||||||||||||
| 86 | ); | ||||||||||||
| 87 | 91 | } | |||||||||||
| 88 | |||||||||||||
| 89 | 91 | 1; | |||||||||||
| 90 | |||||||||||||
| 91 | __END__ | ||||||||||||