Q/ClaimFIFO/Item.pm

filter: Statementstmt 63.8% 23 / 36 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod n/a totaltotal 56.6% 30 / 53 CC 4 SCAR 11.7
CC
4
Cov
55%
_key
6.0
_serialized_data
6.0
_deserialize_data
6.0
CRAP 3.2
« Q/DistFIFO.pm ↑ Summary Q/ClaimFIFO/Perl.pm »
1 package Queue::Q::ClaimFIFO::Item;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Sereal::Decoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Sereal::Encoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Digest::MD5 (); # much faster than sha1 and good enough
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Class::XSAccessor {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 constructor => 'new',
10 getters => [qw(item_data)],
11 5 };
12  
13 5 ▶BEGIN { *data = \&item_data; }
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 our $SerealEncoder = Sereal::Encoder->new;
16 5 our $SerealDecoder = Sereal::Decoder->new;
17 5 our $MD5 = Digest::MD5->new;
18  
19 # for "friends" only
20 0 ▶sub _key {
Subroutine _key: not called CC=2 SCAR=17.9
21 0 my $self = shift;
22 return $self->{_key}
23 0 ▶ if defined $self->{_key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_key"} 0 0 0
24 0 $MD5->add($self->_serialized_data);
25 0 $MD5->add(rand(), time());
26 0 return( $self->{_key} = $MD5->digest );
27 }
28  
29 # for "friends" only
30 0 ▶sub _serialized_data {
Subroutine _serialized_data: not called CC=2 SCAR=17.9
31 0 my $self = shift;
32 return $self->{_serialized_data}
33 0 ▶ if defined $self->{_serialized_data};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_serialized_data"} 0 0 0
34 0 return( $self->{_serialized_data} = $self->_serialize_data($self->data) );
35 }
36  
37 # for "friends" only
38 0 ▶sub _serialize_data {
Subroutine _serialize_data: not called CC=1 SCAR=6.9
39 0 my $self = shift;
40 0 return $SerealEncoder->encode($_[0]);
41 }
42  
43 # for "friends" only
44 0 ▶sub _deserialize_data {
Subroutine _deserialize_data: not called CC=2 SCAR=17.9
45 0 my $self = shift;
46 0 ▶ return undef if not defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
47 0 return $SerealDecoder->decode($_[0]);
48 }
49  
50 5 1;
51 __END__
« Q/DistFIFO.pm ↑ Summary Q/ClaimFIFO/Perl.pm »