Candy/Array.pm

filter: Statementstmt 93.3% 42 / 45 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 14 / 18 Podpod n/a totaltotal 85.9% 61 / 71 SCAR 19.6
CC
7
Cov
89%
POP
2.0
SHIFT
2.0
TIEARRAY
2.0
CRAP 7.1
↑ Summary Candy/Hash.pm »
1 # This file was part of Redis, licensed under:
2 #
3 # The Artistic License 2.0 (GPL Compatible)
4 #
5 # Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
6  
7 package Tie::Redis::Candy::Array;
8  
9 # ABSTRACT: tie Perl arrays to Redis lists - the candy way
10  
11 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp qw(croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use CBOR::XS qw(encode_cbor decode_cbor);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use base 'Tie::Array';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 my $undef = encode_cbor(undef);
18  
19 2 our $VERSION = '1.000'; # VERSION
20  
21 sub TIEARRAY {
22 2 ▶ my ( $class, $redis, $listname ) = @_;
Subroutine TIEARRAY: called CC=2 SCAR=7.0
23  
24 2 ▶ croak "not a Redis instance: $redis"
Branch: 1 branch
BranchTrueFalseTotal
unless ref($redis) =~ /^(?:Test::Mock::)?Redis$/ 0 2 2
25 unless ref($redis) =~ m{^(?:Test::Mock::)?Redis$};
26  
27 2 my $self = {
28 list => $listname,
29 redis => $redis,
30 };
31  
32 2 return bless( $self, $class );
33 }
34  
35 sub FETCH {
36 51 ▶ my ( $self, $index ) = @_;
Subroutine FETCH: called CC=2 SCAR=6.9
37 51 my $data = $self->{redis}->lindex( $self->{list}, $index );
38 51 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 1 50 51
39 50 decode_cbor($data);
40 }
41  
42 sub FETCHSIZE {
43 67 ▶ my ($self) = @_;
Subroutine FETCHSIZE: called CC=1 SCAR=0.0
44 67 $self->{redis}->llen( $self->{list} );
45 }
46  
47 sub STORE {
48 2 ▶ my ( $self, $index, $value ) = @_;
Subroutine STORE: called CC=1 SCAR=0.0
49 2 $self->{redis}->lset( $self->{list}, $index, encode_cbor($value) );
50 }
51  
52 sub STORESIZE {
53 0 ▶ my ( $self, $count ) = @_;
Subroutine STORESIZE: not called CC=1 SCAR=6.9
54 0 $self->{redis}->ltrim( $self->{list}, 0, $count );
55 }
56  
57 sub CLEAR {
58 1 ▶ my ($self) = @_;
Subroutine CLEAR: called CC=1 SCAR=0.0
59 1 $self->{redis}->del( $self->{list} );
60 }
61  
62 sub PUSH {
63 5 ▶ my ( $self, @values ) = @_;
Subroutine PUSH: called CC=2 SCAR=6.9
64 5 $self->{redis}->rpush( $self->{list}, encode_cbor($_) ) for @values;
65 }
66  
67 sub POP {
68 1 ▶ my ($self) = @_;
Subroutine POP: called CC=2 SCAR=7.1
69 1 ▶ map { defined($_) ? decode_cbor($_) : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1 0 1
70 1 $self->{redis}->rpop( $self->{list} );
71 }
72  
73 sub SHIFT {
74 1 ▶ my ($self) = @_;
Subroutine SHIFT: called CC=2 SCAR=7.1
75 1 ▶ map { defined($_) ? decode_cbor($_) : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1 0 1
76 1 $self->{redis}->lpop( $self->{list} );
77 }
78  
79 sub UNSHIFT {
80 1 ▶ my ( $self, @values ) = @_;
Subroutine UNSHIFT: called CC=2 SCAR=6.9
81 1 $self->{redis}->lpush( $self->{list}, encode_cbor($_) ) for reverse @values;
82 }
83  
84 sub SPLICE {
85 0 ▶ confess 'UNIMPLEMENTED';
Subroutine SPLICE: not called CC=1 SCAR=6.9
86 }
87  
88 ▶sub EXTEND {
Subroutine EXTEND: not called CC=1 SCAR=0.0
89 }
90  
91 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
92 }
93  
94 2 1;
95  
96 __END__
↑ Summary Candy/Hash.pm »