| 1 |
|
| MODULE = DBIx::Loop PACKAGE = DBIx::Loop::Future |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| SV * |
| 6 |
|
| new(class) |
| 7 |
|
| SV *class |
| 8 |
|
| CODE: |
| 9 |
16 |
| RETVAL = dbil_future_new(aTHX_ |
| 10 |
32 |
▶ | SvROK(class) ? sv_reftype(SvRV(class), 1) : SvPV_nolen(class)); |
Branch: 1 branch
| Branch | True | False | Total |
| SvROK(class) ? sv_reftype(SvRV(class), 1) : SvPV_nolen(class)); |
0 |
16 |
16 |
|
| 11 |
|
| OUTPUT: |
| 12 |
|
| RETVAL |
| 13 |
|
| |
| 14 |
|
| SV * |
| 15 |
|
| done(self, ...) |
| 16 |
|
| SV *self |
| 17 |
|
| CODE: |
| 18 |
|
| { |
| 19 |
12 |
| dbil_future *f = dbil_future_of(aTHX_ self); |
| 20 |
12 |
| AV *res = newAV(); |
| 21 |
|
| int i; |
| 22 |
12 |
▶ | if (f->state) |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->state) |
1 |
11 |
12 |
|
| 23 |
1 |
| croak("DBIx::Loop::Future: already settled"); |
| 24 |
25 |
▶ | for (i = 1; i < items; i++) av_push(res, newSVsv(ST(i))); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i++) av_push(res, newSVsv(ST(i))); |
14 |
11 |
25 |
|
| 25 |
11 |
| f->result = newRV_noinc((SV *)res); |
| 26 |
11 |
| f->state = 1; |
| 27 |
11 |
| dbil_future_fire(aTHX_ self, f); |
| 28 |
11 |
| RETVAL = SvREFCNT_inc(self); |
| 29 |
|
| } |
| 30 |
|
| OUTPUT: |
| 31 |
|
| RETVAL |
| 32 |
|
| |
| 33 |
|
| SV * |
| 34 |
|
| fail(self, error) |
| 35 |
|
| SV *self |
| 36 |
|
| SV *error |
| 37 |
|
| CODE: |
| 38 |
|
| { |
| 39 |
4 |
| dbil_future *f = dbil_future_of(aTHX_ self); |
| 40 |
4 |
▶ | if (f->state) |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->state) |
0 |
4 |
4 |
|
| 41 |
0 |
| croak("DBIx::Loop::Future: already settled"); |
| 42 |
4 |
| f->error = newSVsv(error); |
| 43 |
4 |
| f->state = 2; |
| 44 |
4 |
| dbil_future_fire(aTHX_ self, f); |
| 45 |
4 |
| RETVAL = SvREFCNT_inc(self); |
| 46 |
|
| } |
| 47 |
|
| OUTPUT: |
| 48 |
|
| RETVAL |
| 49 |
|
| |
| 50 |
|
| SV * |
| 51 |
|
| on_ready(self, cb) |
| 52 |
|
| SV *self |
| 53 |
|
| SV *cb |
| 54 |
|
| CODE: |
| 55 |
|
| { |
| 56 |
8 |
| dbil_future *f = dbil_future_of(aTHX_ self); |
| 57 |
8 |
▶ | if (!SvROK(cb) || SvTYPE(SvRV(cb)) != SVt_PVCV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(cb) || SvTYPE(SvRV(cb)) != SVt_PVCV) |
8 |
0 |
8 |
| if (!SvROK(cb) || SvTYPE(SvRV(cb)) != SVt_PVCV) |
0 |
8 |
8 |
|
| 58 |
0 |
| croak("DBIx::Loop::Future->on_ready: need a coderef"); |
| 59 |
8 |
▶ | if (f->state) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->state) { |
1 |
7 |
8 |
|
| 60 |
1 |
| dSP; |
| 61 |
1 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
1 |
1 |
|
| 62 |
1 |
▶ | EXTEND(SP, 1); PUSHs(self); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); PUSHs(self); PUTBACK; |
0 |
1 |
1 |
|
| 63 |
1 |
| call_sv(cb, G_DISCARD | G_EVAL); |
| 64 |
1 |
▶ | if (SvTRUE(ERRSV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) |
1 |
0 |
1 |
| if (SvTRUE(ERRSV)) |
0 |
1 |
1 |
|
| 65 |
0 |
▶ | warn("DBIx::Loop::Future: on_ready callback died: %s", |
Branch: 1 branch
| Branch | True | False | Total |
| warn("DBIx::Loop::Future: on_ready callback died: %s", |
0 |
0 |
0 |
|
| 66 |
|
| SvPV_nolen(ERRSV)); |
| 67 |
1 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
0 |
1 |
1 |
|
| 68 |
|
| } else { |
| 69 |
7 |
| av_push(f->cbs, newSVsv(cb)); |
| 70 |
|
| } |
| 71 |
8 |
| RETVAL = SvREFCNT_inc(self); |
| 72 |
|
| } |
| 73 |
|
| OUTPUT: |
| 74 |
|
| RETVAL |
| 75 |
|
| |
| 76 |
|
| # then($on_done [, $on_fail]) / else($on_fail) -> a new future. |
| 77 |
|
| # |
| 78 |
|
| # The continuation is an AV on the callback queue, not a closure, so a chain |
| 79 |
|
| # costs one array per link and settling it runs no Perl frame but the user's |
| 80 |
|
| # own callbacks. `else` is the same thing with only the failure half, which is |
| 81 |
|
| # why it is an ALIAS rather than a second body. |
| 82 |
|
| SV * |
| 83 |
|
| then(self, on_done = &PL_sv_undef, on_fail = &PL_sv_undef) |
| 84 |
|
| SV *self |
| 85 |
|
| SV *on_done |
| 86 |
|
| SV *on_fail |
| 87 |
|
| ALIAS: |
| 88 |
|
| else = 1 |
| 89 |
|
| CODE: |
| 90 |
|
| { |
| 91 |
|
| SV *next; |
| 92 |
|
| /* else($cb): the one argument is the failure handler */ |
| 93 |
2015 |
▶ | if (ix == 1) { on_fail = on_done; on_done = &PL_sv_undef; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) { on_fail = on_done; on_done = &PL_sv_undef; } |
1 |
2014 |
2015 |
|
| 94 |
2015 |
| (void)dbil_future_of(aTHX_ self); /* croak early if not one */ |
| 95 |
2015 |
| next = dbil_future_new(aTHX_ "DBIx::Loop::Future"); |
| 96 |
2015 |
| dbil_then_attach(aTHX_ self, next, on_done, on_fail); |
| 97 |
2015 |
| RETVAL = next; |
| 98 |
|
| } |
| 99 |
|
| OUTPUT: |
| 100 |
|
| RETVAL |
| 101 |
|
| |
| 102 |
|
| int |
| 103 |
|
| is_ready(self) |
| 104 |
|
| SV *self |
| 105 |
|
| CODE: |
| 106 |
1445 |
▶ | RETVAL = dbil_future_of(aTHX_ self)->state != 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = dbil_future_of(aTHX_ self)->state != 0; |
1420 |
25 |
1445 |
|
| 107 |
|
| OUTPUT: |
| 108 |
|
| RETVAL |
| 109 |
|
| |
| 110 |
|
| int |
| 111 |
|
| is_done(self) |
| 112 |
|
| SV *self |
| 113 |
|
| CODE: |
| 114 |
60 |
▶ | RETVAL = dbil_future_of(aTHX_ self)->state == 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = dbil_future_of(aTHX_ self)->state == 1; |
31 |
29 |
60 |
|
| 115 |
|
| OUTPUT: |
| 116 |
|
| RETVAL |
| 117 |
|
| |
| 118 |
|
| int |
| 119 |
|
| is_failed(self) |
| 120 |
|
| SV *self |
| 121 |
|
| CODE: |
| 122 |
525 |
▶ | RETVAL = dbil_future_of(aTHX_ self)->state == 2; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = dbil_future_of(aTHX_ self)->state == 2; |
501 |
24 |
525 |
|
| 123 |
|
| OUTPUT: |
| 124 |
|
| RETVAL |
| 125 |
|
| |
| 126 |
|
| SV * |
| 127 |
|
| failure(self) |
| 128 |
|
| SV *self |
| 129 |
|
| CODE: |
| 130 |
|
| { |
| 131 |
19 |
| dbil_future *f = dbil_future_of(aTHX_ self); |
| 132 |
19 |
▶ | RETVAL = (f->state == 2 && f->error) ? newSVsv(f->error) : newSV(0); |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = (f->state == 2 && f->error) ? newSVsv(f->error) : newSV(0); |
19 |
0 |
19 |
| RETVAL = (f->state == 2 && f->error) ? newSVsv(f->error) : newSV(0); |
19 |
0 |
19 |
|
| 133 |
|
| } |
| 134 |
|
| OUTPUT: |
| 135 |
|
| RETVAL |
| 136 |
|
| |
| 137 |
|
| void |
| 138 |
|
| get(self) |
| 139 |
|
| SV *self |
| 140 |
|
| PPCODE: |
| 141 |
|
| { |
| 142 |
167 |
| dbil_future *f = dbil_future_of(aTHX_ self); |
| 143 |
167 |
▶ | if (f->state == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->state == 0) |
1 |
166 |
167 |
|
| 144 |
1 |
| croak("DBIx::Loop::Future->get: future is not ready " |
| 145 |
|
| "(await it on your event loop first)"); |
| 146 |
166 |
▶ | if (f->state == 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (f->state == 2) |
3 |
163 |
166 |
|
| 147 |
3 |
▶ | croak_sv(f->error ? f->error : sv_2mortal(newSVpvs("failed"))); |
Branch: 1 branch
| Branch | True | False | Total |
| croak_sv(f->error ? f->error : sv_2mortal(newSVpvs("failed"))); |
3 |
0 |
3 |
|
| 148 |
|
| { |
| 149 |
163 |
| AV *res = (AV *)SvRV(f->result); |
| 150 |
163 |
| SSize_t i, n = av_len(res) + 1; |
| 151 |
163 |
▶ | EXTEND(SP, n); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, n); |
163 |
0 |
163 |
| EXTEND(SP, n); |
0 |
163 |
163 |
|
| 152 |
330 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
167 |
163 |
330 |
|
| 153 |
167 |
| SV **e = av_fetch(res, i, 0); |
| 154 |
167 |
▶ | PUSHs(e && *e ? sv_2mortal(newSVsv(*e)) : &PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(e && *e ? sv_2mortal(newSVsv(*e)) : &PL_sv_undef); |
167 |
0 |
167 |
| PUSHs(e && *e ? sv_2mortal(newSVsv(*e)) : &PL_sv_undef); |
167 |
0 |
167 |
|
| 155 |
|
| } |
| 156 |
|
| } |
| 157 |
|
| } |