| 1 |
|
| /* punk_compile.h - Punk::App's boot compiler, in C. |
| 2 |
|
| * |
| 3 |
|
| * to_app calls compile(): it resolves and freezes everything the registrar |
| 4 |
|
| * accumulated into the `state` hash punk_serve.h reads, and returns the PSGI |
| 5 |
|
| * app. The app, the docs targets, the boot-time target resolver and the |
| 6 |
|
| * nonblocking Future chain are all real closures - built here with the magic-CV |
| 7 |
|
| * primitive from punk_static.h (punk_closure / punk_clos_cap), so nothing on |
| 8 |
|
| * this path is Perl. lib/Punk/App.pm is documentation only. |
| 9 |
|
| * |
| 10 |
|
| * Must be included after punk_static.h (the closure primitive), punk_serve.h |
| 11 |
|
| * (punk_serve / punk_finish_c / punk_handle_error) and punk_app.h. |
| 12 |
|
| */ |
| 13 |
|
| |
| 14 |
|
| #ifndef PUNK_COMPILE_H |
| 15 |
|
| #define PUNK_COMPILE_H |
| 16 |
|
| |
| 17 |
|
| /* ---- closures ------------------------------------------------------------- */ |
| 18 |
|
| |
| 19 |
|
| /* the PSGI app: capture [ $state ]; body is punk_serve($state, $env). */ |
| 20 |
|
| XS_INTERNAL(pc_app_cb); |
| 21 |
221550 |
| XS_INTERNAL(pc_app_cb) { |
| 22 |
221550 |
| dXSARGS; |
| 23 |
221550 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 24 |
|
| SV **holder; |
| 25 |
|
| pk_state *st; |
| 26 |
|
| /* |
| 27 |
|
| # uncoverable branch true |
| 28 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 29 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 30 |
221550 |
▶ | if (!cap || items < 1) XSRETURN_EMPTY; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cap || items < 1) XSRETURN_EMPTY; |
221550 |
0 |
221550 |
| if (!cap || items < 1) XSRETURN_EMPTY; |
0 |
221550 |
221550 |
|
| 31 |
|
| /* slot 0 is the state hash (kept alive for the struct's borrowed |
| 32 |
|
| * pointers), slot 1 the struct the request path reads */ |
| 33 |
221550 |
| holder = av_fetch(cap, 1, 0); |
| 34 |
|
| /* |
| 35 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 36 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 37 |
221550 |
▶ | st = (holder && *holder) ? pk_state_of(aTHX_ *holder) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| st = (holder && *holder) ? pk_state_of(aTHX_ *holder) : NULL; |
221550 |
0 |
221550 |
| st = (holder && *holder) ? pk_state_of(aTHX_ *holder) : NULL; |
221550 |
0 |
221550 |
|
| 38 |
|
| /* |
| 39 |
|
| # uncoverable branch true |
| 40 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 41 |
221550 |
▶ | if (!st) croak("Punk: the compiled application has no state"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!st) croak("Punk: the compiled application has no state"); |
0 |
221550 |
221550 |
|
| 42 |
|
| /* |
| 43 |
|
| # uncoverable branch true |
| 44 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 45 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 46 |
221550 |
▶ | if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) |
221550 |
0 |
221550 |
| if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) |
0 |
221550 |
221550 |
|
| 47 |
0 |
| croak("Punk: the app takes a PSGI env hashref"); /* # uncoverable statement */ |
| 48 |
|
| { |
| 49 |
221550 |
| HV *env = (HV *)SvRV(ST(0)); |
| 50 |
|
| SV *out; |
| 51 |
|
| /* A preflight is answered here, before routing: OPTIONS on a path with |
| 52 |
|
| * no OPTIONS route would otherwise be the router's 405. */ |
| 53 |
221550 |
| out = pco_preflight(aTHX_ st, env); |
| 54 |
221550 |
▶ | if (!out) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!out) { |
221542 |
8 |
221550 |
|
| 55 |
221542 |
| out = punk_serve(aTHX_ st, env); |
| 56 |
|
| /* and the response is decorated here rather than in an |
| 57 |
|
| * after-dispatch hook, because 404s and 405s never reach one */ |
| 58 |
221540 |
| pco_decorate(aTHX_ st, env, &out); |
| 59 |
|
| } |
| 60 |
|
| /* security headers go on outside the branch, so the preflight 204 |
| 61 |
|
| * carries the policy too */ |
| 62 |
221548 |
| phd_decorate(aTHX_ st, env, &out); |
| 63 |
221548 |
| ST(0) = sv_2mortal(out); |
| 64 |
|
| } |
| 65 |
221548 |
| XSRETURN(1); |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
|
| /* a docs route target: capture [ $response ]; body is $response->() (the |
| 69 |
|
| * matched-route call passes $c, which the thunk ignores). */ |
| 70 |
|
| XS_INTERNAL(pc_docs_cb); |
| 71 |
9 |
| XS_INTERNAL(pc_docs_cb) { |
| 72 |
9 |
| dXSARGS; |
| 73 |
9 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 74 |
9 |
▶ | SV *resp = cap ? *av_fetch(cap, 0, 0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *resp = cap ? *av_fetch(cap, 0, 0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
9 |
0 |
9 |
|
| 75 |
|
| SV *out; |
| 76 |
|
| int count; |
| 77 |
|
| PERL_UNUSED_VAR(items); |
| 78 |
9 |
| ENTER; SAVETMPS; |
| 79 |
9 |
▶ | PUSHMARK(SP); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); PUTBACK; |
0 |
9 |
9 |
|
| 80 |
9 |
| count = call_sv(resp, G_SCALAR); |
| 81 |
9 |
| SPAGAIN; |
| 82 |
9 |
▶ | out = count > 0 ? newSVsv(POPs) : newSV(0); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| out = count > 0 ? newSVsv(POPs) : newSV(0); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
9 |
0 |
9 |
|
| 83 |
9 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
9 |
0 |
9 |
|
| 84 |
9 |
| ST(0) = sv_2mortal(out); |
| 85 |
9 |
| XSRETURN(1); |
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
|
| /* the boot-time resolver handed to the router and api mounts: capture |
| 89 |
|
| * [ $self ]; body is $self->_resolve_target($target, $what). */ |
| 90 |
|
| XS_INTERNAL(pc_resolve_cb); |
| 91 |
61927 |
| XS_INTERNAL(pc_resolve_cb) { |
| 92 |
61927 |
| dXSARGS; |
| 93 |
61927 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 94 |
61927 |
▶ | SV *self = cap ? *av_fetch(cap, 0, 0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *self = cap ? *av_fetch(cap, 0, 0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
61927 |
0 |
61927 |
|
| 95 |
|
| SV *argv[2], *r; |
| 96 |
61927 |
▶ | argv[0] = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| argv[0] = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
61927 |
0 |
61927 |
|
| 97 |
61927 |
▶ | argv[1] = items > 1 ? ST(1) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| argv[1] = items > 1 ? ST(1) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
61927 |
0 |
61927 |
|
| 98 |
61927 |
| r = pcx_call_meth(aTHX_ self, "_resolve_target", argv, 2, 1); |
| 99 |
61913 |
▶ | ST(0) = r ? sv_2mortal(r) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| ST(0) = r ? sv_2mortal(r) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
61913 |
0 |
61913 |
|
| 100 |
61913 |
| XSRETURN(1); |
| 101 |
|
| } |
| 102 |
|
| |
| 103 |
|
| /* ---- target resolution ---------------------------------------------------- */ |
| 104 |
|
| |
| 105 |
|
| /* class->can(method) with inheritance (a ->can without the call) */ |
| 106 |
137 |
| static CV *pc_class_can(pTHX_ const char *class, STRLEN cl, const char *meth) { |
| 107 |
137 |
| HV *stash = gv_stashpvn(class, cl, 0); |
| 108 |
|
| GV *gv; |
| 109 |
137 |
▶ | if (!stash) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stash) return NULL; |
41 |
96 |
137 |
|
| 110 |
96 |
| gv = gv_fetchmethod_autoload(stash, meth, 0); |
| 111 |
96 |
▶ | return gv ? GvCV(gv) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return gv ? GvCV(gv) : NULL; |
90 |
6 |
96 |
|
| 112 |
|
| } |
| 113 |
|
| |
| 114 |
|
| /* $self->_resolve_target($target, $what): a coderef passes through; a |
| 115 |
|
| * 'Controller#method' string resolves (loading the class if need be) to the |
| 116 |
|
| * method coderef. Returns it (+1) or croaks. */ |
| 117 |
62019 |
| static SV *pc_resolve_target(pTHX_ SV *self, SV *target, SV *whatsv) { |
| 118 |
62019 |
| HV *h = app_hv(aTHX_ self); |
| 119 |
124038 |
▶ | const char *what = SvOK(whatsv) ? SvPV_nolen(whatsv) : K_TARGET; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| const char *what = SvOK(whatsv) ? SvPV_nolen(whatsv) : K_TARGET; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
62019 |
0 |
62019 |
|
| 120 |
|
| const char *ts, *method; |
| 121 |
|
| STRLEN tl, metl, i, cll; |
| 122 |
62019 |
| const char *hash = NULL; |
| 123 |
|
| SV *classsv, *caller, *ns; |
| 124 |
|
| STRLEN cl2; const char *classname; |
| 125 |
|
| CV *cvp; |
| 126 |
|
| |
| 127 |
62019 |
▶ | if (SvROK(target) && SvTYPE(SvRV(target)) == SVt_PVCV) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(target) && SvTYPE(SvRV(target)) == SVt_PVCV) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
61963 |
56 |
62019 |
| if (SvROK(target) && SvTYPE(SvRV(target)) == SVt_PVCV) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
61963 |
0 |
61963 |
|
| 128 |
61963 |
| return newSVsv(target); |
| 129 |
56 |
▶ | if (!SvOK(target)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(target)) |
1 |
55 |
56 |
|
| 130 |
1 |
| croak("Punk: %s must be a coderef or 'Controller#method', got undef", |
| 131 |
|
| what); |
| 132 |
55 |
| ts = SvPV_const(target, tl); |
| 133 |
358 |
▶ | for (i = tl; i > 0; i--) if (ts[i - 1] == '#') { hash = ts + i - 1; break; } |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = tl; i > 0; i--) if (ts[i - 1] == '#') { hash = ts + i - 1; break; } |
54 |
303 |
357 |
| for (i = tl; i > 0; i--) if (ts[i - 1] == '#') { hash = ts + i - 1; break; } |
357 |
1 |
358 |
|
| 134 |
55 |
▶ | method = hash ? hash + 1 : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| method = hash ? hash + 1 : NULL; |
54 |
1 |
55 |
|
| 135 |
55 |
▶ | metl = hash ? (STRLEN)(ts + tl - method) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| metl = hash ? (STRLEN)(ts + tl - method) : 0; |
54 |
1 |
55 |
|
| 136 |
55 |
▶ | if (hash && metl) |
Branch: 2 branches
| Branch | True | False | Total |
| if (hash && metl) |
54 |
1 |
55 |
| if (hash && metl) |
53 |
1 |
54 |
|
| 137 |
343 |
▶ | for (i = 0; i < metl; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < metl; i++) |
291 |
52 |
343 |
|
| 138 |
291 |
▶ | if (!isWORDCHAR(method[i])) { hash = NULL; break; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!isWORDCHAR(method[i])) { hash = NULL; break; } |
1 |
290 |
291 |
|
| 139 |
55 |
▶ | if (!hash || !metl) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!hash || !metl) |
53 |
2 |
55 |
| if (!hash || !metl) |
1 |
52 |
53 |
|
| 140 |
3 |
| croak("Punk: %s must be a coderef or 'Controller#method', got '%s'", |
| 141 |
|
| what, ts); |
| 142 |
|
| |
| 143 |
52 |
| cll = (STRLEN)(hash - ts); |
| 144 |
52 |
| classsv = newSVpvn(ts, cll); |
| 145 |
52 |
| sv_2mortal(classsv); |
| 146 |
52 |
| caller = app_get(aTHX_ h, K_CALLER); |
| 147 |
104 |
▶ | ns = sv_2mortal(newSVpvf("%s" PK_NS_CONTROLLER, caller ? SvPV_nolen(caller) : "")); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| ns = sv_2mortal(newSVpvf("%s" PK_NS_CONTROLLER, caller ? SvPV_nolen(caller) : "")); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
52 |
0 |
52 |
|
| 148 |
52 |
▶ | if (!(cll >= SvCUR(ns) && memEQ(ts, SvPVX(ns), SvCUR(ns)))) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(cll >= SvCUR(ns) && memEQ(ts, SvPVX(ns), SvCUR(ns)))) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
1 |
51 |
52 |
| if (!(cll >= SvCUR(ns) && memEQ(ts, SvPVX(ns), SvCUR(ns)))) { /* # uncoverable condition left count:2 class:ignore_covered_err */ |
0 |
1 |
1 |
|
| 149 |
51 |
| SV *full = newSVsv(ns); |
| 150 |
51 |
| sv_catsv(full, classsv); |
| 151 |
51 |
| classsv = sv_2mortal(full); |
| 152 |
|
| } |
| 153 |
52 |
| classname = SvPV_const(classsv, cl2); |
| 154 |
|
| { |
| 155 |
52 |
| SV *methsv = sv_2mortal(newSVpvn(method, metl)); |
| 156 |
52 |
| const char *methname = SvPV_nolen(methsv); |
| 157 |
52 |
| SV *loaderr = NULL; |
| 158 |
52 |
| cvp = pc_class_can(aTHX_ classname, cl2, methname); |
| 159 |
52 |
▶ | if (!cvp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cvp) { |
36 |
16 |
52 |
|
| 160 |
36 |
| SV *req = pk_require_src(aTHX_ classname); |
| 161 |
36 |
| eval_sv(req, G_SCALAR | G_EVAL); |
| 162 |
36 |
▶ | if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
36 |
0 |
36 |
| if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
12 |
24 |
36 |
|
| 163 |
12 |
| HV *st2 = gv_stashpvn(classname, cl2, 0); |
| 164 |
12 |
▶ | if (!(st2 && HvUSEDKEYS(st2))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(st2 && HvUSEDKEYS(st2))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
12 |
0 |
12 |
| if (!(st2 && HvUSEDKEYS(st2))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
0 |
12 |
12 |
| if (!(st2 && HvUSEDKEYS(st2))) /* # uncoverable condition left count:1 class:ignore_covered_err */ |
8 |
4 |
12 |
|
| 165 |
16 |
▶ | croak("Punk: %s names '%s' but %s does not load: %s", |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: %s names '%s' but %s does not load: %s", |
8 |
0 |
8 |
|
| 166 |
|
| what, ts, classname, SvPV_nolen(ERRSV)); |
| 167 |
|
| { |
| 168 |
4 |
| SV *nofile = sv_2mortal(newSVpvs("Can't locate ")); |
| 169 |
4 |
| const char *p = classname, *e = classname + cl2; |
| 170 |
|
| STRLEN nl; |
| 171 |
|
| const char *nf, *es; |
| 172 |
103 |
▶ | while (p < e) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < e) { |
99 |
4 |
103 |
|
| 173 |
99 |
▶ | if (p + 1 < e && p[0] == ':' && p[1] == ':') { /* # uncoverable condition right count:3 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| if (p + 1 < e && p[0] == ':' && p[1] == ':') { /* # uncoverable condition right count:3 class:ignore_covered_err */ |
95 |
4 |
99 |
| if (p + 1 < e && p[0] == ':' && p[1] == ':') { /* # uncoverable condition right count:3 class:ignore_covered_err */ |
9 |
86 |
95 |
| if (p + 1 < e && p[0] == ':' && p[1] == ':') { /* # uncoverable condition right count:3 class:ignore_covered_err */ |
9 |
0 |
9 |
|
| 174 |
9 |
| sv_catpvs(nofile, "/"); |
| 175 |
9 |
| p += 2; |
| 176 |
|
| } else { |
| 177 |
90 |
| sv_catpvn(nofile, p, 1); |
| 178 |
90 |
| p++; |
| 179 |
|
| } |
| 180 |
|
| } |
| 181 |
4 |
| sv_catpvs(nofile, ".pm "); |
| 182 |
4 |
| nf = SvPV_const(nofile, nl); |
| 183 |
4 |
▶ | es = SvPV_nolen(ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| es = SvPV_nolen(ERRSV); |
4 |
0 |
4 |
|
| 184 |
4 |
▶ | if (strncmp(es, nf, nl) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strncmp(es, nf, nl) != 0) |
3 |
1 |
4 |
|
| 185 |
3 |
▶ | loaderr = sv_2mortal(newSVsv(ERRSV)); |
Branch: 1 branch
| Branch | True | False | Total |
| loaderr = sv_2mortal(newSVsv(ERRSV)); |
3 |
0 |
3 |
|
| 186 |
|
| } |
| 187 |
|
| } |
| 188 |
28 |
| cvp = pc_class_can(aTHX_ classname, cl2, methname); |
| 189 |
|
| } |
| 190 |
44 |
▶ | if (!cvp && loaderr) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cvp && loaderr) |
4 |
40 |
44 |
| if (!cvp && loaderr) |
2 |
2 |
4 |
|
| 191 |
2 |
| croak("Punk: %s names '%s' but %s does not load: %s", |
| 192 |
|
| what, ts, classname, SvPV_nolen(loaderr)); |
| 193 |
42 |
▶ | if (!cvp) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cvp) |
2 |
40 |
42 |
|
| 194 |
2 |
| croak("Punk: %s names '%s' but %s has no method '%s'", |
| 195 |
|
| what, ts, classname, methname); |
| 196 |
|
| } |
| 197 |
40 |
| return newRV_inc((SV *)cvp); |
| 198 |
|
| } |
| 199 |
|
| |
| 200 |
|
| /* ---- context class -------------------------------------------------------- */ |
| 201 |
|
| |
| 202 |
|
| /* Build (once) the caller's ::_Context subclass of Punk::Context and install |
| 203 |
|
| * the registered helpers as methods on it. Returns the class name (+1). */ |
| 204 |
858 |
| static SV *pc_context_class(pTHX_ SV *self) { |
| 205 |
858 |
| HV *h = app_hv(aTHX_ self); |
| 206 |
858 |
| SV *caller = app_get(aTHX_ h, K_CALLER); |
| 207 |
1716 |
▶ | SV *classsv = newSVpvf("%s" PK_SFX_CONTEXT, caller ? SvPV_nolen(caller) : ""); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *classsv = newSVpvf("%s" PK_SFX_CONTEXT, caller ? SvPV_nolen(caller) : ""); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
858 |
0 |
858 |
|
| 208 |
858 |
| STRLEN cl; const char *class = SvPV_const(classsv, cl); |
| 209 |
858 |
| SV **defd = hv_fetchs(h, K_CTX_DEFINED, 0); |
| 210 |
|
| HV *helpers; AV *keys; SSize_t i, n; |
| 211 |
|
| |
| 212 |
|
| /* |
| 213 |
|
| # uncoverable branch false |
| 214 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 215 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 216 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 217 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 218 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 219 |
858 |
▶ | if (!(defd && *defd && SvTRUE(*defd))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(defd && *defd && SvTRUE(*defd))) { |
0 |
858 |
858 |
| if (!(defd && *defd && SvTRUE(*defd))) { |
0 |
0 |
0 |
| if (!(defd && *defd && SvTRUE(*defd))) { |
0 |
0 |
0 |
|
| 220 |
858 |
| SV *isaname = sv_2mortal(newSVpvf("%s::ISA", class)); |
| 221 |
858 |
| AV *isa = get_av(SvPV_nolen(isaname), GV_ADD); |
| 222 |
858 |
| av_push(isa, newSVpvs(PK_CONTEXT)); |
| 223 |
858 |
| (void)hv_stores(h, K_CTX_DEFINED, newSViv(1)); |
| 224 |
|
| } |
| 225 |
858 |
| helpers = app_hash(aTHX_ h, K_HELPERS); |
| 226 |
858 |
| keys = app_sorted_keys(aTHX_ helpers); |
| 227 |
858 |
| n = av_len(keys) + 1; |
| 228 |
1227 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
369 |
858 |
1227 |
|
| 229 |
369 |
| SV **kp = av_fetch(keys, i, 0); |
| 230 |
369 |
| STRLEN kl; const char *k = SvPV_const(*kp, kl); |
| 231 |
369 |
| SV **rec = hv_fetch(helpers, k, (I32)kl, 0); |
| 232 |
369 |
▶ | SV **code = (rec && *rec && SvROK(*rec)) |
Branch: 2 branches
| Branch | True | False | Total |
| SV **code = (rec && *rec && SvROK(*rec)) |
369 |
0 |
369 |
| SV **code = (rec && *rec && SvROK(*rec)) |
369 |
0 |
369 |
|
| 233 |
738 |
▶ | ? hv_fetchs((HV *)SvRV(*rec), K_CODE, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? hv_fetchs((HV *)SvRV(*rec), K_CODE, 0) : NULL; |
369 |
0 |
369 |
|
| 234 |
|
| /* |
| 235 |
|
| # uncoverable branch false |
| 236 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 237 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 238 |
369 |
▶ | if (code && *code) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (code && *code) { |
369 |
0 |
369 |
| if (code && *code) { |
369 |
0 |
369 |
|
| 239 |
369 |
| SV *gvname = sv_2mortal(newSVpvf("%s::%s", class, k)); |
| 240 |
369 |
| GV *gv = gv_fetchsv(gvname, GV_ADD, SVt_PVCV); |
| 241 |
369 |
| sv_setsv((SV *)gv, *code); /* *{class::name} = $code */ |
| 242 |
|
| } |
| 243 |
|
| } |
| 244 |
858 |
| return classsv; |
| 245 |
|
| } |
| 246 |
|
| |
| 247 |
|
| /* ---- models --------------------------------------------------------------- */ |
| 248 |
|
| |
| 249 |
|
| /* Load every ${ns}*.pm across @INC; push the bare names onto out. */ |
| 250 |
833 |
| static void pc_discover_namespace(pTHX_ SV *ns_sv, AV *out) { |
| 251 |
833 |
| STRLEN nsl; const char *nss = SvPV_const(ns_sv, nsl); |
| 252 |
833 |
| SV *rel = sv_2mortal(newSVpvn(nss, nsl)); |
| 253 |
833 |
| HV *seen = (HV *)sv_2mortal((SV *)newHV()); |
| 254 |
833 |
| AV *inc = GvAV(PL_incgv); |
| 255 |
|
| SSize_t i, n; |
| 256 |
|
| char *rp; STRLEN j, rl; |
| 257 |
|
| |
| 258 |
|
| /* rel = ns; s/::\z//; s{::}{/}g */ |
| 259 |
|
| /* |
| 260 |
|
| # uncoverable branch false |
| 261 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 262 |
833 |
▶ | if (SvCUR(rel) >= 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvCUR(rel) >= 2) { |
833 |
0 |
833 |
|
| 263 |
833 |
| rp = SvPVX(rel); |
| 264 |
|
| /* |
| 265 |
|
| # uncoverable branch false |
| 266 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 267 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 268 |
833 |
▶ | if (rp[SvCUR(rel) - 1] == ':' && rp[SvCUR(rel) - 2] == ':') |
Branch: 2 branches
| Branch | True | False | Total |
| if (rp[SvCUR(rel) - 1] == ':' && rp[SvCUR(rel) - 2] == ':') |
833 |
0 |
833 |
| if (rp[SvCUR(rel) - 1] == ':' && rp[SvCUR(rel) - 2] == ':') |
833 |
0 |
833 |
|
| 269 |
833 |
| SvCUR_set(rel, SvCUR(rel) - 2); |
| 270 |
|
| } |
| 271 |
833 |
| rp = SvPVX(rel); rl = SvCUR(rel); |
| 272 |
|
| { |
| 273 |
833 |
| SV *slashed = sv_2mortal(newSVpvs("")); |
| 274 |
11682 |
▶ | for (j = 0; j < rl; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < rl; j++) { |
10849 |
833 |
11682 |
|
| 275 |
|
| /* |
| 276 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 277 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 278 |
10849 |
▶ | if (rp[j] == ':' && j + 1 < rl && rp[j + 1] == ':') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (rp[j] == ':' && j + 1 < rl && rp[j + 1] == ':') { |
851 |
9998 |
10849 |
| if (rp[j] == ':' && j + 1 < rl && rp[j + 1] == ':') { |
851 |
0 |
851 |
| if (rp[j] == ':' && j + 1 < rl && rp[j + 1] == ':') { |
851 |
0 |
851 |
|
| 279 |
851 |
| sv_catpvs(slashed, "/"); j++; |
| 280 |
|
| } |
| 281 |
9998 |
| else sv_catpvn(slashed, rp + j, 1); |
| 282 |
|
| } |
| 283 |
833 |
| rel = slashed; |
| 284 |
|
| } |
| 285 |
|
| |
| 286 |
833 |
▶ | n = inc ? av_len(inc) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| n = inc ? av_len(inc) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
833 |
0 |
833 |
|
| 287 |
7663 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
6830 |
833 |
7663 |
|
| 288 |
6830 |
| SV **ip = av_fetch(inc, i, 0); |
| 289 |
|
| SV *dir; DIR *dh; Direntry_t *de; AV *ents; SSize_t ei, en; |
| 290 |
|
| /* |
| 291 |
|
| # uncoverable branch true |
| 292 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 293 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 294 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 295 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 296 |
6830 |
▶ | if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
6830 |
0 |
6830 |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
6830 |
0 |
6830 |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
6830 |
0 |
6830 |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
0 |
6830 |
6830 |
|
| 297 |
6830 |
| dir = sv_2mortal(newSVsv(*ip)); |
| 298 |
6830 |
| sv_catpvs(dir, "/"); sv_catsv(dir, rel); |
| 299 |
6830 |
| dh = PerlDir_open(SvPV_nolen(dir)); |
| 300 |
6830 |
▶ | if (!dh) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dh) continue; |
6828 |
2 |
6830 |
|
| 301 |
2 |
| ents = (AV *)sv_2mortal((SV *)newAV()); |
| 302 |
10 |
▶ | while ((de = PerlDir_read(dh))) av_push(ents, newSVpv(de->d_name, 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| while ((de = PerlDir_read(dh))) av_push(ents, newSVpv(de->d_name, 0)); |
8 |
2 |
10 |
|
| 303 |
2 |
| PerlDir_close(dh); |
| 304 |
2 |
| en = av_len(ents) + 1; |
| 305 |
|
| /* |
| 306 |
|
| # uncoverable branch false |
| 307 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 308 |
2 |
▶ | if (en > 1) sortsv(AvARRAY(ents), (STRLEN)en, Perl_sv_cmp); |
Branch: 1 branch
| Branch | True | False | Total |
| if (en > 1) sortsv(AvARRAY(ents), (STRLEN)en, Perl_sv_cmp); |
2 |
0 |
2 |
|
| 309 |
10 |
▶ | for (ei = 0; ei < en; ei++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ei = 0; ei < en; ei++) { |
8 |
2 |
10 |
|
| 310 |
8 |
| SV **ep = av_fetch(ents, ei, 0); |
| 311 |
8 |
| STRLEN el; const char *es = SvPV_const(*ep, el); |
| 312 |
|
| STRLEN b; int ok; |
| 313 |
|
| SV *name, *class; |
| 314 |
|
| /* |
| 315 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 316 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 317 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 318 |
8 |
▶ | if (el <= 3 || !(es[el-3]=='.' && es[el-2]=='p' && es[el-1]=='m')) |
Branch: 4 branches
| Branch | True | False | Total |
| if (el <= 3 || !(es[el-3]=='.' && es[el-2]=='p' && es[el-1]=='m')) |
4 |
4 |
8 |
| if (el <= 3 || !(es[el-3]=='.' && es[el-2]=='p' && es[el-1]=='m')) |
4 |
0 |
4 |
| if (el <= 3 || !(es[el-3]=='.' && es[el-2]=='p' && es[el-1]=='m')) |
4 |
0 |
4 |
| if (el <= 3 || !(es[el-3]=='.' && es[el-2]=='p' && es[el-1]=='m')) |
0 |
4 |
4 |
|
| 319 |
4 |
| continue; |
| 320 |
4 |
| ok = el - 3 > 0; |
| 321 |
|
| /* |
| 322 |
|
| # uncoverable branch true class:ignore_covered_err |
| 323 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 324 |
25 |
▶ | for (b = 0; b < el - 3; b++) if (!isWORDCHAR(es[b])) { ok = 0; break; } |
Branch: 2 branches
| Branch | True | False | Total |
| for (b = 0; b < el - 3; b++) if (!isWORDCHAR(es[b])) { ok = 0; break; } |
0 |
21 |
21 |
| for (b = 0; b < el - 3; b++) if (!isWORDCHAR(es[b])) { ok = 0; break; } |
21 |
4 |
25 |
|
| 325 |
|
| /* |
| 326 |
|
| # uncoverable branch true |
| 327 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 328 |
4 |
▶ | if (!ok) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ok) continue; |
0 |
4 |
4 |
|
| 329 |
4 |
| name = sv_2mortal(newSVpvn(es, el - 3)); |
| 330 |
4 |
| class = sv_2mortal(newSVsv(ns_sv)); sv_catsv(class, name); |
| 331 |
|
| /* |
| 332 |
|
| # uncoverable branch true |
| 333 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 334 |
4 |
▶ | if (hv_exists_ent(seen, class, 0)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent(seen, class, 0)) continue; |
0 |
4 |
4 |
|
| 335 |
4 |
| (void)hv_store_ent(seen, class, PUNK_SET_TRUE, 0); |
| 336 |
|
| /* |
| 337 |
|
| # uncoverable branch false |
| 338 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 339 |
4 |
▶ | if (!pc_class_can(aTHX_ SvPVX(class), SvCUR(class), |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pc_class_can(aTHX_ SvPVX(class), SvCUR(class), |
4 |
0 |
4 |
|
| 340 |
|
| "_punk_model_meta")) { |
| 341 |
|
| /* by module name, not by the path the scan found: a |
| 342 |
|
| * path-form require of "lib/..." is @INC-searched too and |
| 343 |
|
| * misses when the entry that held the file is relative */ |
| 344 |
4 |
| SV *req = pk_require_src(aTHX_ SvPV_nolen(class)); |
| 345 |
4 |
| eval_sv(req, G_SCALAR | G_EVAL); |
| 346 |
|
| /* |
| 347 |
|
| # uncoverable branch true |
| 348 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 349 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 350 |
4 |
▶ | if (SvTRUE(ERRSV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) |
4 |
0 |
4 |
| if (SvTRUE(ERRSV)) |
0 |
4 |
4 |
|
| 351 |
0 |
▶ | croak("Punk: model %s failed to load: %s", /* # uncoverable statement */ |
Branch: 2 branches
| Branch | True | False | Total |
| croak("Punk: model %s failed to load: %s", /* # uncoverable statement */ |
0 |
0 |
0 |
| croak("Punk: model %s failed to load: %s", /* # uncoverable statement */ |
0 |
0 |
0 |
|
| 352 |
|
| SvPV_nolen(class), SvPV_nolen(ERRSV)); /* # uncoverable statement */ |
| 353 |
|
| } |
| 354 |
4 |
| av_push(out, newSVsv(name)); |
| 355 |
|
| } |
| 356 |
|
| } |
| 357 |
833 |
| } |
| 358 |
|
| |
| 359 |
|
| /* Resolve the registered + auto-discovered model names to classes, checking |
| 360 |
|
| * each is a Punk::Model with a table. Fills $self->{models_compiled}. */ |
| 361 |
854 |
| static void pc_compile_models(pTHX_ SV *self) { |
| 362 |
854 |
| HV *h = app_hv(aTHX_ self); |
| 363 |
854 |
| SV *caller = app_get(aTHX_ h, K_CALLER); |
| 364 |
1708 |
▶ | SV *ns = sv_2mortal(newSVpvf("%s" PK_NS_MODEL, caller ? SvPV_nolen(caller) : "")); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *ns = sv_2mortal(newSVpvf("%s" PK_NS_MODEL, caller ? SvPV_nolen(caller) : "")); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
854 |
0 |
854 |
|
| 365 |
854 |
| AV *names = (AV *)sv_2mortal((SV *)newAV()); |
| 366 |
854 |
| AV *models = app_av(aTHX_ h, K_MODELS); |
| 367 |
854 |
| SV **autop = hv_fetchs(h, K_MODEL_AUTO, 0); |
| 368 |
854 |
| SSize_t i, n = av_len(models) + 1; |
| 369 |
854 |
| int have_named = (n > 0), autoflag; |
| 370 |
|
| HV *reg; |
| 371 |
|
| |
| 372 |
879 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
25 |
854 |
879 |
|
| 373 |
25 |
| SV **e = av_fetch(models, i, 0); |
| 374 |
|
| /* |
| 375 |
|
| # uncoverable branch false |
| 376 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 377 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 378 |
25 |
▶ | if (e && *e) av_push(names, newSVsv(*e)); |
Branch: 2 branches
| Branch | True | False | Total |
| if (e && *e) av_push(names, newSVsv(*e)); |
25 |
0 |
25 |
| if (e && *e) av_push(names, newSVsv(*e)); |
25 |
0 |
25 |
|
| 379 |
|
| } |
| 380 |
2 |
▶ | autoflag = (autop && *autop && SvOK(*autop)) ? (SvTRUE(*autop) ? 1 : 0) |
Branch: 2 branches
| Branch | True | False | Total |
| autoflag = (autop && *autop && SvOK(*autop)) ? (SvTRUE(*autop) ? 1 : 0) |
2 |
0 |
2 |
| autoflag = (autop && *autop && SvOK(*autop)) ? (SvTRUE(*autop) ? 1 : 0) |
2 |
0 |
2 |
|
| 381 |
856 |
▶ | : !have_named; |
Branch: 1 branch
| Branch | True | False | Total |
| : !have_named; |
2 |
852 |
854 |
|
| 382 |
854 |
▶ | if (autoflag) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (autoflag) { |
833 |
21 |
854 |
|
| 383 |
|
| HV *stash; |
| 384 |
833 |
| STRLEN nsl2 = SvCUR(ns); |
| 385 |
833 |
| pc_discover_namespace(aTHX_ ns, names); |
| 386 |
|
| /* plus any ${ns}* already in the symbol table that isa Punk::Model - |
| 387 |
|
| * gv_stashpvn wants the bare package name, so the namespace's |
| 388 |
|
| * trailing '::' comes off first (with it, the lookup misses and |
| 389 |
|
| * in-memory model classes were silently never discovered) */ |
| 390 |
|
| /* |
| 391 |
|
| # uncoverable branch false |
| 392 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 393 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 394 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 395 |
833 |
▶ | if (nsl2 >= 2 && SvPVX(ns)[nsl2 - 1] == ':' |
Branch: 2 branches
| Branch | True | False | Total |
| if (nsl2 >= 2 && SvPVX(ns)[nsl2 - 1] == ':' |
833 |
0 |
833 |
| if (nsl2 >= 2 && SvPVX(ns)[nsl2 - 1] == ':' |
833 |
0 |
833 |
|
| 396 |
833 |
▶ | && SvPVX(ns)[nsl2 - 2] == ':') |
Branch: 1 branch
| Branch | True | False | Total |
| && SvPVX(ns)[nsl2 - 2] == ':') |
833 |
0 |
833 |
|
| 397 |
833 |
| nsl2 -= 2; |
| 398 |
833 |
| stash = gv_stashpvn(SvPVX(ns), nsl2, 0); |
| 399 |
833 |
▶ | if (stash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (stash) { |
18 |
815 |
833 |
|
| 400 |
18 |
| HE *he; AV *syms = (AV *)sv_2mortal((SV *)newAV()); SSize_t si, sn; |
| 401 |
18 |
| hv_iterinit(stash); |
| 402 |
49 |
▶ | while ((he = hv_iternext(stash))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(stash))) { |
31 |
18 |
49 |
|
| 403 |
31 |
▶ | STRLEN kl; const char *k = HePV(he, kl); |
Branch: 1 branch
| Branch | True | False | Total |
| STRLEN kl; const char *k = HePV(he, kl); |
0 |
31 |
31 |
|
| 404 |
|
| /* |
| 405 |
|
| # uncoverable branch false |
| 406 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 407 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 408 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 409 |
31 |
▶ | if (kl >= 3 && k[kl-1] == ':' && k[kl-2] == ':') |
Branch: 3 branches
| Branch | True | False | Total |
| if (kl >= 3 && k[kl-1] == ':' && k[kl-2] == ':') |
31 |
0 |
31 |
| if (kl >= 3 && k[kl-1] == ':' && k[kl-2] == ':') |
31 |
0 |
31 |
| if (kl >= 3 && k[kl-1] == ':' && k[kl-2] == ':') |
31 |
0 |
31 |
|
| 410 |
31 |
| av_push(syms, newSVpvn(k, kl - 2)); |
| 411 |
|
| } |
| 412 |
18 |
| sn = av_len(syms) + 1; |
| 413 |
18 |
▶ | if (sn > 1) sortsv(AvARRAY(syms), (STRLEN)sn, Perl_sv_cmp); |
Branch: 1 branch
| Branch | True | False | Total |
| if (sn > 1) sortsv(AvARRAY(syms), (STRLEN)sn, Perl_sv_cmp); |
6 |
12 |
18 |
|
| 414 |
49 |
▶ | for (si = 0; si < sn; si++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (si = 0; si < sn; si++) { |
31 |
18 |
49 |
|
| 415 |
31 |
| SV **symp = av_fetch(syms, si, 0); |
| 416 |
31 |
| SV *class = sv_2mortal(newSVsv(ns)); |
| 417 |
31 |
| sv_catsv(class, *symp); |
| 418 |
31 |
▶ | if (sv_derived_from(sv_2mortal(newSVsv(class)), PK_MODEL)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_derived_from(sv_2mortal(newSVsv(class)), PK_MODEL)) |
29 |
2 |
31 |
|
| 419 |
29 |
| av_push(names, newSVsv(*symp)); |
| 420 |
|
| } |
| 421 |
|
| } |
| 422 |
|
| } |
| 423 |
854 |
▶ | if (av_len(names) < 0) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(names) < 0) return; |
816 |
38 |
854 |
|
| 424 |
|
| |
| 425 |
38 |
| (void)pk_require_once(aTHX_ PK_MODEL, TRUE); |
| 426 |
38 |
| reg = newHV(); |
| 427 |
38 |
| n = av_len(names) + 1; |
| 428 |
93 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
58 |
35 |
93 |
|
| 429 |
58 |
| SV **np = av_fetch(names, i, 0); |
| 430 |
58 |
| STRLEN nl; const char *nm = SvPV_const(*np, nl); |
| 431 |
|
| SV *class; STRLEN cl; const char *cs; SV *meta; |
| 432 |
58 |
▶ | if (hv_exists(reg, nm, (I32)nl)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(reg, nm, (I32)nl)) continue; |
5 |
53 |
58 |
|
| 433 |
53 |
▶ | if (memchr(nm, ':', nl)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (memchr(nm, ':', nl)) |
2 |
51 |
53 |
|
| 434 |
2 |
| class = sv_2mortal(newSVsv(*np)); |
| 435 |
51 |
| else { class = sv_2mortal(newSVsv(ns)); sv_catsv(class, *np); } |
| 436 |
53 |
| cs = SvPV_const(class, cl); |
| 437 |
53 |
▶ | if (!pc_class_can(aTHX_ cs, cl, "_punk_model_meta")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pc_class_can(aTHX_ cs, cl, "_punk_model_meta")) { |
3 |
50 |
53 |
|
| 438 |
3 |
| SV *req = pk_require_src(aTHX_ cs); |
| 439 |
3 |
| eval_sv(req, G_SCALAR | G_EVAL); |
| 440 |
3 |
▶ | if (SvTRUE(ERRSV)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
3 |
0 |
3 |
| if (SvTRUE(ERRSV)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
1 |
2 |
3 |
|
| 441 |
2 |
▶ | croak("Punk: model '%s' (%s) failed to load: %s", |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: model '%s' (%s) failed to load: %s", |
1 |
0 |
1 |
|
| 442 |
|
| nm, cs, SvPV_nolen(ERRSV)); |
| 443 |
|
| } |
| 444 |
52 |
▶ | if (!sv_derived_from(class, PK_MODEL)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_derived_from(class, PK_MODEL)) |
1 |
51 |
52 |
|
| 445 |
1 |
| croak("Punk: model '%s' (%s) does not use Punk::Model", nm, cs); |
| 446 |
51 |
| meta = pcx_call_meth(aTHX_ class, "_punk_model_meta", NULL, 0, 1); |
| 447 |
|
| /* |
| 448 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 449 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 450 |
51 |
▶ | if (!(meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV)) { |
51 |
0 |
51 |
| if (!(meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV)) { |
50 |
1 |
51 |
| if (!(meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV)) { |
0 |
50 |
50 |
|
| 451 |
|
| /* |
| 452 |
|
| # uncoverable branch false |
| 453 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 454 |
1 |
▶ | if (meta) SvREFCNT_dec(meta); |
Branch: 1 branch
| Branch | True | False | Total |
| if (meta) SvREFCNT_dec(meta); |
1 |
0 |
1 |
|
| 455 |
1 |
| croak("Punk: model '%s' (%s) declares no table", nm, cs); |
| 456 |
|
| } |
| 457 |
50 |
| SvREFCNT_dec(meta); |
| 458 |
50 |
| (void)hv_store(reg, nm, (I32)nl, newSVsv(class), 0); |
| 459 |
|
| } |
| 460 |
35 |
| (void)hv_stores(h, K_MODELS_C, newRV_noinc((SV *)reg)); |
| 461 |
|
| } |
| 462 |
|
| |
| 463 |
|
| /* the backend options for a model class: its selected database, or {} for the |
| 464 |
|
| * (possibly unconfigured) default. */ |
| 465 |
44 |
| static SV *pc_db_opts_for(pTHX_ SV *self, SV *classsv) { |
| 466 |
44 |
| HV *h = app_hv(aTHX_ self); |
| 467 |
44 |
| HV *dbs = app_hash(aTHX_ h, K_DATABASES); |
| 468 |
44 |
| SV *meta = pcx_call_meth(aTHX_ classsv, "_punk_model_meta", NULL, 0, 1); |
| 469 |
44 |
| const char *wname = K_DEFAULT; STRLEN wl = 7; |
| 470 |
|
| SV **opts; SV *ret; |
| 471 |
|
| /* |
| 472 |
|
| # uncoverable branch false |
| 473 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 474 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 475 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 476 |
44 |
▶ | if (meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV) { |
44 |
0 |
44 |
| if (meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV) { |
44 |
0 |
44 |
| if (meta && SvROK(meta) && SvTYPE(SvRV(meta)) == SVt_PVHV) { |
44 |
0 |
44 |
|
| 477 |
44 |
| SV **d = hv_fetchs((HV *)SvRV(meta), "database", 0); |
| 478 |
|
| /* |
| 479 |
|
| # uncoverable branch false |
| 480 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 481 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 482 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 483 |
88 |
▶ | if (d && *d && SvTRUE(*d)) wname = SvPV_const(*d, wl); |
Branch: 3 branches
| Branch | True | False | Total |
| if (d && *d && SvTRUE(*d)) wname = SvPV_const(*d, wl); |
44 |
0 |
44 |
| if (d && *d && SvTRUE(*d)) wname = SvPV_const(*d, wl); |
44 |
0 |
44 |
| if (d && *d && SvTRUE(*d)) wname = SvPV_const(*d, wl); |
44 |
0 |
44 |
|
| 484 |
|
| } |
| 485 |
44 |
| opts = hv_fetch(dbs, wname, (I32)wl, 0); |
| 486 |
|
| /* |
| 487 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 488 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 489 |
44 |
▶ | if (opts && *opts && SvOK(*opts)) ret = newSVsv(*opts); |
Branch: 3 branches
| Branch | True | False | Total |
| if (opts && *opts && SvOK(*opts)) ret = newSVsv(*opts); |
43 |
1 |
44 |
| if (opts && *opts && SvOK(*opts)) ret = newSVsv(*opts); |
43 |
0 |
43 |
| if (opts && *opts && SvOK(*opts)) ret = newSVsv(*opts); |
43 |
0 |
43 |
|
| 490 |
|
| /* |
| 491 |
|
| # uncoverable branch false |
| 492 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 493 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 494 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 495 |
1 |
▶ | else if (!(wl == 7 && memEQ(wname, K_DEFAULT, 7))) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (!(wl == 7 && memEQ(wname, K_DEFAULT, 7))) |
0 |
1 |
1 |
| else if (!(wl == 7 && memEQ(wname, K_DEFAULT, 7))) |
0 |
0 |
0 |
|
| 496 |
1 |
| croak("Punk: model '%s' selects database '%s', which no database " |
| 497 |
|
| "keyword configured", SvPV_nolen(classsv), wname); |
| 498 |
0 |
| else ret = newRV_noinc((SV *)newHV()); /* # uncoverable statement */ |
| 499 |
|
| /* |
| 500 |
|
| # uncoverable branch false |
| 501 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 502 |
43 |
▶ | if (meta) SvREFCNT_dec(meta); |
Branch: 1 branch
| Branch | True | False | Total |
| if (meta) SvREFCNT_dec(meta); |
43 |
0 |
43 |
|
| 503 |
43 |
| return ret; |
| 504 |
|
| } |
| 505 |
|
| |
| 506 |
|
| /* ---- docs (Open::API::UI) into plain GET route records -------------------- */ |
| 507 |
|
| |
| 508 |
|
| /* Materialise the `docs` records into GET route records (target a closure over |
| 509 |
|
| * the UI's finished-triplet thunk), croaking if a docs path collides with a |
| 510 |
|
| * mounted spec's operation. api_mounts is the compiled [{mount,prefix,len}]. */ |
| 511 |
879 |
| static AV *pc_docs_routes(pTHX_ SV *self, AV *api_mounts) { |
| 512 |
879 |
| HV *h = app_hv(aTHX_ self); |
| 513 |
879 |
| AV *extra = (AV *)sv_2mortal((SV *)newAV()); |
| 514 |
879 |
| SV **docsp = hv_fetchs(h, K_DOCS, 0); |
| 515 |
|
| /* |
| 516 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 517 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 518 |
879 |
▶ | AV *docs = (docsp && *docsp && SvROK(*docsp)) ? (AV *)SvRV(*docsp) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| AV *docs = (docsp && *docsp && SvROK(*docsp)) ? (AV *)SvRV(*docsp) : NULL; |
14 |
865 |
879 |
| AV *docs = (docsp && *docsp && SvROK(*docsp)) ? (AV *)SvRV(*docsp) : NULL; |
14 |
0 |
14 |
| AV *docs = (docsp && *docsp && SvROK(*docsp)) ? (AV *)SvRV(*docsp) : NULL; |
14 |
0 |
14 |
|
| 519 |
879 |
▶ | SSize_t i, n = docs ? av_len(docs) + 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t i, n = docs ? av_len(docs) + 1 : 0; |
14 |
865 |
879 |
|
| 520 |
879 |
▶ | SSize_t amn = api_mounts ? av_len(api_mounts) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t amn = api_mounts ? av_len(api_mounts) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
879 |
0 |
879 |
|
| 521 |
|
| |
| 522 |
889 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
14 |
875 |
889 |
|
| 523 |
14 |
| SV **rp = av_fetch(docs, i, 0); |
| 524 |
|
| /* |
| 525 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 526 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 527 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 528 |
14 |
▶ | HV *rec = (rp && *rp && SvROK(*rp)) ? (HV *)SvRV(*rp) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| HV *rec = (rp && *rp && SvROK(*rp)) ? (HV *)SvRV(*rp) : NULL; |
14 |
0 |
14 |
| HV *rec = (rp && *rp && SvROK(*rp)) ? (HV *)SvRV(*rp) : NULL; |
14 |
0 |
14 |
| HV *rec = (rp && *rp && SvROK(*rp)) ? (HV *)SvRV(*rp) : NULL; |
14 |
0 |
14 |
|
| 529 |
|
| SV *mount, *path, *opts, *api, *ui, *routes, **x; |
| 530 |
|
| AV *nav, *rl; SSize_t ri, rn; int nn, k; SV **nargv; |
| 531 |
|
| /* |
| 532 |
|
| # uncoverable branch true |
| 533 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 534 |
14 |
▶ | if (!rec) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rec) continue; |
0 |
14 |
14 |
|
| 535 |
|
| /* |
| 536 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 537 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 538 |
14 |
▶ | x = hv_fetchs(rec, K_MOUNT, 0); mount = (x && *x && SvOK(*x)) ? *x : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| x = hv_fetchs(rec, K_MOUNT, 0); mount = (x && *x && SvOK(*x)) ? *x : NULL; |
14 |
0 |
14 |
| x = hv_fetchs(rec, K_MOUNT, 0); mount = (x && *x && SvOK(*x)) ? *x : NULL; |
14 |
0 |
14 |
| x = hv_fetchs(rec, K_MOUNT, 0); mount = (x && *x && SvOK(*x)) ? *x : NULL; |
9 |
5 |
14 |
|
| 539 |
|
| /* |
| 540 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 541 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 542 |
14 |
▶ | x = hv_fetchs(rec, K_PATH, 0); path = (x && *x) ? *x : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| x = hv_fetchs(rec, K_PATH, 0); path = (x && *x) ? *x : &PL_sv_undef; |
14 |
0 |
14 |
| x = hv_fetchs(rec, K_PATH, 0); path = (x && *x) ? *x : &PL_sv_undef; |
14 |
0 |
14 |
|
| 543 |
|
| /* |
| 544 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 545 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 546 |
14 |
▶ | x = hv_fetchs(rec, K_OPTS, 0); opts = (x && *x) ? *x : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| x = hv_fetchs(rec, K_OPTS, 0); opts = (x && *x) ? *x : NULL; |
14 |
0 |
14 |
| x = hv_fetchs(rec, K_OPTS, 0); opts = (x && *x) ? *x : NULL; |
14 |
0 |
14 |
|
| 547 |
14 |
▶ | if (!mount) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mount) { |
5 |
9 |
14 |
|
| 548 |
|
| HV *m0h; SV **mm; |
| 549 |
5 |
▶ | if (amn < 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (amn < 1) |
2 |
3 |
5 |
|
| 550 |
2 |
| croak("Punk: docs needs an api mount (none registered)"); |
| 551 |
3 |
▶ | if (amn > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (amn > 1) |
1 |
2 |
3 |
|
| 552 |
1 |
| croak("Punk: docs needs the mount named (several apis " |
| 553 |
|
| "are registered)"); |
| 554 |
2 |
| m0h = (HV *)SvRV(*av_fetch(api_mounts, 0, 0)); |
| 555 |
2 |
| mm = hv_fetchs(m0h, K_MOUNT, 0); |
| 556 |
|
| /* |
| 557 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 558 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 559 |
2 |
▶ | mount = (mm && *mm) ? *mm : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| mount = (mm && *mm) ? *mm : NULL; |
2 |
0 |
2 |
| mount = (mm && *mm) ? *mm : NULL; |
2 |
0 |
2 |
|
| 560 |
|
| } |
| 561 |
|
| /* |
| 562 |
|
| # uncoverable branch true |
| 563 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 564 |
11 |
▶ | if (!pk_require_once(aTHX_ PK_OA_UI, FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pk_require_once(aTHX_ PK_OA_UI, FALSE)) |
0 |
11 |
11 |
|
| 565 |
0 |
▶ | croak("Punk: the docs keyword needs Open::API::UI - Open::API " /* # uncoverable statement */ |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: the docs keyword needs Open::API::UI - Open::API " /* # uncoverable statement */ |
0 |
0 |
0 |
|
| 566 |
|
| "0.03+ with Template::Stencil and Markdown::Simple - and " |
| 567 |
|
| "it failed to load: %s", SvPV_nolen(ERRSV)); /* # uncoverable statement */ |
| 568 |
11 |
| api = sv_2mortal(pcx_call_meth(aTHX_ mount, K_API, NULL, 0, 1)); |
| 569 |
11 |
| nav = (AV *)sv_2mortal((SV *)newAV()); |
| 570 |
11 |
| av_push(nav, newSVpvs(K_API)); av_push(nav, newSVsv(api)); |
| 571 |
11 |
| av_push(nav, newSVpvs(K_PATH)); av_push(nav, newSVsv(path)); |
| 572 |
|
| /* The docs UI does a double-submit: it reads the mirror cookie and |
| 573 |
|
| * sends the header. Hand it the real names when csrf is on, so |
| 574 |
|
| * try-it-out can write; 0 (off) when it is not. */ |
| 575 |
11 |
| av_push(nav, newSVpvs(K_CSRF)); |
| 576 |
|
| { |
| 577 |
11 |
| SV **cc = hv_fetchs(h, K_CSRF, 0); |
| 578 |
|
| /* |
| 579 |
|
| # uncoverable branch true |
| 580 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 581 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 582 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 583 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 584 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 585 |
|
| # uncoverable condition left count:4 class:ignore_covered_err |
| 586 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 587 |
11 |
▶ | if (cc && *cc && SvROK(*cc) && SvTYPE(SvRV(*cc)) == SVt_PVHV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (cc && *cc && SvROK(*cc) && SvTYPE(SvRV(*cc)) == SVt_PVHV) { |
0 |
11 |
11 |
| if (cc && *cc && SvROK(*cc) && SvTYPE(SvRV(*cc)) == SVt_PVHV) { |
0 |
0 |
0 |
| if (cc && *cc && SvROK(*cc) && SvTYPE(SvRV(*cc)) == SVt_PVHV) { |
0 |
0 |
0 |
| if (cc && *cc && SvROK(*cc) && SvTYPE(SvRV(*cc)) == SVt_PVHV) { |
0 |
0 |
0 |
|
| 588 |
0 |
| HV *cfg = (HV *)SvRV(*cc), *ui = newHV(); /* # uncoverable statement */ |
| 589 |
|
| static const char *const pass[] = { "header", "cookie", NULL }; |
| 590 |
|
| int pi; |
| 591 |
|
| /* |
| 592 |
|
| # uncoverable statement |
| 593 |
|
| # uncoverable branch true |
| 594 |
|
| # uncoverable branch false |
| 595 |
|
| # uncoverable condition left count:1 |
| 596 |
|
| # uncoverable condition right count:1 */ |
| 597 |
0 |
▶ | for (pi = 0; pass[pi]; pi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (pi = 0; pass[pi]; pi++) { |
0 |
0 |
0 |
|
| 598 |
0 |
| SV **e = hv_fetch(cfg, pass[pi], (I32)strlen(pass[pi]), 0); /* # uncoverable statement */ |
| 599 |
|
| /* |
| 600 |
|
| # uncoverable statement |
| 601 |
|
| # uncoverable branch true |
| 602 |
|
| # uncoverable branch false |
| 603 |
|
| # uncoverable condition left count:1 |
| 604 |
|
| # uncoverable condition right count:1 |
| 605 |
|
| # uncoverable condition left count:2 |
| 606 |
|
| # uncoverable condition right count:2 |
| 607 |
|
| # uncoverable condition left count:3 |
| 608 |
|
| # uncoverable condition right count:3 */ |
| 609 |
0 |
▶ | if (e && *e && SvOK(*e)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (e && *e && SvOK(*e)) |
0 |
0 |
0 |
| if (e && *e && SvOK(*e)) |
0 |
0 |
0 |
| if (e && *e && SvOK(*e)) |
0 |
0 |
0 |
|
| 610 |
0 |
| (void)hv_store(ui, pass[pi], (I32)strlen(pass[pi]), /* # uncoverable statement */ |
| 611 |
|
| newSVsv(*e), 0); |
| 612 |
|
| } |
| 613 |
0 |
| av_push(nav, newRV_noinc((SV *)ui)); /* # uncoverable statement */ |
| 614 |
|
| } |
| 615 |
11 |
| else av_push(nav, newSViv(0)); |
| 616 |
|
| } |
| 617 |
|
| /* |
| 618 |
|
| # uncoverable branch false |
| 619 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 620 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 621 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 622 |
11 |
▶ | if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) { |
11 |
0 |
11 |
| if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) { |
11 |
0 |
11 |
| if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) { |
11 |
0 |
11 |
|
| 623 |
11 |
| HV *oh = (HV *)SvRV(opts); HE *oe; |
| 624 |
11 |
| hv_iterinit(oh); |
| 625 |
12 |
▶ | while ((oe = hv_iternext(oh))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((oe = hv_iternext(oh))) { |
1 |
11 |
12 |
|
| 626 |
1 |
| av_push(nav, newSVsv(hv_iterkeysv(oe))); |
| 627 |
1 |
| av_push(nav, newSVsv(hv_iterval(oh, oe))); |
| 628 |
|
| } |
| 629 |
|
| } |
| 630 |
11 |
| nn = (int)(av_len(nav) + 1); |
| 631 |
11 |
▶ | Newx(nargv, nn > 0 ? nn : 1, SV *); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| Newx(nargv, nn > 0 ? nn : 1, SV *); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
11 |
0 |
11 |
|
| 632 |
79 |
▶ | for (k = 0; k < nn; k++) nargv[k] = *av_fetch(nav, k, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < nn; k++) nargv[k] = *av_fetch(nav, k, 0); |
68 |
11 |
79 |
|
| 633 |
11 |
| ui = sv_2mortal(pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_OA_UI)), |
| 634 |
|
| "new", nargv, nn, 1)); |
| 635 |
11 |
| Safefree(nargv); |
| 636 |
11 |
| routes = sv_2mortal(pcx_call_meth(aTHX_ ui, "routes", NULL, 0, 1)); |
| 637 |
11 |
▶ | rl = (routes && SvROK(routes) && SvTYPE(SvRV(routes)) == SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| rl = (routes && SvROK(routes) && SvTYPE(SvRV(routes)) == SVt_PVAV) |
11 |
0 |
11 |
| rl = (routes && SvROK(routes) && SvTYPE(SvRV(routes)) == SVt_PVAV) |
11 |
0 |
11 |
|
| 638 |
22 |
▶ | ? (AV *)SvRV(routes) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (AV *)SvRV(routes) : NULL; |
11 |
0 |
11 |
|
| 639 |
11 |
▶ | rn = rl ? av_len(rl) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| rn = rl ? av_len(rl) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
11 |
0 |
11 |
|
| 640 |
61 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
51 |
10 |
61 |
|
| 641 |
51 |
| SV **rr = av_fetch(rl, ri, 0); |
| 642 |
|
| /* |
| 643 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 644 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 645 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 646 |
51 |
▶ | HV *r = (rr && *rr && SvROK(*rr)) ? (HV *)SvRV(*rr) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| HV *r = (rr && *rr && SvROK(*rr)) ? (HV *)SvRV(*rr) : NULL; |
51 |
0 |
51 |
| HV *r = (rr && *rr && SvROK(*rr)) ? (HV *)SvRV(*rr) : NULL; |
51 |
0 |
51 |
| HV *r = (rr && *rr && SvROK(*rr)) ? (HV *)SvRV(*rr) : NULL; |
51 |
0 |
51 |
|
| 647 |
|
| SV **rpathp, **respp; STRLEN rpl; const char *rps; |
| 648 |
|
| HV *route; SV *target; AV *dcap; SSize_t mi; |
| 649 |
|
| /* |
| 650 |
|
| # uncoverable branch true |
| 651 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 652 |
51 |
▶ | if (!r) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) continue; |
0 |
51 |
51 |
|
| 653 |
51 |
| rpathp = hv_fetchs(r, K_PATH, 0); |
| 654 |
51 |
| rps = SvPV_const(*rpathp, rpl); |
| 655 |
106 |
▶ | for (mi = 0; mi < amn; mi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mi = 0; mi < amn; mi++) { |
56 |
50 |
106 |
|
| 656 |
56 |
| HV *mh = (HV *)SvRV(*av_fetch(api_mounts, mi, 0)); |
| 657 |
56 |
| SV **pfp = hv_fetchs(mh, K_PREFIX, 0); |
| 658 |
56 |
| SV **lp = hv_fetchs(mh, K_LEN, 0); |
| 659 |
56 |
| SV **mmp = hv_fetchs(mh, K_MOUNT, 0); |
| 660 |
|
| STRLEN pfl; const char *pf; |
| 661 |
|
| /* |
| 662 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 663 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 664 |
56 |
▶ | IV len = (lp && *lp) ? SvIV(*lp) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| IV len = (lp && *lp) ? SvIV(*lp) : 0; |
56 |
0 |
56 |
| IV len = (lp && *lp) ? SvIV(*lp) : 0; |
56 |
0 |
56 |
|
| 665 |
56 |
| SV *sub, *mapi, *firsthit = NULL; int mc; |
| 666 |
|
| /* |
| 667 |
|
| # uncoverable branch false |
| 668 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 669 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 670 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 671 |
112 |
▶ | if (pfp && *pfp && SvOK(*pfp)) pf = SvPV_const(*pfp, pfl); |
Branch: 3 branches
| Branch | True | False | Total |
| if (pfp && *pfp && SvOK(*pfp)) pf = SvPV_const(*pfp, pfl); |
56 |
0 |
56 |
| if (pfp && *pfp && SvOK(*pfp)) pf = SvPV_const(*pfp, pfl); |
56 |
0 |
56 |
| if (pfp && *pfp && SvOK(*pfp)) pf = SvPV_const(*pfp, pfl); |
56 |
0 |
56 |
|
| 672 |
0 |
| else { pf = ""; pfl = 0; } /* # uncoverable statement */ |
| 673 |
56 |
▶ | if (!(rpl >= pfl && memEQ(rps, pf, pfl))) continue; /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(rpl >= pfl && memEQ(rps, pf, pfl))) continue; /* # uncoverable condition left count:1 class:ignore_covered_err */ |
56 |
0 |
56 |
| if (!(rpl >= pfl && memEQ(rps, pf, pfl))) continue; /* # uncoverable condition left count:1 class:ignore_covered_err */ |
50 |
6 |
56 |
|
| 674 |
6 |
▶ | sub = sv_2mortal((rpl > (STRLEN)len) |
Branch: 1 branch
| Branch | True | False | Total |
| sub = sv_2mortal((rpl > (STRLEN)len) |
6 |
0 |
6 |
|
| 675 |
|
| ? newSVpvn(rps + len, rpl - len) |
| 676 |
|
| : newSVpvs("/")); |
| 677 |
|
| /* |
| 678 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 679 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 680 |
6 |
▶ | mapi = sv_2mortal(pcx_call_meth(aTHX_ (mmp && *mmp) ? *mmp |
Branch: 2 branches
| Branch | True | False | Total |
| mapi = sv_2mortal(pcx_call_meth(aTHX_ (mmp && *mmp) ? *mmp |
6 |
0 |
6 |
| mapi = sv_2mortal(pcx_call_meth(aTHX_ (mmp && *mmp) ? *mmp |
6 |
0 |
6 |
|
| 681 |
|
| : &PL_sv_undef, K_API, NULL, 0, 1)); |
| 682 |
|
| { |
| 683 |
6 |
| dSP; |
| 684 |
6 |
| ENTER; SAVETMPS; |
| 685 |
6 |
▶ | PUSHMARK(SP); EXTEND(SP, 3); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 3); |
0 |
6 |
6 |
| PUSHMARK(SP); EXTEND(SP, 3); |
0 |
6 |
6 |
|
| 686 |
6 |
| PUSHs(mapi); |
| 687 |
6 |
| PUSHs(sv_2mortal(newSVpvs("GET"))); |
| 688 |
6 |
| PUSHs(sub); |
| 689 |
6 |
| PUTBACK; |
| 690 |
6 |
| mc = call_method("match", G_ARRAY); |
| 691 |
6 |
| SPAGAIN; |
| 692 |
6 |
▶ | if (mc > 0) firsthit = SvREFCNT_inc(SP[-mc + 1]); |
Branch: 1 branch
| Branch | True | False | Total |
| if (mc > 0) firsthit = SvREFCNT_inc(SP[-mc + 1]); |
1 |
5 |
6 |
|
| 693 |
6 |
| SP -= mc; PUTBACK; |
| 694 |
6 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
6 |
0 |
6 |
|
| 695 |
|
| } |
| 696 |
6 |
▶ | if (mc > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mc > 0) { |
1 |
5 |
6 |
|
| 697 |
1 |
| SV *msg = sv_2mortal(newSVpvf( |
| 698 |
|
| "Punk: docs path '%.*s' is declared by the mounted " |
| 699 |
|
| "spec", (int)rpl, rps)); |
| 700 |
|
| /* |
| 701 |
|
| # uncoverable branch false |
| 702 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 703 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 704 |
1 |
▶ | if (firsthit && SvOK(firsthit)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (firsthit && SvOK(firsthit)) |
1 |
0 |
1 |
| if (firsthit && SvOK(firsthit)) |
1 |
0 |
1 |
|
| 705 |
1 |
| sv_catpvf(msg, " (operation '%s')", SvPV_nolen(firsthit)); |
| 706 |
1 |
| sv_catpvs(msg, "; choose another docs path"); |
| 707 |
|
| /* |
| 708 |
|
| # uncoverable branch false |
| 709 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 710 |
1 |
▶ | if (firsthit) SvREFCNT_dec(firsthit); |
Branch: 1 branch
| Branch | True | False | Total |
| if (firsthit) SvREFCNT_dec(firsthit); |
1 |
0 |
1 |
|
| 711 |
1 |
| croak("%s", SvPV_nolen(msg)); |
| 712 |
|
| } |
| 713 |
|
| /* |
| 714 |
|
| # uncoverable branch true |
| 715 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 716 |
5 |
▶ | if (firsthit) SvREFCNT_dec(firsthit); |
Branch: 1 branch
| Branch | True | False | Total |
| if (firsthit) SvREFCNT_dec(firsthit); |
0 |
5 |
5 |
|
| 717 |
|
| } |
| 718 |
50 |
| respp = hv_fetchs(r, K_RESPONSE, 0); |
| 719 |
50 |
| dcap = newAV(); |
| 720 |
|
| /* |
| 721 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 722 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 723 |
50 |
▶ | av_push(dcap, newSVsv((respp && *respp) ? *respp : &PL_sv_undef)); |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(dcap, newSVsv((respp && *respp) ? *respp : &PL_sv_undef)); |
50 |
0 |
50 |
| av_push(dcap, newSVsv((respp && *respp) ? *respp : &PL_sv_undef)); |
50 |
0 |
50 |
|
| 724 |
50 |
| target = punk_closure(aTHX_ pc_docs_cb, dcap); |
| 725 |
50 |
| route = newHV(); |
| 726 |
50 |
| (void)hv_stores(route, K_METHOD, newSVpvs("GET")); |
| 727 |
50 |
| (void)hv_stores(route, K_PATH, newSVsv(*rpathp)); |
| 728 |
50 |
| (void)hv_stores(route, K_TARGET, target); |
| 729 |
50 |
| (void)hv_stores(route, K_GUARDS, newRV_noinc((SV *)newAV())); |
| 730 |
50 |
| av_push(extra, newRV_noinc((SV *)route)); |
| 731 |
|
| } |
| 732 |
|
| } |
| 733 |
875 |
| return extra; |
| 734 |
|
| } |
| 735 |
|
| |
| 736 |
|
| /* ---- longest-prefix ordering ---------------------------------------------- */ |
| 737 |
|
| |
| 738 |
32 |
| static IV pc_len_of(pTHX_ SV *el) { |
| 739 |
|
| /* |
| 740 |
|
| # uncoverable branch false |
| 741 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 742 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 743 |
32 |
▶ | if (SvROK(el) && SvTYPE(SvRV(el)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(el) && SvTYPE(SvRV(el)) == SVt_PVHV) { |
32 |
0 |
32 |
| if (SvROK(el) && SvTYPE(SvRV(el)) == SVt_PVHV) { |
32 |
0 |
32 |
|
| 744 |
32 |
| SV **l = hv_fetchs((HV *)SvRV(el), K_LEN, 0); |
| 745 |
|
| /* |
| 746 |
|
| # uncoverable branch false |
| 747 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 748 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 749 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 750 |
32 |
▶ | if (l && *l && SvOK(*l)) return SvIV(*l); |
Branch: 3 branches
| Branch | True | False | Total |
| if (l && *l && SvOK(*l)) return SvIV(*l); |
32 |
0 |
32 |
| if (l && *l && SvOK(*l)) return SvIV(*l); |
32 |
0 |
32 |
| if (l && *l && SvOK(*l)) return SvIV(*l); |
32 |
0 |
32 |
|
| 751 |
|
| } |
| 752 |
0 |
| return 0; /* # uncoverable statement */ |
| 753 |
|
| } |
| 754 |
16 |
| static I32 pc_cmp_len_desc(pTHX_ SV *a, SV *b) { |
| 755 |
16 |
| return (I32)(pc_len_of(aTHX_ b) - pc_len_of(aTHX_ a)); |
| 756 |
|
| } |
| 757 |
|
| |
| 758 |
|
| /* ---- the nonblocking Future chain ($ret->then(done, fail)) ---------------- * |
| 759 |
|
| * capture [ $c, $on_error, $method, \@after ]; the deliver/handle-error work |
| 760 |
|
| * is punk_context.h / punk_serve.h C, exactly the blocking path's. */ |
| 761 |
|
| |
| 762 |
|
| /* $app->env - the config's env, else PUNK_ENV, else production. Mortal. */ |
| 763 |
146 |
| static SV *pc_app_env(pTHX_ SV *self) { |
| 764 |
146 |
| dSP; |
| 765 |
|
| int count; |
| 766 |
|
| SV *out; |
| 767 |
146 |
| ENTER; SAVETMPS; |
| 768 |
146 |
▶ | PUSHMARK(SP); EXTEND(SP, 1); PUSHs(self); PUTBACK; |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(self); PUTBACK; |
0 |
146 |
146 |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(self); PUTBACK; |
0 |
146 |
146 |
|
| 769 |
146 |
| count = call_method("env", G_SCALAR); |
| 770 |
146 |
| SPAGAIN; |
| 771 |
146 |
▶ | out = count > 0 ? newSVsv(POPs) : newSVpvs("production"); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| out = count > 0 ? newSVsv(POPs) : newSVpvs("production"); /* # uncoverable condition right count:1 class:ignore_covered_err */ |
146 |
0 |
146 |
|
| 772 |
146 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
146 |
0 |
146 |
|
| 773 |
146 |
| return sv_2mortal(out); |
| 774 |
|
| } |
| 775 |
|
| |
| 776 |
51 |
| static int pc_is_head(pTHX_ SV *methsv) { |
| 777 |
102 |
▶ | STRLEN ml; const char *m = SvOK(methsv) ? SvPV_const(methsv, ml) : "GET"; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| STRLEN ml; const char *m = SvOK(methsv) ? SvPV_const(methsv, ml) : "GET"; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
51 |
0 |
51 |
|
| 778 |
|
| /* |
| 779 |
|
| # uncoverable branch true |
| 780 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 781 |
51 |
▶ | if (!SvOK(methsv)) ml = 3; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(methsv)) ml = 3; |
0 |
51 |
51 |
|
| 782 |
51 |
▶ | return (ml == 4 && memEQ(m, "HEAD", 4)); /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| return (ml == 4 && memEQ(m, "HEAD", 4)); /* # uncoverable condition right count:2 class:ignore_covered_err */ |
1 |
50 |
51 |
| return (ml == 4 && memEQ(m, "HEAD", 4)); /* # uncoverable condition right count:2 class:ignore_covered_err */ |
1 |
0 |
1 |
|
| 783 |
|
| } |
| 784 |
51 |
| static AV *pc_after_of(pTHX_ SV *ref) { |
| 785 |
51 |
▶ | return (ref && SvROK(ref) && SvTYPE(SvRV(ref)) == SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| return (ref && SvROK(ref) && SvTYPE(SvRV(ref)) == SVt_PVAV) |
51 |
0 |
51 |
| return (ref && SvROK(ref) && SvTYPE(SvRV(ref)) == SVt_PVAV) |
51 |
0 |
51 |
|
| 786 |
102 |
▶ | ? (AV *)SvRV(ref) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (AV *)SvRV(ref) : NULL; |
51 |
0 |
51 |
|
| 787 |
|
| } |
| 788 |
|
| |
| 789 |
|
| /* A `then` callback must hand back a FUTURE, not the value it computed. |
| 790 |
|
| * Future's own sequencing enforces that - "Expected __ANON__(...) to return |
| 791 |
|
| * a Future" - and older releases enforce it strictly, so returning a raw |
| 792 |
|
| * triplet here fails on any perl whose Future predates the relaxation. |
| 793 |
|
| * Reported by CPAN Testers against 0.16 on perls 5.20, 5.22 and 5.24; it |
| 794 |
|
| * passed locally only because this box's Future no longer checks. |
| 795 |
|
| * |
| 796 |
|
| * The wrap is conditional because the two future flavours differ on this: |
| 797 |
|
| * `Future->done($v)` is a class method that mints a completed future, while |
| 798 |
|
| * Punk::Future's `done` is an instance method (its class-level constructor |
| 799 |
|
| * is done_future) and its own `then` accepts the value directly. So the |
| 800 |
|
| * capture carries a flag set at chain time from `$ret->isa('Future')`, and |
| 801 |
|
| * only that path is wrapped. Slot 4. */ |
| 802 |
8 |
| static int pc_ff_flag(pTHX_ AV *cap, int slot) { |
| 803 |
8 |
| SV **wp = av_fetch(cap, slot, 0); |
| 804 |
|
| /* |
| 805 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 806 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 807 |
8 |
▶ | return (wp && *wp && SvTRUE(*wp)) ? 1 : 0; |
Branch: 3 branches
| Branch | True | False | Total |
| return (wp && *wp && SvTRUE(*wp)) ? 1 : 0; |
8 |
0 |
8 |
| return (wp && *wp && SvTRUE(*wp)) ? 1 : 0; |
8 |
0 |
8 |
| return (wp && *wp && SvTRUE(*wp)) ? 1 : 0; |
6 |
2 |
8 |
|
| 808 |
|
| } |
| 809 |
|
| |
| 810 |
6 |
| static SV *pc_ff_wrap(pTHX_ int wrap, SV *resp) { |
| 811 |
|
| SV *argv[1], *f; |
| 812 |
|
| /* |
| 813 |
|
| # uncoverable branch true |
| 814 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 815 |
6 |
▶ | if (!wrap) return resp; /* Punk::Future path */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!wrap) return resp; /* Punk::Future path */ |
0 |
6 |
6 |
|
| 816 |
6 |
| argv[0] = sv_2mortal(resp); |
| 817 |
6 |
| f = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs("Future")), "done", argv, 1, 1); |
| 818 |
6 |
▶ | return f ? f : newSVsv(argv[0]); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| return f ? f : newSVsv(argv[0]); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
0 |
6 |
6 |
|
| 819 |
|
| } |
| 820 |
|
| |
| 821 |
|
| /* The streaming callbacks answer through the responder and have no value to |
| 822 |
|
| * carry, but they are still `then` callbacks and still owe a future back. */ |
| 823 |
|
| /* |
| 824 |
|
| # uncoverable statement |
| 825 |
|
| # uncoverable subroutine */ |
| 826 |
0 |
| static SV *pc_ff_done_empty(pTHX) { |
| 827 |
0 |
| SV *f = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs("Future")), "done", /* # uncoverable statement */ |
| 828 |
|
| NULL, 0, 1); |
| 829 |
|
| /* |
| 830 |
|
| # uncoverable statement |
| 831 |
|
| # uncoverable condition left count:1 |
| 832 |
|
| # uncoverable condition right count:1 */ |
| 833 |
0 |
▶ | return f ? f : newSV(0); |
Branch: 1 branch
| Branch | True | False | Total |
| return f ? f : newSV(0); |
0 |
0 |
0 |
|
| 834 |
|
| } |
| 835 |
|
| |
| 836 |
|
| XS_INTERNAL(pc_ff_done_cb); |
| 837 |
4 |
| XS_INTERNAL(pc_ff_done_cb) { |
| 838 |
4 |
| dXSARGS; |
| 839 |
4 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 840 |
4 |
| SV *c = *av_fetch(cap, 0, 0); |
| 841 |
4 |
| int hd = pc_is_head(aTHX_ *av_fetch(cap, 2, 0)); |
| 842 |
4 |
| AV *aft = pc_after_of(aTHX_ *av_fetch(cap, 3, 0)); |
| 843 |
4 |
▶ | SV *val = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *val = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
4 |
0 |
4 |
|
| 844 |
4 |
| ST(0) = sv_2mortal(pc_ff_wrap(aTHX_ pc_ff_flag(aTHX_ cap, 4), |
| 845 |
|
| punk_deliver(aTHX_ c, val, hd, aft))); |
| 846 |
4 |
| XSRETURN(1); |
| 847 |
|
| } |
| 848 |
|
| |
| 849 |
|
| /* The Punk::Future path, fused. |
| 850 |
|
| * |
| 851 |
|
| * Chaining a handler's future through `then` builds three closures per |
| 852 |
|
| * request: a done callback, a fail callback, and the one `then` makes inside |
| 853 |
|
| * itself to drive the derived future. Each is a fresh CV - punk_closure is |
| 854 |
|
| * newXS - plus a capture AV. When the handler's future is one of ours none of |
| 855 |
|
| * that indirection buys anything: this is a single reaction that reads the |
| 856 |
|
| * settled state itself and settles the derived future directly, so one |
| 857 |
|
| * closure and one AV do the work of three. |
| 858 |
|
| * |
| 859 |
|
| * Capture: [ c, on_error, method, after, derived ]. No wrap flag - the wrap |
| 860 |
|
| * exists to satisfy CPAN Future's "a then callback must return a Future" |
| 861 |
|
| * rule, and nothing here goes through `then`. |
| 862 |
|
| * |
| 863 |
|
| * The source future arrives as $_[0], which is what PFR_ON_READY passes. */ |
| 864 |
|
| XS_INTERNAL(pc_ff_both_cb); |
| 865 |
6 |
| XS_INTERNAL(pc_ff_both_cb) { |
| 866 |
6 |
| dXSARGS; |
| 867 |
6 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 868 |
6 |
| SV *c = *av_fetch(cap, 0, 0); |
| 869 |
6 |
| SV *oe = *av_fetch(cap, 1, 0); |
| 870 |
6 |
| int hd = pc_is_head(aTHX_ *av_fetch(cap, 2, 0)); |
| 871 |
6 |
| AV *aft = pc_after_of(aTHX_ *av_fetch(cap, 3, 0)); |
| 872 |
6 |
| SV *derived = *av_fetch(cap, 4, 0); |
| 873 |
6 |
▶ | SV *src = items > 0 ? ST(0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *src = items > 0 ? ST(0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
6 |
0 |
6 |
|
| 874 |
6 |
▶ | punk_future *sf = src ? pf_of(aTHX_ src) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| punk_future *sf = src ? pf_of(aTHX_ src) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
6 |
0 |
6 |
|
| 875 |
|
| SV *resp; |
| 876 |
|
| /* |
| 877 |
|
| # uncoverable branch true |
| 878 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 879 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 880 |
6 |
▶ | if (!sf || !derived) XSRETURN_EMPTY; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sf || !derived) XSRETURN_EMPTY; |
6 |
0 |
6 |
| if (!sf || !derived) XSRETURN_EMPTY; |
0 |
6 |
6 |
|
| 881 |
|
| /* |
| 882 |
|
| # uncoverable branch false |
| 883 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 884 |
6 |
▶ | if (sf->state == PF_DONE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sf->state == PF_DONE) { |
6 |
0 |
6 |
|
| 885 |
6 |
▶ | SV **v = sf->vals ? av_fetch(sf->vals, 0, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV **v = sf->vals ? av_fetch(sf->vals, 0, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
6 |
0 |
6 |
|
| 886 |
|
| /* |
| 887 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 888 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 889 |
6 |
▶ | resp = punk_deliver(aTHX_ c, v && *v ? *v : &PL_sv_undef, hd, aft); |
Branch: 2 branches
| Branch | True | False | Total |
| resp = punk_deliver(aTHX_ c, v && *v ? *v : &PL_sv_undef, hd, aft); |
6 |
0 |
6 |
| resp = punk_deliver(aTHX_ c, v && *v ? *v : &PL_sv_undef, hd, aft); |
6 |
0 |
6 |
|
| 890 |
|
| } |
| 891 |
|
| /* |
| 892 |
|
| # uncoverable statement |
| 893 |
|
| # uncoverable branch true |
| 894 |
|
| # uncoverable branch false |
| 895 |
|
| # uncoverable condition left count:1 |
| 896 |
|
| # uncoverable condition right count:1 */ |
| 897 |
0 |
▶ | else if (sf->state == PF_FAILED) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (sf->state == PF_FAILED) { |
0 |
0 |
0 |
|
| 898 |
|
| /* |
| 899 |
|
| # uncoverable statement |
| 900 |
|
| # uncoverable condition left count:1 |
| 901 |
|
| # uncoverable condition right count:1 */ |
| 902 |
0 |
▶ | SV **e = sf->vals ? av_fetch(sf->vals, 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **e = sf->vals ? av_fetch(sf->vals, 0, 0) : NULL; |
0 |
0 |
0 |
|
| 903 |
|
| /* |
| 904 |
|
| # uncoverable statement |
| 905 |
|
| # uncoverable condition left count:1 |
| 906 |
|
| # uncoverable condition right count:1 |
| 907 |
|
| # uncoverable condition left count:2 |
| 908 |
|
| # uncoverable condition right count:2 |
| 909 |
|
| # uncoverable condition left count:3 |
| 910 |
|
| # uncoverable condition right count:3 */ |
| 911 |
0 |
▶ | SV *err = (e && *e && SvOK(*e)) ? *e : sv_2mortal(newSVpvs("failed")); |
Branch: 3 branches
| Branch | True | False | Total |
| SV *err = (e && *e && SvOK(*e)) ? *e : sv_2mortal(newSVpvs("failed")); |
0 |
0 |
0 |
| SV *err = (e && *e && SvOK(*e)) ? *e : sv_2mortal(newSVpvs("failed")); |
0 |
0 |
0 |
| SV *err = (e && *e && SvOK(*e)) ? *e : sv_2mortal(newSVpvs("failed")); |
0 |
0 |
0 |
|
| 912 |
|
| /* |
| 913 |
|
| # uncoverable statement |
| 914 |
|
| # uncoverable condition left count:1 |
| 915 |
|
| # uncoverable condition right count:1 */ |
| 916 |
0 |
▶ | SV *handled = punk_handle_error(aTHX_ c, err, SvOK(oe) ? oe : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *handled = punk_handle_error(aTHX_ c, err, SvOK(oe) ? oe : NULL); |
0 |
0 |
0 |
|
| 917 |
0 |
| resp = punk_deliver(aTHX_ c, handled, hd, aft); /* # uncoverable statement */ |
| 918 |
0 |
| SvREFCNT_dec(handled); /* # uncoverable statement */ |
| 919 |
|
| } |
| 920 |
|
| else { /* cancelled: nothing was asked for, so nothing is delivered */ |
| 921 |
0 |
| pf_settle(aTHX_ pf_of(aTHX_ derived), derived, PF_CANCELLED, NULL); /* # uncoverable statement */ |
| 922 |
0 |
| XSRETURN_EMPTY; /* # uncoverable statement */ |
| 923 |
|
| } |
| 924 |
|
| { |
| 925 |
6 |
| AV *out = newAV(); |
| 926 |
6 |
| av_push(out, resp); /* takes the reference punk_deliver made */ |
| 927 |
6 |
| pf_settle(aTHX_ pf_of(aTHX_ derived), derived, PF_DONE, out); |
| 928 |
|
| } |
| 929 |
6 |
| XSRETURN_EMPTY; |
| 930 |
|
| } |
| 931 |
|
| |
| 932 |
|
| XS_INTERNAL(pc_ff_fail_cb); |
| 933 |
2 |
| XS_INTERNAL(pc_ff_fail_cb) { |
| 934 |
2 |
| dXSARGS; |
| 935 |
2 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 936 |
2 |
| SV *c = *av_fetch(cap, 0, 0); |
| 937 |
2 |
| SV *oe = *av_fetch(cap, 1, 0); |
| 938 |
2 |
| int hd = pc_is_head(aTHX_ *av_fetch(cap, 2, 0)); |
| 939 |
2 |
| AV *aft = pc_after_of(aTHX_ *av_fetch(cap, 3, 0)); |
| 940 |
|
| /* |
| 941 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 942 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 943 |
2 |
▶ | SV *err = (items > 0 && SvOK(ST(0))) ? ST(0) : sv_2mortal(newSVpvs("failed")); |
Branch: 2 branches
| Branch | True | False | Total |
| SV *err = (items > 0 && SvOK(ST(0))) ? ST(0) : sv_2mortal(newSVpvs("failed")); |
2 |
0 |
2 |
| SV *err = (items > 0 && SvOK(ST(0))) ? ST(0) : sv_2mortal(newSVpvs("failed")); |
2 |
0 |
2 |
|
| 944 |
2 |
▶ | SV *resp = punk_handle_error(aTHX_ c, err, SvOK(oe) ? oe : NULL); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *resp = punk_handle_error(aTHX_ c, err, SvOK(oe) ? oe : NULL); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
0 |
2 |
2 |
|
| 945 |
|
| /* the same contract as the done side: a `then` callback returns a |
| 946 |
|
| * future, not the value. A failure that answers with a 500 triplet is |
| 947 |
|
| * still a SUCCESSFUL sequencing step - the error was handled - so this |
| 948 |
|
| * wraps with done, not fail. */ |
| 949 |
2 |
| ST(0) = sv_2mortal(pc_ff_wrap(aTHX_ pc_ff_flag(aTHX_ cap, 4), |
| 950 |
|
| punk_deliver(aTHX_ c, resp, hd, aft))); |
| 951 |
2 |
| SvREFCNT_dec(resp); |
| 952 |
2 |
| XSRETURN(1); |
| 953 |
|
| } |
| 954 |
|
| |
| 955 |
|
| /* ---- the streaming variant: a Future behind a psgi.streaming responder ---- |
| 956 |
|
| * |
| 957 |
|
| * A raw Future handed back as the PSGI response is a shape only Hyperman |
| 958 |
|
| * understands, and anything standing between Punk and the server - the Lint |
| 959 |
|
| * and AccessLog middleware plackup adds in its development default, or this |
| 960 |
|
| * application's own `middleware` - dies on it. When the server advertises |
| 961 |
|
| * psgi.streaming, the future rides inside the standard delayed response |
| 962 |
|
| * instead: a coderef every middleware passes through, resolving to the same |
| 963 |
|
| * triplet through the same deliver path. */ |
| 964 |
|
| |
| 965 |
|
| /* Hand `resp` to the responder - or, when the future resolved to a streaming |
| 966 |
|
| * coderef of its own (an SSE body, say), hand the responder to it. */ |
| 967 |
8 |
| static void pc_respond(pTHX_ SV *responder, SV *resp) { |
| 968 |
8 |
| dSP; |
| 969 |
|
| /* |
| 970 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 971 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 972 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 973 |
8 |
▶ | int stream = SvROK(resp) && SvTYPE(SvRV(resp)) == SVt_PVCV; |
Branch: 2 branches
| Branch | True | False | Total |
| int stream = SvROK(resp) && SvTYPE(SvRV(resp)) == SVt_PVCV; |
8 |
0 |
8 |
| int stream = SvROK(resp) && SvTYPE(SvRV(resp)) == SVt_PVCV; |
0 |
8 |
8 |
|
| 974 |
8 |
| ENTER; SAVETMPS; |
| 975 |
8 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
8 |
8 |
|
| 976 |
|
| /* |
| 977 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 978 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 979 |
8 |
▶ | XPUSHs(stream ? responder : resp); |
Branch: 2 branches
| Branch | True | False | Total |
| XPUSHs(stream ? responder : resp); |
0 |
8 |
8 |
| XPUSHs(stream ? responder : resp); |
0 |
8 |
8 |
|
| 980 |
8 |
| PUTBACK; |
| 981 |
8 |
▶ | call_sv(stream ? resp : responder, G_VOID | G_DISCARD | G_EVAL); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| call_sv(stream ? resp : responder, G_VOID | G_DISCARD | G_EVAL); /* # uncoverable condition left count:1 class:ignore_covered_err */ |
0 |
8 |
8 |
|
| 982 |
|
| /* |
| 983 |
|
| # uncoverable branch true |
| 984 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 985 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 986 |
8 |
▶ | if (SvTRUE(ERRSV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) |
8 |
0 |
8 |
| if (SvTRUE(ERRSV)) |
0 |
8 |
8 |
|
| 987 |
0 |
▶ | warn("Punk: responder failed: %" SVf, SVfARG(ERRSV)); /* # uncoverable statement */ |
Branch: 1 branch
| Branch | True | False | Total |
| warn("Punk: responder failed: %" SVf, SVfARG(ERRSV)); /* # uncoverable statement */ |
0 |
0 |
0 |
|
| 988 |
8 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
0 |
8 |
8 |
|
| 989 |
8 |
| } |
| 990 |
|
| |
| 991 |
|
| /* cap: [c, on_error, method, after, responder] - the pc_ff_* layout plus the |
| 992 |
|
| * responder the server handed the delayed response. */ |
| 993 |
|
| XS_INTERNAL(pc_ffs_done_cb); |
| 994 |
2 |
| XS_INTERNAL(pc_ffs_done_cb) { |
| 995 |
2 |
| dXSARGS; |
| 996 |
2 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 997 |
2 |
| SV *c = *av_fetch(cap, 0, 0); |
| 998 |
2 |
| int hd = pc_is_head(aTHX_ *av_fetch(cap, 2, 0)); |
| 999 |
2 |
| AV *aft = pc_after_of(aTHX_ *av_fetch(cap, 3, 0)); |
| 1000 |
2 |
| SV *rsp = *av_fetch(cap, 4, 0); |
| 1001 |
2 |
▶ | SV *val = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *val = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
2 |
0 |
2 |
|
| 1002 |
2 |
| SV *trip = punk_deliver(aTHX_ c, val, hd, aft); |
| 1003 |
2 |
| pc_respond(aTHX_ rsp, trip); |
| 1004 |
2 |
| SvREFCNT_dec(trip); |
| 1005 |
|
| /* |
| 1006 |
|
| # uncoverable branch true |
| 1007 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 1008 |
2 |
▶ | if (pc_ff_flag(aTHX_ cap, 5)) { ST(0) = sv_2mortal(pc_ff_done_empty(aTHX)); XSRETURN(1); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (pc_ff_flag(aTHX_ cap, 5)) { ST(0) = sv_2mortal(pc_ff_done_empty(aTHX)); XSRETURN(1); } |
0 |
2 |
2 |
|
| 1009 |
2 |
| XSRETURN(0); |
| 1010 |
|
| } |
| 1011 |
|
| |
| 1012 |
|
| XS_INTERNAL(pc_ffs_fail_cb); |
| 1013 |
|
| /* |
| 1014 |
|
| # uncoverable statement |
| 1015 |
|
| # uncoverable subroutine */ |
| 1016 |
0 |
| XS_INTERNAL(pc_ffs_fail_cb) { |
| 1017 |
0 |
| dXSARGS; /* # uncoverable statement */ |
| 1018 |
0 |
| AV *cap = punk_clos_cap(aTHX_ cv); /* # uncoverable statement */ |
| 1019 |
0 |
| SV *c = *av_fetch(cap, 0, 0); /* # uncoverable statement */ |
| 1020 |
0 |
| SV *oe = *av_fetch(cap, 1, 0); /* # uncoverable statement */ |
| 1021 |
0 |
| int hd = pc_is_head(aTHX_ *av_fetch(cap, 2, 0)); /* # uncoverable statement */ |
| 1022 |
0 |
| AV *aft = pc_after_of(aTHX_ *av_fetch(cap, 3, 0)); /* # uncoverable statement */ |
| 1023 |
0 |
| SV *rsp = *av_fetch(cap, 4, 0); /* # uncoverable statement */ |
| 1024 |
|
| /* |
| 1025 |
|
| # uncoverable statement |
| 1026 |
|
| # uncoverable condition left count:1 |
| 1027 |
|
| # uncoverable condition right count:1 |
| 1028 |
|
| # uncoverable condition left count:2 |
| 1029 |
|
| # uncoverable condition right count:2 */ |
| 1030 |
0 |
▶ | SV *err = (items > 0 && SvOK(ST(0))) ? ST(0) : sv_2mortal(newSVpvs("failed")); |
Branch: 2 branches
| Branch | True | False | Total |
| SV *err = (items > 0 && SvOK(ST(0))) ? ST(0) : sv_2mortal(newSVpvs("failed")); |
0 |
0 |
0 |
| SV *err = (items > 0 && SvOK(ST(0))) ? ST(0) : sv_2mortal(newSVpvs("failed")); |
0 |
0 |
0 |
|
| 1031 |
|
| /* |
| 1032 |
|
| # uncoverable statement |
| 1033 |
|
| # uncoverable condition left count:1 |
| 1034 |
|
| # uncoverable condition right count:1 */ |
| 1035 |
0 |
▶ | SV *resp = punk_handle_error(aTHX_ c, err, SvOK(oe) ? oe : NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *resp = punk_handle_error(aTHX_ c, err, SvOK(oe) ? oe : NULL); |
0 |
0 |
0 |
|
| 1036 |
0 |
| SV *trip = punk_deliver(aTHX_ c, resp, hd, aft); /* # uncoverable statement */ |
| 1037 |
0 |
| pc_respond(aTHX_ rsp, trip); /* # uncoverable statement */ |
| 1038 |
0 |
| SvREFCNT_dec(trip); /* # uncoverable statement */ |
| 1039 |
0 |
| SvREFCNT_dec(resp); /* # uncoverable statement */ |
| 1040 |
|
| /* |
| 1041 |
|
| # uncoverable statement |
| 1042 |
|
| # uncoverable branch true |
| 1043 |
|
| # uncoverable branch false |
| 1044 |
|
| # uncoverable condition left count:1 |
| 1045 |
|
| # uncoverable condition right count:1 */ |
| 1046 |
0 |
▶ | if (pc_ff_flag(aTHX_ cap, 5)) { ST(0) = sv_2mortal(pc_ff_done_empty(aTHX)); XSRETURN(1); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (pc_ff_flag(aTHX_ cap, 5)) { ST(0) = sv_2mortal(pc_ff_done_empty(aTHX)); XSRETURN(1); } |
0 |
0 |
0 |
|
| 1047 |
0 |
| XSRETURN(0); /* # uncoverable statement */ |
| 1048 |
|
| } |
| 1049 |
|
| |
| 1050 |
|
| /* The delayed response itself. cap: [c, ret, on_error, method, after]; |
| 1051 |
|
| * called by the server (or the innermost middleware) with the responder. |
| 1052 |
|
| * |
| 1053 |
|
| * On a live Hyperman worker loop the then-chain is enough - the loop is what |
| 1054 |
|
| * resolves the future, and the responder fires when it does. Without one |
| 1055 |
|
| * (a foreign nonblocking server, a synthetic test env) nothing would ever |
| 1056 |
|
| * drive a pending future, so it is awaited inline - the same semantics the |
| 1057 |
|
| * blocking branch has always had, delivered through the responder. */ |
| 1058 |
|
| XS_INTERNAL(pc_ffs_cb); |
| 1059 |
8 |
| XS_INTERNAL(pc_ffs_cb) { |
| 1060 |
8 |
| dXSARGS; |
| 1061 |
8 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 1062 |
8 |
| SV *c = *av_fetch(cap, 0, 0); |
| 1063 |
8 |
| SV *ret = *av_fetch(cap, 1, 0); |
| 1064 |
8 |
▶ | SV *responder = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *responder = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
8 |
0 |
8 |
|
| 1065 |
8 |
| const hm_abi *A = punk_hm(aTHX); |
| 1066 |
|
| /* |
| 1067 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 1068 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 1069 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 1070 |
8 |
▶ | int ffs_wrap = (SvROK(ret) && sv_derived_from(ret, "Future")); |
Branch: 2 branches
| Branch | True | False | Total |
| int ffs_wrap = (SvROK(ret) && sv_derived_from(ret, "Future")); |
8 |
0 |
8 |
| int ffs_wrap = (SvROK(ret) && sv_derived_from(ret, "Future")); |
0 |
8 |
8 |
|
| 1071 |
10 |
▶ | if (A && A->cur_loop(aTHX)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (A && A->cur_loop(aTHX)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
8 |
0 |
8 |
| if (A && A->cur_loop(aTHX)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ |
2 |
6 |
8 |
|
| 1072 |
|
| SV *done, *fail, *argv[2], *chained; |
| 1073 |
|
| AV *caps[2]; |
| 1074 |
|
| int j; |
| 1075 |
6 |
▶ | for (j = 0; j < 2; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < 2; j++) { |
4 |
2 |
6 |
|
| 1076 |
4 |
| AV *icap = caps[j] = newAV(); |
| 1077 |
4 |
| SV **oe = av_fetch(cap, 2, 0), **af = av_fetch(cap, 4, 0); |
| 1078 |
4 |
| av_push(icap, newSVsv(c)); |
| 1079 |
|
| /* |
| 1080 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 1081 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 1082 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 1083 |
4 |
▶ | av_push(icap, (oe && SvOK(*oe)) ? newSVsv(*oe) : newSV(0)); |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(icap, (oe && SvOK(*oe)) ? newSVsv(*oe) : newSV(0)); |
4 |
0 |
4 |
| av_push(icap, (oe && SvOK(*oe)) ? newSVsv(*oe) : newSV(0)); |
0 |
4 |
4 |
|
| 1084 |
4 |
| av_push(icap, newSVsv(*av_fetch(cap, 3, 0))); |
| 1085 |
|
| /* |
| 1086 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 1087 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 1088 |
4 |
▶ | av_push(icap, (af && SvOK(*af)) ? newSVsv(*af) |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(icap, (af && SvOK(*af)) ? newSVsv(*af) |
4 |
0 |
4 |
| av_push(icap, (af && SvOK(*af)) ? newSVsv(*af) |
4 |
0 |
4 |
|
| 1089 |
|
| : newRV_noinc((SV *)newAV())); |
| 1090 |
4 |
| av_push(icap, newSVsv(responder)); |
| 1091 |
4 |
| av_push(icap, newSViv(ffs_wrap)); |
| 1092 |
|
| } |
| 1093 |
2 |
| done = sv_2mortal(punk_closure(aTHX_ pc_ffs_done_cb, caps[0])); |
| 1094 |
2 |
| fail = sv_2mortal(punk_closure(aTHX_ pc_ffs_fail_cb, caps[1])); |
| 1095 |
2 |
| argv[0] = done; argv[1] = fail; |
| 1096 |
2 |
| chained = pcx_call_meth(aTHX_ ret, "then", argv, 2, 1); |
| 1097 |
|
| /* the pending chain is held by what will resolve it */ |
| 1098 |
|
| /* |
| 1099 |
|
| # uncoverable branch false |
| 1100 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 1101 |
2 |
▶ | if (chained) SvREFCNT_dec(chained); |
Branch: 1 branch
| Branch | True | False | Total |
| if (chained) SvREFCNT_dec(chained); |
2 |
0 |
2 |
|
| 1102 |
|
| } |
| 1103 |
|
| else { |
| 1104 |
6 |
| dSP; int count, died, hd; |
| 1105 |
|
| SV *got, *resp, *trip; |
| 1106 |
6 |
| SV **oe = av_fetch(cap, 2, 0); |
| 1107 |
6 |
| AV *aft = pc_after_of(aTHX_ *av_fetch(cap, 4, 0)); |
| 1108 |
6 |
| ENTER; SAVETMPS; |
| 1109 |
6 |
▶ | PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ret); PUTBACK; |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ret); PUTBACK; |
0 |
6 |
6 |
| PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ret); PUTBACK; |
0 |
6 |
6 |
|
| 1110 |
6 |
| count = call_method("get", G_SCALAR | G_EVAL); |
| 1111 |
6 |
| SPAGAIN; |
| 1112 |
6 |
▶ | got = count > 0 ? SvREFCNT_inc(POPs) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| got = count > 0 ? SvREFCNT_inc(POPs) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
6 |
0 |
6 |
|
| 1113 |
6 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
6 |
0 |
6 |
|
| 1114 |
6 |
▶ | died = SvTRUE(ERRSV) ? 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| died = SvTRUE(ERRSV) ? 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
6 |
0 |
6 |
|
| 1115 |
6 |
| hd = pc_is_head(aTHX_ *av_fetch(cap, 3, 0)); |
| 1116 |
4 |
▶ | resp = died ? punk_handle_error(aTHX_ c, ERRSV, /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| resp = died ? punk_handle_error(aTHX_ c, ERRSV, /* # uncoverable condition right count:1 class:ignore_covered_err */ |
2 |
0 |
2 |
| resp = died ? punk_handle_error(aTHX_ c, ERRSV, /* # uncoverable condition right count:1 class:ignore_covered_err */ |
2 |
0 |
2 |
|
| 1117 |
2 |
▶ | (oe && SvOK(*oe)) ? *oe : NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| (oe && SvOK(*oe)) ? *oe : NULL) |
0 |
2 |
2 |
|
| 1118 |
6 |
▶ | : punk_coerce(aTHX_ c, got); |
Branch: 1 branch
| Branch | True | False | Total |
| : punk_coerce(aTHX_ c, got); |
2 |
4 |
6 |
|
| 1119 |
6 |
| trip = punk_deliver(aTHX_ c, resp, hd, aft); |
| 1120 |
6 |
| pc_respond(aTHX_ responder, trip); |
| 1121 |
6 |
| SvREFCNT_dec(trip); |
| 1122 |
6 |
| SvREFCNT_dec(resp); |
| 1123 |
6 |
▶ | if (got != &PL_sv_undef) SvREFCNT_dec(got); |
Branch: 1 branch
| Branch | True | False | Total |
| if (got != &PL_sv_undef) SvREFCNT_dec(got); |
4 |
2 |
6 |
|
| 1124 |
|
| } |
| 1125 |
8 |
| XSRETURN(0); |
| 1126 |
|
| } |
| 1127 |
|
| |
| 1128 |
|
| #endif /* PUNK_COMPILE_H */ |