| 1 | package Queue::Q::ReliableFIFO::Item; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Class::XSAccessor {getters => ['_serialized']}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # for reasons of debugging, JSON is easier, while Sereal::* is | ||||||||||||||||||||||||||||
| 8 | # faster (about 7%) and delivers smaller serialized blobs. | ||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use JSON::XS; # use the real stuff, no fall back on pure Perl JSON please | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | my $serializer = JSON::XS->new->utf8->pretty(0); | |||||||||||||||||||||||||||
| 11 | 1 | my $deserializer = JSON::XS->new->utf8->pretty(0); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #use Sereal::Encoder; | ||||||||||||||||||||||||||||
| 14 | #use Sereal::Decoder; | ||||||||||||||||||||||||||||
| 15 | #my $serializer = Sereal::Encoder->new(); | ||||||||||||||||||||||||||||
| 16 | #my $deserializer = Sereal::Decoder->new(); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | my @item_info = ( | |||||||||||||||||||||||||||
| 19 | 't', # time the item was created | ||||||||||||||||||||||||||||
| 20 | 'rc', # requeue counter (how often the item is requeued) | ||||||||||||||||||||||||||||
| 21 | 'fc', # fail counter (how often the item reached max-requeue) | ||||||||||||||||||||||||||||
| 22 | 'error', # last error message | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | 0 | my $self = bless { @_ }, $class; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | die "'data' or '_serialized' named parameters required for constructor" | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if not exists $self->{data} and not exists $self->{_serialized}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $self->{"data"} or exists $self->{"_serialized"}
MC/DC0%0/2
exists $self->{"data"} or exists $self->{"_serialized"}
exists $self->{"data"}
exists $self->{"_serialized"}
Truth table0%0/3
A or B
A= exists $self->{"data"}B= exists $self->{"_serialized"}
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (not exists $self->{_serialized}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | $self->{_serialized} ||= | ||||||||||||||||||||||||||||
| 34 | $serializer->encode({ | ||||||||||||||||||||||||||||
| 35 | t => time(), | ||||||||||||||||||||||||||||
| 36 | b => $self->{data} | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | }); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_serialized"} ||= $serializer->encode({"t", time, "b", $self->{"data"}})
MC/DC0%0/2
$self->{"_serialized"} ||= $serializer->encode({"t", time, "b", $self->{"data"}})
$self->{"_serialized"}
$serializer->encode({"t", time, "b", $self->{"data"}})
Truth table0%0/3
A ||= B
A= $self->{"_serialized"}B= $serializer->encode({"t", time, "b", $self->{"data"}})
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub _get { | ||||||||||||||||||||||||||
|
Subroutine
_get: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 43 | 0 | my ($self, $elem) = @_; | |||||||||||||||||||||||||||
| 44 | $self->_deserialize | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if not exists $self->{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | return $self->{$elem}; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub time_created { $_[0]->_get('t_created') || $_[0]->_get('t') } | ||||||||||||||||||||||||||
|
Subroutine
time_created: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub time_queued { $_[0]->_get('t') } | ||||||||||||||||||||||||||
|
Subroutine
time_queued: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub data { $_[0]->_get('data') } | ||||||||||||||||||||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub requeue_count { $_[0]->_get('rc') || 0 } | ||||||||||||||||||||||||||
|
Subroutine
requeue_count: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub fail_count { $_[0]->_get('fc') || 0 } | ||||||||||||||||||||||||||
|
Subroutine
fail_count: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub last_error { $_[0]->_get('error') } | ||||||||||||||||||||||||||
|
Subroutine
last_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub inc_nr_requeues { | ||||||||||||||||||||||||||
|
Subroutine
inc_nr_requeues: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 0 | my $plain = $deserializer->decode($self->{_serialized}); | |||||||||||||||||||||||||||
| 59 | 0 | $self->{rc} = ++$plain->{rc}; | |||||||||||||||||||||||||||
| 60 | 0 | $self->{_serialized} = $serializer->encode($plain); | |||||||||||||||||||||||||||
| 61 | 0 | return $self->{rc}; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _deserialize { | ||||||||||||||||||||||||||
|
Subroutine
_deserialize: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 0 | my $plain = $deserializer->decode($self->{_serialized}); | |||||||||||||||||||||||||||
| 67 | 0 | $self->{data} = $plain->{b}; | |||||||||||||||||||||||||||
| 68 | 0 | for my $k (@item_info) { | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (exists $plain->{$k}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | $self->{$k} = $plain->{$k}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | delete $self->{$k}; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 1 | 1; | |||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||