include/punk/pk_abi_impl.h

filter: Statementstmt 100% 39 / 39 Branchbran 58.0% 35 / 62 (5 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.2% 74 / 101 (5 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/password.xs ↑ Summary xs/dbi.xs »
1 /* pk_abi_impl.h - Punk's side of its public C ABI (pk_abi.h).
2 *
3 * Included by Punk.xs AFTER punk_context.h (the PCX_* slot layout) and
4 * punk_obs.h (the observer registry). Everything here is private to Punk's
5 * translation unit; a consumer reaches it only through the PK_ABI table
6 * returned by Punk::_abi_ptr.
7 */
8  
9 #ifndef PK_ABI_IMPL_H
10 #define PK_ABI_IMPL_H
11  
12 #include "pk_abi.h"
13  
14 /* A context's AV, or NULL for anything that is not one. The whole table has
15 * to be safe to call on a value the consumer only thinks is a context, so
16 * this never croaks the way pcx_av does. */
17 1451 static AV *pk_abi_av(pTHX_ SV *c) {
18 PERL_UNUSED_CONTEXT;
19 /*
20 # uncoverable branch true
21 # uncoverable condition left count:1 class:ignore_covered_err
22 # uncoverable condition left count:2 class:ignore_covered_err
23 # uncoverable condition left count:3 class:ignore_covered_err */
24 1451 ▶ if (!c || !SvROK(c) || SvTYPE(SvRV(c)) != SVt_PVAV) return NULL;
Branch: 3 branches
BranchTrueFalseTotal
if (!c || !SvROK(c) || SvTYPE(SvRV(c)) != SVt_PVAV) return NULL; 1451 0 1451
if (!c || !SvROK(c) || SvTYPE(SvRV(c)) != SVt_PVAV) return NULL; 1451 0 1451
if (!c || !SvROK(c) || SvTYPE(SvRV(c)) != SVt_PVAV) return NULL; 0 1451 1451
25 1451 return (AV *)SvRV(c);
26 }
27  
28 /* One slot, borrowed; NULL when absent or undef. */
29 1403 static SV *pk_abi_slot(pTHX_ SV *c, SSize_t i) {
30 1403 AV *av = pk_abi_av(aTHX_ c);
31 1403 ▶ SV **e = av ? av_fetch(av, i, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SV **e = av ? av_fetch(av, i, 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 1403 0 1403
32 /*
33 # uncoverable condition right count:1 class:ignore_covered_err
34 # uncoverable condition right count:2 class:ignore_covered_err
35 # uncoverable condition right count:3 class:ignore_covered_err */
36 1403 ▶ return (e && *e && SvOK(*e)) ? *e : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return (e && *e && SvOK(*e)) ? *e : NULL; 1403 0 1403
return (e && *e && SvOK(*e)) ? *e : NULL; 1403 0 1403
return (e && *e && SvOK(*e)) ? *e : NULL; 1403 0 1403
37 }
38  
39 677 static SV *pk_abi_env_of(pTHX_ SV *c) { return pk_abi_slot(aTHX_ c, PCX_ENV); }
40 48 static SV *pk_abi_app_of(pTHX_ SV *c) { return pk_abi_slot(aTHX_ c, PCX_APP); }
41 678 static SV *pk_abi_match_of(pTHX_ SV *c) { return pk_abi_slot(aTHX_ c, PCX_MATCH); }
42  
43 /* The stash, created on first ask. A consumer's first act is normally to
44 * leave something for the response side to find, and it should not have to
45 * know the slot layout to do it. */
46 48 static SV *pk_abi_stash_of(pTHX_ SV *c) {
47 48 AV *av = pk_abi_av(aTHX_ c);
48 SV *st;
49 /*
50 # uncoverable branch true
51 # uncoverable condition left count:1 class:ignore_covered_err */
52 48 ▶ if (!av) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!av) return NULL; 0 48 48
53 48 st = pcx_get(aTHX_ av, PCX_STASH);
54 48 ▶ if (!st) {
Branch: 1 branch
BranchTrueFalseTotal
if (!st) { 24 24 48
55 24 st = newRV_noinc((SV *)newHV());
56 /*
57 # uncoverable branch true
58 # uncoverable condition left count:1 class:ignore_covered_err */
59 24 ▶ if (!av_store(av, PCX_STASH, st)) { SvREFCNT_dec(st); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!av_store(av, PCX_STASH, st)) { SvREFCNT_dec(st); return NULL; } 0 24 24
60 }
61 48 return st;
62 }
63  
64 /* The match hash, or NULL. */
65 630 static HV *pk_abi_match_hv(pTHX_ SV *c) {
66 630 SV *m = pk_abi_match_of(aTHX_ c);
67 /*
68 # uncoverable branch true
69 # uncoverable condition left count:1 class:ignore_covered_err
70 # uncoverable condition left count:2 class:ignore_covered_err
71 # uncoverable condition left count:3 class:ignore_covered_err */
72 630 ▶ if (!(m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV)) return NULL;
Branch: 3 branches
BranchTrueFalseTotal
if (!(m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV)) return NULL; 630 0 630
if (!(m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV)) return NULL; 630 0 630
if (!(m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV)) return NULL; 0 630 630
73 630 return (HV *)SvRV(m);
74 }
75  
76 /* The declared route path, through the route record the dispatcher stores in
77 * the match. NULL whenever there is no matched route to name, which includes
78 * every request-start callback: routing has not happened yet. */
79 350 static SV *pk_abi_route_pattern_of(pTHX_ SV *c) {
80 350 HV *mh = pk_abi_match_hv(aTHX_ c);
81 SV **r, **p;
82 /*
83 # uncoverable branch true
84 # uncoverable condition left count:1 class:ignore_covered_err */
85 350 ▶ if (!mh) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!mh) return NULL; 0 350 350
86 350 r = hv_fetchs(mh, "route", 0);
87 /*
88 # uncoverable condition left count:2 class:ignore_covered_err
89 # uncoverable condition left count:3 class:ignore_covered_err
90 # uncoverable condition left count:4 class:ignore_covered_err */
91 350 ▶ if (!(r && *r && SvROK(*r) && SvTYPE(SvRV(*r)) == SVt_PVHV)) return NULL;
Branch: 4 branches
BranchTrueFalseTotal
if (!(r && *r && SvROK(*r) && SvTYPE(SvRV(*r)) == SVt_PVHV)) return NULL; 86 264 350
if (!(r && *r && SvROK(*r) && SvTYPE(SvRV(*r)) == SVt_PVHV)) return NULL; 86 0 86
if (!(r && *r && SvROK(*r) && SvTYPE(SvRV(*r)) == SVt_PVHV)) return NULL; 86 0 86
if (!(r && *r && SvROK(*r) && SvTYPE(SvRV(*r)) == SVt_PVHV)) return NULL; 0 86 86
92 86 p = hv_fetchs((HV *)SvRV(*r), K_PATH, 0);
93 /*
94 # uncoverable condition right count:1 class:ignore_covered_err
95 # uncoverable condition right count:2 class:ignore_covered_err
96 # uncoverable condition right count:3 class:ignore_covered_err */
97 86 ▶ return (p && *p && SvOK(*p)) ? *p : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return (p && *p && SvOK(*p)) ? *p : NULL; 86 0 86
return (p && *p && SvOK(*p)) ? *p : NULL; 86 0 86
return (p && *p && SvOK(*p)) ? *p : NULL; 86 0 86
98 }
99  
100 280 static SV *pk_abi_operation_of(pTHX_ SV *c) {
101 280 HV *mh = pk_abi_match_hv(aTHX_ c);
102 280 ▶ SV **o = mh ? hv_fetchs(mh, "operation", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SV **o = mh ? hv_fetchs(mh, "operation", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 280 0 280
103 /*
104 # uncoverable condition right count:2 class:ignore_covered_err
105 # uncoverable condition right count:3 class:ignore_covered_err */
106 280 ▶ return (o && *o && SvOK(*o)) ? *o : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return (o && *o && SvOK(*o)) ? *o : NULL; 2 278 280
return (o && *o && SvOK(*o)) ? *o : NULL; 2 0 2
return (o && *o && SvOK(*o)) ? *o : NULL; 2 0 2
107 }
108  
109 /* The status out of a PSGI triplet; -1 when there is none to read - a
110 * streaming coderef, or anything that is not a triplet. */
111 326 static IV pk_abi_status_of(pTHX_ SV *response) {
112 AV *ra;
113 SV **s;
114 /*
115 # uncoverable condition left count:1 class:ignore_covered_err
116 # uncoverable condition left count:2 class:ignore_covered_err */
117 326 ▶ if (!response || !SvROK(response) || SvTYPE(SvRV(response)) != SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (!response || !SvROK(response) || SvTYPE(SvRV(response)) != SVt_PVAV) 326 0 326
if (!response || !SvROK(response) || SvTYPE(SvRV(response)) != SVt_PVAV) 326 0 326
if (!response || !SvROK(response) || SvTYPE(SvRV(response)) != SVt_PVAV) 1 325 326
118 1 return -1;
119 325 ra = (AV *)SvRV(response);
120 325 s = av_fetch(ra, 0, 0);
121 /*
122 # uncoverable condition right count:1 class:ignore_covered_err
123 # uncoverable condition right count:2 class:ignore_covered_err
124 # uncoverable condition right count:3 class:ignore_covered_err */
125 325 ▶ return (s && *s && SvOK(*s)) ? SvIV(*s) : -1;
Branch: 3 branches
BranchTrueFalseTotal
return (s && *s && SvOK(*s)) ? SvIV(*s) : -1; 325 0 325
return (s && *s && SvOK(*s)) ? SvIV(*s) : -1; 325 0 325
return (s && *s && SvOK(*s)) ? SvIV(*s) : -1; 325 0 325
126 }
127  
128 static const pk_abi PK_ABI = {
129 PK_ABI_VERSION,
130 pk_abi_env_of,
131 pk_abi_app_of,
132 pk_abi_match_of,
133 pk_abi_stash_of,
134 pk_abi_route_pattern_of,
135 pk_abi_operation_of,
136 pk_abi_status_of,
137 pk_obs_add_req,
138 pk_obs_add_res,
139 pk_obs_add_query, /* v2 */
140 pl_observe, /* v3 */
141 pl_observe_ctx, /* v4 */
142 pk_cur_get, /* v5 */
143 };
144  
145 #endif /* PK_ABI_IMPL_H */
« xs/password.xs ↑ Summary xs/dbi.xs »