| 1 | package BusyBird::StatusStorage::Memory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use v5.8.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use parent ('BusyBird::StatusStorage'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use BusyBird::Util qw(set_param sort_statuses); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use BusyBird::Log qw(bblog); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use BusyBird::StatusStorage::Common qw(contains ack_statuses get_unacked_counts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use BusyBird::DateTime::Format; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use List::Util qw(min); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | my ($class, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | timelines => {}, ## timelines should always be sorted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | $self->set_param(\%options, 'max_status_num', 2000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | if($self->{max_status_num} <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | croak "max_status_num option must be bigger than 0."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my ($self, $level, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | bblog($level, $msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1057 | ▶ | sub _index { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_index: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1057 | my ($self, $timeline, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1057 | ▶ | return -1 if not defined($self->{timelines}{$timeline}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1012 | my $tl = $self->{timelines}{$timeline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1012 | my @ret = grep { $tl->[$_]{id} eq $id } 0..$#$tl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1012 | ▶ | confess "multiple IDs in timeline $timeline." if int(@ret) >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1012 | ▶ | return int(@ret) == 0 ? -1 : $ret[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4930 | ▶ | sub _acked { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_acked: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4930 | my ($self, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | no autovivification; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4930 | return $status->{busybird}{acked_at}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($self, $filepath) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if(not defined($filepath)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | croak '$filepath is not specified.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if(!open $file, ">", $filepath) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $self->_log("error", "Cannot open $filepath to write."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | print $file encode_json($self->{timelines}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $success = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | }catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->_log("error", "Error while saving: $e"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $success = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | close $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($self, $filepath) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if(not defined($filepath)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | croak '$filepath is not specified.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if(!open $file, "<", $filepath) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->_log("notice", "Cannot open $filepath to read"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $text = do { local $/; <$file> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->{timelines} = decode_json($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $success = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | }catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->_log("error", "Error while loading: $e"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $success = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | close $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1799 | ▶ | sub _is_timestamp_format_ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_timestamp_format_ok: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1799 | my ($timestamp_str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1799 | ▶ | return 1 if not defined $timestamp_str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ## It is very inefficient to parse $timestamp_str to check its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ## format, because creating a DateTime object takes long time. We | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | ## do it because BB::SS::Memory is just a reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ## implementation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1318 | return defined(BusyBird::DateTime::Format->parse_datetime($timestamp_str)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 121 | ▶ | sub put_statuses { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_statuses: called CC=25 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 121 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 121 | ▶ | croak 'timeline arg is mandatory' if not defined $args{timeline}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 120 | my $timeline = $args{timeline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 120 | ▶ | if(!defined($args{mode}) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not defined $args{"mode"} or $args{"mode"} ne "insert" and $args{"mode"} ne "update" and $args{"mode"} ne "upsert"
$args{"mode"} ne "insert" and $args{"mode"} ne "update" and $args{"mode"} ne "upsert"
$args{"mode"} ne "insert" and $args{"mode"} ne "update"
MC/DC25%1/4
not defined $args{"mode"} or $args{"mode"} ne "insert" and $args{"mode"} ne "update" and $args{"mode"} ne "upsert"
not defined $args{"mode"}
$args{"mode"} ne "insert"
$args{"mode"} ne "update"
$args{"mode"} ne "upsert"
Truth table80%4/5
not(A) or B and C and D
A= not defined $args{"mode"}B= $args{"mode"} ne "insert"C= $args{"mode"} ne "update"D= $args{"mode"} ne "upsert"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ($args{mode} ne 'insert' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | && $args{mode} ne 'update' && $args{mode} ne 'upsert')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | croak 'mode arg must be insert/update/upsert'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 119 | my $mode = $args{mode}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 119 | my $statuses; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 119 | ▶ | if(!defined($args{statuses})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | croak 'statuses arg is mandatory'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | }elsif(ref($args{statuses}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 28 | $statuses = [ $args{statuses} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | }elsif(ref($args{statuses}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 90 | $statuses = $args{statuses}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | croak 'statuses arg must be STATUS/ARRAYREF_OF_STATUSES'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 118 | foreach my $s (@$statuses) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | no autovivification; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 919 | ▶ | croak "{id} field is mandatory in statuses" if not defined $s->{id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 904 | ▶ | croak "{busybird} field must be a hash-ref if present" if defined($s->{busybird}) && ref($s->{busybird}) ne "HASH"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $$s{"busybird"} and ref $$s{"busybird"} ne "HASH"
MC/DC100%2/2
defined $$s{"busybird"} and ref $$s{"busybird"} ne "HASH"
defined $$s{"busybird"}
ref $$s{"busybird"} ne "HASH"
Truth table100%3/3
A and B
A= defined $$s{"busybird"}B= ref $$s{"busybird"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 901 | ▶ | croak "{created_at} field must be parsable by BusyBird::DateTime::Format" if !_is_timestamp_format_ok($s->{created_at}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 898 | my $acked_at = $s->{busybird}{acked_at}; ## avoid autovivification | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 898 | ▶ | croak "{busybird}{acked_at} field must be parsable by BusyBird::DateTime::Format" if !_is_timestamp_format_ok($acked_at); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 94 | my $put_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 94 | foreach my $status_index (reverse 0 .. $#$statuses) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 880 | my $s = $statuses->[$status_index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 880 | my $tl_index = $self->_index($timeline, $s->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 880 | my $existent = ($tl_index >= 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 880 | ▶ | next if ($mode eq 'insert' && $existent) || ($mode eq 'update' && !$existent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$mode eq "insert" and $existent or $mode eq "update" and not $existent
$mode eq "insert" and $existent
$mode eq "update" and not $existent
MC/DC100%4/4
$mode eq "insert" and $existent or $mode eq "update" and not $existent
$mode eq "insert"
$existent
$mode eq "update"
not $existent
Truth table71%5/7
A and B or C and not(D)
A= $mode eq "insert"B= $existentC= $mode eq "update"D= not $existent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 869 | my $is_insert = ($mode eq 'insert'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 869 | ▶ | if($mode eq 'upsert') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 24 | $is_insert = (!$existent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 869 | ▶ | if($is_insert) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 548 | unshift(@{$self->{timelines}{$timeline}}, dclone($s)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ## update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 321 | $self->{timelines}{$timeline}[$tl_index] = dclone($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 869 | $put_count++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 94 | ▶ | if($put_count > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 90 | $self->{timelines}{$timeline} = sort_statuses($self->{timelines}{$timeline}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 90 | ▶ | if(int(@{$self->{timelines}{$timeline}}) > $self->{max_status_num}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | splice(@{$self->{timelines}{$timeline}}, -(int(@{$self->{timelines}{$timeline}}) - $self->{max_status_num})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 94 | ▶ | if($args{callback}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 94 | @_ = (undef, $put_count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 94 | goto $args{callback}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 58 | ▶ | sub delete_statuses { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_statuses: called CC=14 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 58 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 58 | ▶ | croak 'timeline arg is mandatory' if not defined $args{timeline}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 57 | ▶ | croak 'ids arg is mandatory' if not exists $args{ids}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 56 | my $timeline = $args{timeline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 56 | my $ids = $args{ids}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 56 | ▶ | if(defined($ids)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 7 | ▶ | if(!ref($ids)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 2 | $ids = [$ids]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | }elsif(ref($ids) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 5 | ▶ | croak "ids arg array must not contain undef" if grep { !defined($_) } @$ids; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | croak "ids must be undef/ID/ARRAYREF_OF_IDS"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 55 | ▶ | if(!$self->{timelines}{$timeline}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 14 | ▶ | if($args{callback}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 14 | @_ = (undef, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 14 | goto $args{callback}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 41 | my $delete_num = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 41 | ▶ | if(defined($ids)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | foreach my $id (@$ids) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | my $tl_index = $self->_index($timeline, $id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | ▶ | last if $tl_index < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 7 | splice(@{$self->{timelines}{$timeline}}, $tl_index, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | $delete_num++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 36 | ▶ | if(defined($self->{timelines}{$timeline})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 36 | $delete_num = @{$self->{timelines}{$timeline}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 36 | delete $self->{timelines}{$timeline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 41 | ▶ | if($args{callback}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 41 | @_ = (undef, $delete_num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 41 | goto $args{callback}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 538 | ▶ | sub get_statuses { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_statuses: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 538 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 538 | ▶ | croak 'timeline arg is mandatory' if not defined $args{timeline}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 537 | ▶ | croak 'callback arg is mandatory' if not defined $args{callback}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 536 | my $timeline = $args{timeline}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 536 | ▶ | if(!$self->{timelines}{$timeline}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 68 | @_ = (undef, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 68 | goto $args{callback}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 468 | ▶ | my $ack_state = $args{ack_state} || 'any'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'ack_state'} || 'any'
MC/DC100%1/1
$args{'ack_state'} || 'any'
$args{'ack_state'}
Truth table100%2/2
A
A= $args{'ack_state'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 468 | my $max_id = $args{max_id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 468 | ▶ | my $count = defined($args{count}) ? $args{count} : 20; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 2866 | ▶ | my $ack_test = $ack_state eq 'unacked' ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 2866 | !$self->_acked(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 2064 | ▶ | } : $ack_state eq 'acked' ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2064 | $self->_acked(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 468 | ▶ | } : sub { 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 468 | my $start_index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 468 | ▶ | if(defined($max_id)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 169 | my $tl_index = $self->_index($timeline, $max_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 169 | ▶ | if($tl_index < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 23 | @_ = (undef, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 23 | goto $args{callback}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 146 | my $s = $self->{timelines}{$timeline}[$tl_index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 146 | ▶ | if(!$ack_test->($s)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 40 | @_ = (undef, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 40 | goto $args{callback}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 106 | $start_index = $tl_index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | my @indice = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 7905 | ▶ | if(!$ack_test->($self->{timelines}{$timeline}[$_])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2283 | 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ▶ | }elsif(defined($start_index) && $_ < $start_index) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $start_index and $_ < $start_index
MC/DC100%2/2
defined $start_index and $_ < $start_index
defined $start_index
$_ < $start_index
Truth table100%3/3
A and B
A= defined $start_indexB= $_ < $start_index
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 726 | 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | }else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4896 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 405 | } 0 .. $#{$self->{timelines}{$timeline}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 405 | ▶ | $count = int(@indice) if $count eq 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 405 | $count = min($count, int(@indice)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | my $result_statuses = $count <= 0 ? [] : [ map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 405 | ▶ | dclone($self->{timelines}{$timeline}[$_]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } @indice[0 .. ($count-1)] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 405 | @_ = (undef, $result_statuses); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 405 | goto $args{callback}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||