xs/future.xs

filter: Statementstmt 87.3% 124 / 142 Branchbran 49.4% 88 / 178 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 66.2% 212 / 320 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/hyperman/hm_http3.h ↑ Summary include/hyperman/hm_quic.h »
1 MODULE = Hyperman PACKAGE = Hyperman::Future
2  
3 # Native array-slot Future, fully XS: creation, resolution,
4 # callbacks, chaining, combinators, and CPAN Future interop. Continuations
5 # are C closures (hm_future.h) trampolined through the fire queue.
6 #
7 # The AWAIT_* aliases are the Future::AsyncAwait::Awaitable protocol, which
8 # is how `await $f` reaches a future of this class inside an async sub. They
9 # are aliases rather than wrappers so the protocol costs nothing beyond the
10 # XSUB it already resolves to.
11  
12 SV *
13 new(class)
14 SV *class
15 CODE:
16 {
17 const char *name;
18 87 ▶ if (SvROK(class) && SvOBJECT(SvRV(class))) /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(class) && SvOBJECT(SvRV(class))) /* # uncoverable condition right count:2 class:ignore_covered_err */ 1 86 87
if (SvROK(class) && SvOBJECT(SvRV(class))) /* # uncoverable condition right count:2 class:ignore_covered_err */ 1 0 1
19 1 ▶ name = HvNAME(SvSTASH(SvRV(class)));
Branch: 6 branches
BranchTrueFalseTotal
name = HvNAME(SvSTASH(SvRV(class))); 1 0 1
name = HvNAME(SvSTASH(SvRV(class))); 1 0 1
name = HvNAME(SvSTASH(SvRV(class))); 0 1 1
name = HvNAME(SvSTASH(SvRV(class))); 0 0 0
name = HvNAME(SvSTASH(SvRV(class))); 1 0 1
name = HvNAME(SvSTASH(SvRV(class))); 0 1 1
20 else
21 86 name = SvPV_nolen(class);
22 87 RETVAL = hmf_new(aTHX_ name);
23 }
24 OUTPUT:
25 RETVAL
26  
27 SV *
28 done(self, ...)
29 SV *self
30 ALIAS:
31 AWAIT_DONE = 1
32 CODE:
33 PERL_UNUSED_VAR(ix);
34 48 ▶ if (hmf_state(aTHX_ self) == HMF_PENDING)
Branch: 1 branch
BranchTrueFalseTotal
if (hmf_state(aTHX_ self) == HMF_PENDING) 43 3 46
35 43 hmf_settle(aTHX_ self, HMF_DONE, &ST(1), items - 1);
36 46 RETVAL = SvREFCNT_inc(self);
37 OUTPUT:
38 RETVAL
39  
40 SV *
41 fail(self, ...)
42 SV *self
43 ALIAS:
44 AWAIT_FAIL = 1
45 CODE:
46 PERL_UNUSED_VAR(ix);
47 14 ▶ # uncoverable branch false class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch false class:ignore_covered_err 14 0 14
48 14 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 13 1 14
49 13 if (hmf_state(aTHX_ self) == HMF_PENDING) {
50 if (items > 1) {
51 1 hmf_settle(aTHX_ self, HMF_FAILED, &ST(1), items - 1);
52 1 } else {
53 SV *def = sv_2mortal(newSVpvs("Failed\n"));
54 hmf_settle(aTHX_ self, HMF_FAILED, &def, 1);
55 14 }
56 }
57 RETVAL = SvREFCNT_inc(self);
58 OUTPUT:
59 RETVAL
60  
61 SV *
62 done_future(class, ...)
63 SV *class
64 ALIAS:
65 AWAIT_NEW_DONE = 1
66 CODE:
67 {
68 0 ▶ const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */
Branch: 5 branches
BranchTrueFalseTotal
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
69 20 ▶ : SvPV_nolen(class);
Branch: 3 branches
BranchTrueFalseTotal
: SvPV_nolen(class); 0 10 10
: SvPV_nolen(class); 0 0 0
: SvPV_nolen(class); 0 0 0
70 PERL_UNUSED_VAR(ix);
71 10 RETVAL = hmf_new(aTHX_ name);
72 10 hmf_settle(aTHX_ RETVAL, HMF_DONE, &ST(1), items - 1);
73 }
74 OUTPUT:
75 RETVAL
76  
77 SV *
78 fail_future(class, ...)
79 SV *class
80 ALIAS:
81 AWAIT_NEW_FAIL = 1
82 CODE:
83 {
84 0 ▶ const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */
Branch: 5 branches
BranchTrueFalseTotal
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
85 8 ▶ : SvPV_nolen(class);
Branch: 3 branches
BranchTrueFalseTotal
: SvPV_nolen(class); 0 4 4
: SvPV_nolen(class); 0 0 0
: SvPV_nolen(class); 0 0 0
86 PERL_UNUSED_VAR(ix);
87 4 RETVAL = hmf_new(aTHX_ name);
88 4 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 2 2 4
89 2 hmf_settle(aTHX_ RETVAL, HMF_FAILED, &ST(1), items - 1);
90 } else {
91 2 SV *def = sv_2mortal(newSVpvs("Failed\n"));
92 2 hmf_settle(aTHX_ RETVAL, HMF_FAILED, &def, 1);
93 }
94 }
95 OUTPUT:
96 RETVAL
97  
98 SV *
99 cancel(self)
100 SV *self
101 CODE:
102 24 hmf_cancel(aTHX_ self);
103 24 RETVAL = SvREFCNT_inc(self);
104 OUTPUT:
105 RETVAL
106  
107 int
108 is_ready(self)
109 SV *self
110 ALIAS:
111 AWAIT_IS_READY = 1
112 CODE:
113 PERL_UNUSED_VAR(ix);
114 23 ▶ RETVAL = hmf_state(aTHX_ self) != HMF_PENDING;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = hmf_state(aTHX_ self) != HMF_PENDING; 1 22 23
115 OUTPUT:
116 RETVAL
117  
118 int
119 is_done(self)
120 SV *self
121 CODE:
122 10 ▶ RETVAL = hmf_state(aTHX_ self) == HMF_DONE;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = hmf_state(aTHX_ self) == HMF_DONE; 0 10 10
123 OUTPUT:
124 RETVAL
125  
126 int
127 is_failed(self)
128 SV *self
129 CODE:
130 13 ▶ RETVAL = hmf_state(aTHX_ self) == HMF_FAILED;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = hmf_state(aTHX_ self) == HMF_FAILED; 0 13 13
131 OUTPUT:
132 RETVAL
133  
134 int
135 is_cancelled(self)
136 SV *self
137 ALIAS:
138 AWAIT_IS_CANCELLED = 1
139 CODE:
140 PERL_UNUSED_VAR(ix);
141 28 ▶ RETVAL = hmf_state(aTHX_ self) == HMF_CANCELLED;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = hmf_state(aTHX_ self) == HMF_CANCELLED; 0 28 28
142 OUTPUT:
143 RETVAL
144  
145 # A new pending future of the same class. The instance is not modified, and
146 # no per-instance state is copied.
147 SV *
148 AWAIT_CLONE(self)
149 SV *self
150 CODE:
151 1 RETVAL = hmf_new(aTHX_ hmf_class_of(aTHX_ self));
152 OUTPUT:
153 RETVAL
154  
155 SV *
156 on_ready(self, cb)
157 SV *self
158 SV *cb
159 ALIAS:
160 AWAIT_ON_READY = 1
161 CODE:
162 PERL_UNUSED_VAR(ix);
163 9 hmf_on_ready(aTHX_ self, cb);
164 7 RETVAL = SvREFCNT_inc(self);
165 OUTPUT:
166 RETVAL
167  
168 # Run $thing when this future is cancelled: a code reference is called with
169 # the future, anything else is cancelled. Registering on a future that has
170 # already been cancelled runs it at once; on one that completed normally it
171 # is dropped, since that future will never cancel.
172 SV *
173 on_cancel(self, thing)
174 SV *self
175 SV *thing
176 ALIAS:
177 AWAIT_ON_CANCEL = 1
178 AWAIT_CHAIN_CANCEL = 2
179 CODE:
180 {
181 9 IV st = hmf_state(aTHX_ self);
182 PERL_UNUSED_VAR(ix);
183 9 ▶ if (st == HMF_CANCELLED) {
Branch: 1 branch
BranchTrueFalseTotal
if (st == HMF_CANCELLED) { 1 8 9
184 1 hmf_cancel_target(aTHX_ thing, self);
185 8 ▶ } else if (st == HMF_PENDING) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (st == HMF_PENDING) { 7 1 8
186 7 SV *cb = hm_closure(aTHX_ hm_xs_oncancel_cb, NULL, thing,
187 NULL, NULL, 0, 0);
188 7 hmf_on_ready(aTHX_ self, cb);
189 7 SvREFCNT_dec(cb);
190 }
191 9 RETVAL = SvREFCNT_inc(self);
192 }
193 OUTPUT:
194 RETVAL
195  
196 SV *
197 on_done(self, usercb)
198 SV *self
199 SV *usercb
200 ALIAS:
201 on_fail = 1
202 CODE:
203 {
204 2002 ▶ SV *cb = hm_closure(aTHX_ hm_xs_ondone_cb, NULL, usercb, NULL, NULL,
Branch: 1 branch
BranchTrueFalseTotal
SV *cb = hm_closure(aTHX_ hm_xs_ondone_cb, NULL, usercb, NULL, NULL, 2001 1 2002
205 ix == 0 ? HMF_DONE : HMF_FAILED, 0);
206 2002 hmf_on_ready(aTHX_ self, cb);
207 2002 SvREFCNT_dec(cb);
208 2002 RETVAL = SvREFCNT_inc(self);
209 }
210 OUTPUT:
211 RETVAL
212  
213 SV *
214 await(self)
215 SV *self
216 CODE:
217 1 hmf_await(aTHX_ self);
218 1 RETVAL = SvREFCNT_inc(self);
219 OUTPUT:
220 RETVAL
221  
222 void
223 get(self)
224 SV *self
225 ALIAS:
226 result = 1
227 AWAIT_WAIT = 2
228 AWAIT_GET = 3
229 PPCODE:
230 {
231 IV st;
232 /* AWAIT_GET is defined only on a future that is already ready, so it
233 * reads the result where every other spelling waits for one.
234 * AWAIT_WAIT is the spelling that does wait - it is what a toplevel
235 * await resolves to. */
236 46 ▶ if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 3) { 7 39 46
237 7 st = hmf_state(aTHX_ self);
238 7 ▶ if (st == HMF_PENDING) croak("Hyperman::Future is not ready");
Branch: 1 branch
BranchTrueFalseTotal
if (st == HMF_PENDING) croak("Hyperman::Future is not ready"); 1 6 7
239 } else {
240 /* The wait pumps the loop, which runs other handlers: the Perl
241 * stack can be reallocated under this frame, so the pointer this
242 * PPCODE pushes results through is re-read afterwards. */
243 39 PUTBACK;
244 39 hmf_await(aTHX_ self);
245 30 SPAGAIN;
246 30 st = hmf_state(aTHX_ self);
247 }
248 36 ▶ if (st == HMF_FAILED) {
Branch: 1 branch
BranchTrueFalseTotal
if (st == HMF_FAILED) { 7 29 36
249 7 AV *fav = hmf_values_av(aTHX_ self);
250 7 ▶ SV **e = fav ? av_fetch(fav, 0, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SV **e = fav ? av_fetch(fav, 0, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 7 0 7
251 7 ▶ # uncoverable branch false
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch false 7 0 7
252 0 # uncoverable condition right count:1 class:ignore_covered_err
253 if (e) croak_sv(sv_mortalcopy(*e));
254 29 ▶ croak("Failed"); /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
croak("Failed"); /* # uncoverable statement */ 1 28 29
255 1 }
256 if (st == HMF_CANCELLED)
257 28 croak("Hyperman::Future was cancelled");
258 28 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
{ 28 0 28
259 28 ▶ AV *rav = hmf_values_av(aTHX_ self);
Branch: 1 branch
BranchTrueFalseTotal
AV *rav = hmf_values_av(aTHX_ self); 7 21 28
260 SSize_t n = rav ? av_len(rav) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
261 7 ▶ if (GIMME_V == G_ARRAY) {
Branch: 2 branches
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 7 0 7
if (GIMME_V == G_ARRAY) { 0 7 7
262 24 ▶ SSize_t i;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i; 17 7 24
263 17 EXTEND(SP, n);
264 17 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 17 0 17
265 SV **e = av_fetch(rav, i, 0);
266 21 ▶ PUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef); /* # uncoverable condition right count:1 class:ignore_covered_err */ 14 7 21
267 14 }
268 14 ▶ } else if (n) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (n) { 0 14 14
} else if (n) { 14 0 14
269 SV **e = av_fetch(rav, 0, 0);
270 7 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 0 7 7
271 # uncoverable condition right count:2 class:ignore_covered_err
272 XPUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef);
273 } else {
274 XPUSHs(&PL_sv_undef);
275 }
276 }
277 }
278  
279 void
280 failure(self)
281 SV *self
282 PPCODE:
283 {
284 8 PUTBACK;
285 8 hmf_await(aTHX_ self);
286 8 SPAGAIN;
287 8 ▶ # uncoverable branch true class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch true class:ignore_covered_err 0 8 8
288 # uncoverable condition left count:1 class:ignore_covered_err
289 8 if (hmf_state(aTHX_ self) != HMF_FAILED) XSRETURN_EMPTY;
290 8 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
{ 8 0 8
291 8 ▶ AV *fav = hmf_values_av(aTHX_ self);
Branch: 1 branch
BranchTrueFalseTotal
AV *fav = hmf_values_av(aTHX_ self); 1 7 8
292 SSize_t n = fav ? av_len(fav) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
293 1 ▶ if (GIMME_V == G_ARRAY) {
Branch: 2 branches
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 1 0 1
if (GIMME_V == G_ARRAY) { 0 1 1
294 5 ▶ SSize_t i;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i; 4 1 5
295 4 EXTEND(SP, n);
296 4 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 4 0 4
297 SV **e = av_fetch(fav, i, 0);
298 7 ▶ PUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef); /* # uncoverable condition right count:1 class:ignore_covered_err */ 7 0 7
299 7 }
300 7 ▶ # uncoverable branch false class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable branch false class:ignore_covered_err 0 7 7
# uncoverable branch false class:ignore_covered_err 7 0 7
301 # uncoverable condition right count:1 class:ignore_covered_err
302 } else if (n) {
303 SV **e = av_fetch(fav, 0, 0);
304 # uncoverable condition left count:1 class:ignore_covered_err
305 # uncoverable condition right count:2 class:ignore_covered_err
306 XPUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef);
307 }
308 }
309 }
310  
311 # result/failure values as a plain list, no dying, no awaiting.
312 void
313 _values(self)
314 SV *self
315 PPCODE:
316 {
317 17 AV *rav = hmf_values_av(aTHX_ self);
318 17 ▶ SSize_t i, n = rav ? av_len(rav) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i, n = rav ? av_len(rav) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ 17 0 17
319 17 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 17 0 17
EXTEND(SP, n); 0 17 17
320 38 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 21 17 38
321 21 SV **e = av_fetch(rav, i, 0);
322 21 ▶ PUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(e ? sv_mortalcopy(*e) : &PL_sv_undef); /* # uncoverable condition right count:1 class:ignore_covered_err */ 21 0 21
323 }
324 }
325  
326 # ---- chaining ----
327  
328 SV *
329 then(self, ...)
330 SV *self
331 ALIAS:
332 else = 1
333 CODE:
334 {
335 50023 SV *on_done = NULL, *on_fail = NULL;
336 SV *cb;
337 50023 ▶ if (ix == 0) { /* then($ok?, $err?) */
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 0) { /* then($ok?, $err?) */ 50022 1 50023
338 50022 ▶ if (items > 1 && SvOK(ST(1))) on_done = ST(1); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (items > 1 && SvOK(ST(1))) on_done = ST(1); /* # uncoverable condition right count:1 class:ignore_covered_err */ 50022 0 50022
if (items > 1 && SvOK(ST(1))) on_done = ST(1); /* # uncoverable condition right count:1 class:ignore_covered_err */ 50021 1 50022
339 50022 ▶ if (items > 2 && SvOK(ST(2))) on_fail = ST(2); /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (items > 2 && SvOK(ST(2))) on_fail = ST(2); /* # uncoverable condition right count:2 class:ignore_covered_err */ 1 50021 50022
if (items > 2 && SvOK(ST(2))) on_fail = ST(2); /* # uncoverable condition right count:2 class:ignore_covered_err */ 1 0 1
340 } else { /* else($err) */
341 1 ▶ # uncoverable branch false class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable branch false class:ignore_covered_err 1 0 1
# uncoverable branch false class:ignore_covered_err 1 0 1
342 # uncoverable condition right count:1 class:ignore_covered_err
343 50023 # uncoverable condition right count:2 class:ignore_covered_err
344 50023 if (items > 1 && SvOK(ST(1))) on_fail = ST(1);
345 50023 }
346 50023 RETVAL = hmf_new(aTHX_ hmf_class_of(aTHX_ self));
347 50023 hmf_set_upstream(aTHX_ RETVAL, self);
348 cb = hm_closure(aTHX_ hm_xs_then_cb, RETVAL, on_done, on_fail, NULL, 0, 0);
349 hmf_on_ready(aTHX_ self, cb);
350 SvREFCNT_dec(cb);
351 }
352 OUTPUT:
353 RETVAL
354  
355 SV *
356 followed_by(self, usercb)
357 SV *self
358 SV *usercb
359 CODE:
360 {
361 SV *cb;
362 9 RETVAL = hmf_new(aTHX_ hmf_class_of(aTHX_ self));
363 9 hmf_set_upstream(aTHX_ RETVAL, self);
364 9 cb = hm_closure(aTHX_ hm_xs_then_cb, RETVAL, usercb, NULL, NULL, 1, 0);
365 9 hmf_on_ready(aTHX_ self, cb);
366 9 SvREFCNT_dec(cb);
367 }
368 OUTPUT:
369 RETVAL
370  
371 SV *
372 transform(self, ...)
373 SV *self
374 CODE:
375 {
376 9 SV *xd = NULL, *xf = NULL;
377 SV *cb;
378 int i;
379 9 ▶ if ((items - 1) % 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 1) % 2) 1 8 9
380 1 croak("transform: odd number of arguments");
381 14 ▶ for (i = 1; i + 1 < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i + 1 < items; i += 2) { 7 7 14
382 7 const char *key = SvPV_nolen(ST(i));
383 7 ▶ if (strEQ(key, "done")) xd = ST(i + 1);
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "done")) xd = ST(i + 1); 4 3 7
384 3 ▶ else if (strEQ(key, "fail")) xf = ST(i + 1);
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "fail")) xf = ST(i + 1); 2 1 3
385 1 else croak("transform: unknown argument '%s'", key);
386 }
387 7 RETVAL = hmf_new(aTHX_ hmf_class_of(aTHX_ self));
388 7 hmf_set_upstream(aTHX_ RETVAL, self);
389 7 cb = hm_closure(aTHX_ hm_xs_transform_cb, RETVAL, xd, xf, NULL, 0, 0);
390 7 hmf_on_ready(aTHX_ self, cb);
391 7 SvREFCNT_dec(cb);
392 }
393 OUTPUT:
394 RETVAL
395  
396 # Weakly link $derived to its $upstream for cancel propagation.
397 void
398 _set_upstream(derived, upstream)
399 SV *derived
400 SV *upstream
401 CODE:
402 1 hmf_set_upstream(aTHX_ derived, upstream);
403  
404 # ---- convergent combinators ----
405  
406 SV *
407 wait_all(class, ...)
408 SV *class
409 ALIAS:
410 wait_any = 1
411 needs_all = 2
412 needs_any = 3
413 CODE:
414 {
415 static const IV modes[4] = { HM_COMB_WAIT_ALL, HM_COMB_WAIT_ANY,
416 HM_COMB_NEEDS_ALL, HM_COMB_NEEDS_ANY };
417 17 RETVAL = hmf_combine(aTHX_ class, &ST(1), items - 1, modes[ix]);
418 }
419 OUTPUT:
420 RETVAL
421  
422 # ---- CPAN Future interop ----
423  
424 SV *
425 as_cpan_future(self)
426 SV *self
427 CODE:
428 {
429 SV *cf, *cb;
430 0 dSP;
431 int n;
432 0 load_module(PERL_LOADMOD_NOIMPORT, newSVpvs("Future"), NULL);
433 0 ENTER; SAVETMPS;
434 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
435 0 ▶ XPUSHs(sv_2mortal(newSVpvs("Future")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("Future"))); 0 0 0
436 0 PUTBACK;
437 0 n = call_method("new", G_SCALAR);
438 0 SPAGAIN;
439 0 ▶ cf = n ? SvREFCNT_inc(POPs) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
cf = n ? SvREFCNT_inc(POPs) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ 0 0 0
440 0 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 0 0 0
441 0 cb = hm_closure(aTHX_ hm_xs_tocpan_cb, cf, NULL, NULL, NULL, 0, 0);
442 0 hmf_on_ready(aTHX_ self, cb);
443 0 SvREFCNT_dec(cb);
444 0 RETVAL = cf;
445 }
446 OUTPUT:
447 RETVAL
448  
449 SV *
450 from_future(class, other)
451 SV *class
452 SV *other
453 CODE:
454 {
455 0 ▶ const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */
Branch: 5 branches
BranchTrueFalseTotal
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
const char *name = (SvROK(class) && SvOBJECT(SvRV(class))) ? HvNAME(SvSTASH(SvRV(class))) /* # uncoverable statement class:ignore_covered_err */ 0 0 0
456 6 ▶ : SvPV_nolen(class);
Branch: 3 branches
BranchTrueFalseTotal
: SvPV_nolen(class); 0 3 3
: SvPV_nolen(class); 0 0 0
: SvPV_nolen(class); 0 0 0
457 SV *cb;
458 3 RETVAL = hmf_new(aTHX_ name);
459 3 cb = hm_closure(aTHX_ hm_xs_fromcpan_cb, RETVAL, NULL, NULL, NULL, 0, 0);
460 3 hm_any_on_ready(aTHX_ other, cb);
461 3 SvREFCNT_dec(cb);
462 }
463 OUTPUT:
464 RETVAL
« include/hyperman/hm_http3.h ↑ Summary include/hyperman/hm_quic.h »