Qless/Lua.pm

filter: Statementstmt 28.8% 13 / 45 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 3 totaltotal 23.6% 17 / 72 CC 8 SCAR 28.7
CC
8
Cov
22%
call
42.0
new
6.0
reload
6.0
CRAP 17.6
« Qless/Worker.pm ↑ Summary Qless/Utils.pm »
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
BranchTrueFalseTotal
if ref $class 0 0 0
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
BranchTrueFalseTotal
open my $fh, "<", $filename or die $! 0 0 0
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
BranchTrueFalseTotal
unless $self->{"sha"} 0 0 0
41  
42 0 ▶ $keys ||= [];
Condition0%0/2
$keys ||= []
l!l
00
MC/DC0%0/1
$keys ||= []
$keys
Truth table0%0/2
A
A= $keys
Aresult
11
00
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
BranchTrueFalseTotal
$keys_count ? : 0 0 0
47 };
48  
49 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
50 0 $self->reload;
51 0 ▶ $rv = $self->{'redis'}->evalsha($self->{'sha'}, $keys_count, $keys_count ? @{ $keys } : (), @args);
Branch: 1 branch
BranchTrueFalseTotal
$keys_count ? : 0 0 0
52 }
53  
54 0 return $rv;
55 }
56  
57 1 1;
« Qless/Worker.pm ↑ Summary Qless/Utils.pm »