| 1 | package AnyEvent::Delay::Simple; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use AnyEvent (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 8 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 8 | our @EXPORT = qw(delay); | |||||||||||||||||||||||||||
| 16 | 8 | our @EXPORT_OK = qw(easy_delay); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 20 | 8 | my ($class, @args) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 8 | my (@ae, @up); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 8 | foreach (@args) { | |||||||||||||||||||||||||||
| 25 | 11 | ▶ | if ($_ && /^AE::(.+)?/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ and /^AE::(.+)?/
MC/DC50%1/2
$_ and /^AE::(.+)?/
$_
/^AE::(.+)?/
Truth table66%2/3
A and B
A= $_B= /^AE::(.+)?/
| |||||||||||||||||||||||||||||
| 26 | 2 | push(@ae, $1); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | else { | ||||||||||||||||||||||||||||
| 29 | 9 | push(@up, $_); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 8 | ▶ | if (@ae) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 1 | $class->export('AE', @ae); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 8 | ▶ | if (@up) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 6 | $class->export_to_level(1, undef, @up); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 8 | ▶ | sub delay { | ||||||||||||||||||||||||||
|
Subroutine
delay: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 8 | my ($obj, $fin); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 8 | ▶ | if (blessed($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 2 | $obj = shift(); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 8 | $fin = pop(); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 8 | ▶ | return unless $fin; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 8 | my ($subs, $err); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 8 | ▶ | if (ref($_[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 3 | $subs = shift(); | |||||||||||||||||||||||||||
| 54 | 3 | $err = pop(); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 5 | $err = pop(); | |||||||||||||||||||||||||||
| 58 | 5 | $subs = \@_; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 8 | my $cv = AE::cv; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 8 | $cv->begin(); | |||||||||||||||||||||||||||
| 64 | 3 | ▶ | $cv->cb(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 3 | _delay_step($obj, [$fin], undef, [$cv->recv()], $cv); | |||||||||||||||||||||||||||
| 66 | 8 | }); | |||||||||||||||||||||||||||
| 67 | 8 | _delay_step($obj, $subs, $err, $cv); | |||||||||||||||||||||||||||
| 68 | 8 | $cv->end(); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 8 | return; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 49 | ▶ | sub _delay_step { | ||||||||||||||||||||||||||
|
Subroutine
_delay_step: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 74 | 49 | my $cv = pop(); | |||||||||||||||||||||||||||
| 75 | 49 | my ($obj, $subs, $err, $args) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 49 | my $sub = shift(@$subs); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 49 | ▶ | unless (defined($args)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 8 | $args = []; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 49 | ▶ | unless ($sub) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 11 | $cv->send(@$args); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 11 | return; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 38 | $cv->begin(); | |||||||||||||||||||||||||||
| 89 | 38 | ▶ | AE::postpone { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 90 | 38 | my @res; | |||||||||||||||||||||||||||
| 91 | 38 | my $xcv = AE::cv; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 38 | $xcv->begin(); | |||||||||||||||||||||||||||
| 94 | 38 | ▶ | if ($err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 20 | eval { | |||||||||||||||||||||||||||
| 96 | 20 | ▶ | $sub->($obj ? $obj : (), @$args, $xcv); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||
| 98 | 20 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 4 | _delay_err($obj, $err, $@, $cv); | |||||||||||||||||||||||||||
| 100 | 4 | undef($xcv); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||
| 103 | 16 | _delay_step_ex($obj, $subs, $err, $xcv, $cv); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||
| 107 | 18 | ▶ | $sub->($obj ? $obj : (), @$args, $xcv); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 18 | _delay_step_ex($obj, $subs, $err, $xcv, $cv); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 38 | }; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 38 | return; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 34 | ▶ | sub _delay_step_ex { | ||||||||||||||||||||||||||
|
Subroutine
_delay_step_ex: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | 34 | my ($obj, $subs, $err, $xcv, $cv) = @_; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 34 | my $cb = $xcv->cb(); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 34 | ▶ | $xcv->cb(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 121 | 34 | ▶ | if ($cb) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 1 | ▶ | if ($err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 1 | eval { | |||||||||||||||||||||||||||
| 124 | 1 | $cb->(); | |||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||
| 126 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | _delay_err($obj, $err, $@, $cv); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | return; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||
| 133 | 0 | $cb->(); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 33 | _delay_step($obj, $subs, $err, [$xcv->recv()], $cv); | |||||||||||||||||||||||||||
| 137 | 33 | $cv->end(); | |||||||||||||||||||||||||||
| 138 | 34 | }); | |||||||||||||||||||||||||||
| 139 | 34 | $xcv->end(); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 34 | return; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 5 | ▶ | sub _delay_err { | ||||||||||||||||||||||||||
|
Subroutine
_delay_err: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 145 | 5 | my ($obj, $err, $msg, $cv) = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 5 | AE::log error => $msg; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 5 | ▶ | $cv->cb(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | 5 | _delay_step($obj, [$err], undef, [$msg], $cv); | |||||||||||||||||||||||||||
| 151 | 5 | }); | |||||||||||||||||||||||||||
| 152 | 5 | $cv->end(); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 5 | return; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 7 | ▶ | sub easy_delay { | ||||||||||||||||||||||||||
|
Subroutine
easy_delay: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 7 | my ($obj, $fin); | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 7 | ▶ | if (blessed($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 2 | $obj = shift(); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | 7 | $fin = pop(); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 7 | ▶ | return unless $fin; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 7 | my ($subs, $err); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 7 | ▶ | if (ref($_[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 3 | $subs = shift(); | |||||||||||||||||||||||||||
| 171 | 3 | $err = pop(); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||
| 174 | 4 | $err = pop(); | |||||||||||||||||||||||||||
| 175 | 4 | $subs = \@_; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 7 | my $cv = AE::cv; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 7 | $cv->begin(); | |||||||||||||||||||||||||||
| 181 | 3 | ▶ | $cv->cb(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 182 | 3 | ▶ | $fin->($obj ? $obj : (), $cv->recv()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 7 | }); | |||||||||||||||||||||||||||
| 184 | 7 | _easy_delay_step($obj, $subs, $err, $cv); | |||||||||||||||||||||||||||
| 185 | 7 | $cv->end(); | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 7 | return; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 31 | ▶ | sub _easy_delay_step { | ||||||||||||||||||||||||||
|
Subroutine
_easy_delay_step: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 191 | 31 | my ($cv) = pop(); | |||||||||||||||||||||||||||
| 192 | 31 | my ($obj, $subs, $err, $args) = @_; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 31 | my $sub = shift(@$subs); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 31 | ▶ | unless (defined($args)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 7 | $args = []; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 31 | ▶ | unless ($sub) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 3 | $cv->send(@$args); | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 3 | return; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 28 | $cv->begin(); | |||||||||||||||||||||||||||
| 206 | 28 | ▶ | AE::postpone { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 207 | 28 | my @res; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 28 | ▶ | if ($err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 18 | eval { | |||||||||||||||||||||||||||
| 211 | 18 | ▶ | @res = $sub->($obj ? $obj : (), @$args); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | }; | ||||||||||||||||||||||||||||
| 213 | 18 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 4 | my $msg = $@; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 4 | AE::log error => $msg; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 4 | ▶ | $cv->cb(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 219 | 4 | ▶ | $err->($obj ? $obj : (), $msg); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 4 | }); | |||||||||||||||||||||||||||
| 221 | 4 | $cv->send(@$args); | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||
| 224 | 14 | _easy_delay_step($obj, $subs, $err, \@res, $cv); | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||
| 228 | 10 | ▶ | @res = $sub->($obj ? $obj : (), @$args); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 10 | _easy_delay_step($obj, $subs, $err, \@res, $cv); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | 28 | $cv->end(); | |||||||||||||||||||||||||||
| 232 | 28 | }; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 28 | return; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 8 | 1; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | __END__ | ||||||||||||||||||||||||||||