| 1 | package BusyBird::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 17 | ▶ | use v5.8.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use Scalar::Util qw(blessed weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Exporter 5.57 qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use BusyBird::DateTime::Format; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use BusyBird::Log qw(bblog); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use BusyBird::SafeData qw(safed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 17 | ▶ | use Future::Q 0.040; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 17 | our @EXPORT_OK = | |||||||||||||||||||||||||||||||||||||||||
| 17 | qw(set_param expand_param config_directory config_file_path sort_statuses | ||||||||||||||||||||||||||||||||||||||||||
| 18 | split_with_entities future_of make_tracking vivifiable_as); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 17 | our @CARP_NOT = qw(Future::Q); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1616 | ▶ | sub set_param { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_param: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1616 | my ($hashref, $params_ref, $key, $default, $is_mandatory) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1616 | ▶ | if($is_mandatory && !defined($params_ref->{$key})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_mandatory and not defined $params_ref->{$key}
MC/DC0%0/2
$is_mandatory and not defined $params_ref->{$key}
$is_mandatory
not defined $params_ref->{$key}
Truth table66%2/3
A and not(B)
A= $is_mandatoryB= not defined $params_ref->{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $classname = blessed $hashref; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | croak "ERROR: set_param in $classname: Parameter for '$key' is mandatory, but not supplied."; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 1616 | ▶ | $hashref->{$key} = (defined($params_ref->{$key}) ? $params_ref->{$key} : $default); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | ▶ | sub export_ok_all_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_ok_all_tags: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 17 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 8 | my ($caller_package) = caller; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 8 | my $export_ok = \@{"${caller_package}::EXPORT_OK"}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 8 | my $export_tags = \%{"${caller_package}::EXPORT_TAGS"}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | my @all = @$export_ok; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | foreach my $tag (keys %$export_tags) { | |||||||||||||||||||||||||||||||||||||||||
| 37 | 16 | my $exported = $export_tags->{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 16 | push(@all, @$exported); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 16 | push(@$export_ok, @$exported); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | $export_tags->{all} = \@all; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub expand_param { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_param: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my ($param, @names) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $refparam = ref($param); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my @result = (); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if($refparam eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | @result = @$param; | |||||||||||||||||||||||||||||||||||||||||
| 50 | }elsif($refparam eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | @result = @{$param}{@names}; | |||||||||||||||||||||||||||||||||||||||||
| 52 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $result[0] = $param; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return wantarray ? @result : $result[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub config_directory { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_directory: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return File::Spec->catfile(File::HomeDir->my_home, ".busybird"); | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub config_file_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_file_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my (@paths) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return File::Spec->catfile(config_directory, @paths); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 71 | ▶ | sub vivifiable_as { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vivifiable_as: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 71 | ▶ | return !defined($_[0]) || ref($_[0]) eq $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
!defined($_[0]) || ref $_[0] eq $_[1]
MC/DC100%2/2
!defined($_[0]) || ref $_[0] eq $_[1]
!defined($_[0])
ref $_[0] eq $_[1]
Truth table100%3/3
not(A) || B
A= !defined($_[0])B= ref $_[0] eq $_[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2916 | ▶ | sub _epoch_undef { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_epoch_undef: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2916 | my ($datetime_str) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 2916 | my $dt = BusyBird::DateTime::Format->parse_datetime($datetime_str); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 2916 | ▶ | return defined($dt) ? $dt->epoch : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 3513 | ▶ | sub _sort_compare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sort_compare: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 3513 | my ($a, $b) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 3513 | ▶ | if(defined($a) && defined($b)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
defined $a and defined $b
MC/DC100%2/2
defined $a and defined $b
defined $a
defined $b
Truth table100%3/3
A and B
A= defined $aB= defined $b
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 2355 | return $b <=> $a; | |||||||||||||||||||||||||||||||||||||||||
| 81 | ▶ | }elsif(!defined($a) && defined($b)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not defined $a and defined $b
MC/DC100%2/2
not defined $a and defined $b
not defined $a
defined $b
Truth table100%3/3
not(A) and B
A= not defined $aB= defined $b
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 73 | return -1; | |||||||||||||||||||||||||||||||||||||||||
| 83 | ▶ | }elsif(defined($a) && !defined($b)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $a and not defined $b
MC/DC50%1/2
defined $a and not defined $b
defined $a
not defined $b
Truth table66%2/3
A and not(B)
A= defined $aB= not defined $b
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 222 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 863 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 92 | ▶ | sub sort_statuses { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_statuses: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 92 | my ($statuses) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 17 | ▶ | use sort 'stable'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | my @dt_statuses = map { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 92 | my $safe_status = safed($_); | |||||||||||||||||||||||||||||||||||||||||
| 96 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 1458 | $_, | |||||||||||||||||||||||||||||||||||||||||
| 98 | _epoch_undef($safe_status->val("busybird", "acked_at")), | ||||||||||||||||||||||||||||||||||||||||||
| 99 | _epoch_undef($safe_status->val("created_at")), | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } @$statuses; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 1458 | return [ map { $_->[0] } sort { | |||||||||||||||||||||||||||||||||||||||||
| 103 | 92 | foreach my $sort_key (1, 2) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 3513 | my $ret = _sort_compare($a->[$sort_key], $b->[$sort_key]); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 3513 | ▶ | return $ret if $ret != 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 61 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } @dt_statuses]; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 94 | ▶ | sub _create_text_segment { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_text_segment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 94 | text => substr($_[0], $_[1], $_[2] - $_[1]), | |||||||||||||||||||||||||||||||||||||||||
| 114 | start => $_[1], | ||||||||||||||||||||||||||||||||||||||||||
| 115 | end => $_[2], | ||||||||||||||||||||||||||||||||||||||||||
| 116 | type => $_[3], | ||||||||||||||||||||||||||||||||||||||||||
| 117 | entity => $_[4], | ||||||||||||||||||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 32 | ▶ | sub split_with_entities { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_with_entities: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 32 | my ($text, $entities_hashref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 17 | ▶ | use sort 'stable'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 32 | ▶ | if(!defined($text)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | croak "text must not be undef"; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 31 | ▶ | if(ref($entities_hashref) ne "HASH") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 12 | return [_create_text_segment($text, 0, length($text))]; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | ## create entity segments | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 19 | my @entity_segments = (); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 19 | foreach my $entity_type (keys %$entities_hashref) { | |||||||||||||||||||||||||||||||||||||||||
| 134 | 50 | my $entities = $entities_hashref->{$entity_type}; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 50 | ▶ | next if ref($entities) ne "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 49 | foreach my $entity (@$entities) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | 46 | my $se = safed($entity); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 46 | my $start = $se->val("indices", 0); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 46 | my $end = $se->val("indices", 1); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 46 | ▶ | if(defined($start) && defined($end) && $start <= $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $start and defined $end and $start <= $end
defined $start and defined $end
MC/DC100%3/3
defined $start and defined $end and $start <= $end
defined $start
defined $end
$start <= $end
Truth table100%4/4
A and B and C
A= defined $startB= defined $endC= $start <= $end
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 41 | push(@entity_segments, _create_text_segment( | |||||||||||||||||||||||||||||||||||||||||
| 142 | $text, $start, $end, $entity_type, $entity | ||||||||||||||||||||||||||||||||||||||||||
| 143 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 19 | @entity_segments = sort { $a->{start} <=> $b->{start} } @entity_segments; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | ## combine entity_segments with non-entity segments | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 19 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 19 | my @final_segments = (); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 19 | foreach my $entity_segment (@entity_segments) { | |||||||||||||||||||||||||||||||||||||||||
| 153 | 41 | ▶ | if($pos < $entity_segment->{start}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | push(@final_segments, _create_text_segment( | ||||||||||||||||||||||||||||||||||||||||||
| 155 | $text, $pos, $entity_segment->{start} | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 30 | )); | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 41 | push(@final_segments, $entity_segment); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 41 | $pos = $entity_segment->{end}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 19 | ▶ | if($pos < length($text)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 11 | push(@final_segments, _create_text_segment( | |||||||||||||||||||||||||||||||||||||||||
| 163 | $text, $pos, length($text) | ||||||||||||||||||||||||||||||||||||||||||
| 164 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 19 | return \@final_segments; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 296 | ▶ | sub future_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
future_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 296 | my ($invocant, $method, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 296 | ▶ | return Future::Q->try(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 296 | ▶ | croak "invocant parameter is mandatory" if not defined $invocant; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 295 | ▶ | croak "method parameter is mandatory" if not defined $method; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 294 | ▶ | croak "invocant is not blessed" if not blessed $invocant; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 293 | ▶ | croak "no such method as $method" if not $invocant->can($method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 292 | my $f = Future::Q->new(); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 287 | ▶ | $invocant->$method(%args, callback => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 287 | my ($error, @results) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 287 | ▶ | if($error) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 6 | $f->reject($error, 1); | |||||||||||||||||||||||||||||||||||||||||
| 181 | }else { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 281 | $f->fulfill(@results); | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 292 | }); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 287 | return $f; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 296 | }); | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | sub make_tracking { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_tracking: called CC=6 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | my ($tracking_timeline, $main_timeline) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | ▶ | if(!blessed($tracking_timeline) || !$tracking_timeline->isa("BusyBird::Timeline")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($tracking_timeline) and $tracking_timeline->isa("BusyBird::Timeline")
MC/DC0%0/2
builtin::blessed($tracking_timeline) and $tracking_timeline->isa("BusyBird::Timeline")
builtin::blessed($tracking_timeline)
$tracking_timeline->isa("BusyBird::Timeline")
Truth table33%1/3
A and B
A= builtin::blessed($tracking_timeline)B= $tracking_timeline->isa("BusyBird::Timeline")
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | croak "tracking_timeline must be a BusyBird::Timeline."; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | ▶ | if(!blessed($main_timeline) || !$main_timeline->isa("BusyBird::Timeline")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($main_timeline) and $main_timeline->isa("BusyBird::Timeline")
MC/DC0%0/2
builtin::blessed($main_timeline) and $main_timeline->isa("BusyBird::Timeline")
builtin::blessed($main_timeline)
$main_timeline->isa("BusyBird::Timeline")
Truth table33%1/3
A and B
A= builtin::blessed($main_timeline)B= $main_timeline->isa("BusyBird::Timeline")
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | croak "main_timeline must be a BusyBird::Timeline."; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | my $name_tracking = $tracking_timeline->name; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | my $name_main = $main_timeline->name; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | ▶ | if($name_tracking eq $name_main) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | croak "tracking_timeline and main_timeline must be different timelines."; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | weaken(my $track = $tracking_timeline); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | ▶ | $tracking_timeline->add_filter_async(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | my ($statuses, $done) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 5 | ▶ | if(!defined($track)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $done->($statuses); | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | ▶ | $track->contains(query => $statuses, callback => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 5 | my ($error, $contained, $not_contained) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | ▶ | if(defined($error)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | bblog("error", "tracking timeline '$name_tracking' contains() error: $error"); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $done->($statuses); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 5 | ▶ | $main_timeline->add($not_contained, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | my ($error, $count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 5 | ▶ | if(defined($error)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | bblog("error", "main timeline '$name_main' add() error: $error"); | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | $done->($statuses); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 5 | }); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 5 | }); | |||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | }); | |||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | return $tracking_timeline; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | __END__ | ||||||||||||||||||||||||||||||||||||||||||