| 1 | package Qless::Lua; | ||||||||||||
| 2 | =head1 NAME | ||||||||||||
| 3 | |||||||||||||
| 4 | Qless::Lua | ||||||||||||
| 5 | |||||||||||||
| 6 | =cut | ||||||||||||
| 7 | |||||||||||||
| 8 | 1 | ▶ | use strict; use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use File::ShareDir qw(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 0 | ▶ | use overload '&{}' => sub { my $self = shift; sub { $self->call(@_) }; }, fallback => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 11 | |||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 13 | 0 | my $class = shift; | |||||||||||
| 14 | 0 | my ($name, $r) = @_; | |||||||||||
| 15 | |||||||||||||
| 16 | 0 | ▶ | $class = ref $class if ref $class; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 17 | 0 | my $self = bless {}, $class; | |||||||||||
| 18 | |||||||||||||
| 19 | 0 | $self->{'name'} = $name; | |||||||||||
| 20 | 0 | $self->{'redis'} = $r; | |||||||||||
| 21 | 0 | $self->{'sha'} = undef; | |||||||||||
| 22 | |||||||||||||
| 23 | 0 | $self; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | 0 | ▶ | sub reload { | ||||||||||
|
Subroutine
reload: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 27 | 0 | my ($self) = @_; | |||||||||||
| 28 | |||||||||||||
| 29 | 0 | my $filename = File::ShareDir::dist_file('Qless', $self->{'name'}.'.lua'); | |||||||||||
| 30 | 0 | ▶ | open my $fh, '<', $filename or die $!; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 0 | my $content = do { local $/; <$fh> }; | |||||||||||
| 32 | 0 | close $fh; | |||||||||||
| 33 | |||||||||||||
| 34 | 0 | return $self->{'sha'} = $self->{'redis'}->script('load', $content); | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | sub call { | ||||||||||
|
Subroutine
call: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||
| 38 | 0 | my ($self, $keys, @args) = @_; | |||||||||||
| 39 | |||||||||||||
| 40 | 0 | ▶ | $self->reload if !$self->{'sha'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | $keys ||= []; | ||||||||||
|
Condition0%0/2
$keys ||= []
MC/DC0%0/1
$keys ||= []
$keys
Truth table0%0/2
A
A= $keys
| |||||||||||||
| 43 | 0 | my $keys_count = scalar @{ $keys }; | |||||||||||
| 44 | |||||||||||||
| 45 | 0 | my $rv = eval { | |||||||||||
| 46 | 0 | ▶ | $self->{'redis'}->evalsha($self->{'sha'}, $keys_count, $keys_count ? @{ $keys } : (), @args); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | }; | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 0 | $self->reload; | |||||||||||
| 51 | 0 | ▶ | $rv = $self->{'redis'}->evalsha($self->{'sha'}, $keys_count, $keys_count ? @{ $keys } : (), @args); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 0 | return $rv; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 1 | 1; | |||||||||||