Punk.xs

filter: Statementstmt 92.8% 37 / 42 (2 uncoverable) Branchbran 71.6% 30 / 60 (15 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 80.3% 67 / 102 (17 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_filecache.h ↑ Summary xs/router.xs »
1 /*
2 * Punk.xs - root XS file
3 *
4 * Thin wrapper: resolves the File::Raw::JSON C ABI, includes the C
5 * implementation headers, then pulls in the per-module XS fragments
6 * from xs/ via INCLUDE: (the Chandra / Open::API layout).
7 */
8  
9 #define PERL_NO_GET_CONTEXT
10 #include "EXTERN.h"
11 #include "perl.h"
12 #include "XSUB.h"
13 #include "punk/punk_immortal_probe.h" /* TEMP author probe (-DPUNK_IMMORTAL_PROBE) */
14  
15 #include "punk/punk_compat.h" /* pre-5.16 perl shims; must precede punk/ */
16  
17 #include "frj_abi.h"
18 #include "frx_abi.h"
19  
20 /* ---- the File::Raw::JSON C ABI (JSON response fast path) ------------------ *
21 * Resolved lazily on first use from File::Raw::JSON::_abi_ptr, exactly the
22 * consumer pattern Open::API uses. A mismatch croaks; the Perl caller only
23 * reaches here when the XS tier is active, and File::Raw::JSON is a hard
24 * PREREQ, so this is a startup-environment error, not a request-time one. */
25 static const frj_abi *PUNK_FRJ = NULL;
26 static int PUNK_FRJ_TRIED = 0;
27  
28 110946 static const frj_abi *punk_frj(pTHX) {
29 110946 ▶ if (!PUNK_FRJ && !PUNK_FRJ_TRIED) { /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (!PUNK_FRJ && !PUNK_FRJ_TRIED) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 146 110800 110946
if (!PUNK_FRJ && !PUNK_FRJ_TRIED) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 146 0 146
30 146 dSP; int count; IV p = 0;
31 146 PUNK_FRJ_TRIED = 1;
32 146 eval_pv("require File::Raw::JSON;", FALSE);
33 /* The require runs arbitrary Perl. If that grew the value stack it was
34 * reallocated, and the SP captured above now points into the freed
35 * block - which the PUTBACK below would publish as PL_stack_sp. */
36 146 SPAGAIN;
37 /*
38 # uncoverable branch false
39 # uncoverable condition right count:1 class:ignore_covered_err
40 # uncoverable condition right count:2 class:ignore_covered_err */
41 146 ▶ if (!SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV)) { 146 0 146
if (!SvTRUE(ERRSV)) { 146 0 146
42 146 ▶ ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; 0 146 146
43 146 count = call_pv("File::Raw::JSON::_abi_ptr", G_SCALAR | G_EVAL);
44 146 SPAGAIN;
45 /*
46 # uncoverable branch false
47 # uncoverable condition right count:1 class:ignore_covered_err
48 # uncoverable condition right count:2 class:ignore_covered_err */
49 146 ▶ if (!SvTRUE(ERRSV) && count > 0) p = POPi;
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 146 0 146
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 146 0 146
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 146 0 146
50 /*
51 # uncoverable statement
52 # uncoverable branch true
53 # uncoverable branch false
54 # uncoverable condition left count:1
55 # uncoverable condition right count:1 */
56 0 ▶ else if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) (void)POPs; 0 0 0
57 146 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 146 0 146
58 /*
59 # uncoverable branch false
60 # uncoverable condition right count:1 class:ignore_covered_err */
61 146 ▶ if (p) {
Branch: 1 branch
BranchTrueFalseTotal
if (p) { 146 0 146
62 146 const frj_abi *a = INT2PTR(const frj_abi *, p);
63 /*
64 # uncoverable branch false
65 # uncoverable condition right count:1 class:ignore_covered_err
66 # uncoverable condition right count:2 class:ignore_covered_err */
67 146 ▶ if (a && a->abi_version >= FRJ_ABI_VERSION) PUNK_FRJ = a;
Branch: 2 branches
BranchTrueFalseTotal
if (a && a->abi_version >= FRJ_ABI_VERSION) PUNK_FRJ = a; 146 0 146
if (a && a->abi_version >= FRJ_ABI_VERSION) PUNK_FRJ = a; 146 0 146
68 }
69 }
70 }
71 /*
72 # uncoverable branch true
73 # uncoverable condition left count:1 class:ignore_covered_err */
74 110946 ▶ if (!PUNK_FRJ)
Branch: 1 branch
BranchTrueFalseTotal
if (!PUNK_FRJ) 0 110946 110946
75 0 croak("Punk: the XS JSON path needs File::Raw::JSON with a " /* # uncoverable statement */
76 "compatible C ABI (FRJ_ABI_VERSION %d)", FRJ_ABI_VERSION);
77 110946 return PUNK_FRJ;
78 }
79  
80 /* ---- the File::Raw::XML C ABI (the XML body path) ------------------------- *
81 * The frj twin. The XML path needs frx_abi's SV bridge - doc_to_sv,
82 * doc_from_sv, node_from_sv, node_to_sv - which is what lets a document cross
83 * between C and Perl without a method call; File::Raw::XML 0.03 is the first
84 * with it and is a hard PREREQ, so a failure here is a startup-environment
85 * error rather than something to fall back from. */
86 static const frx_abi *PUNK_FRX = NULL;
87 static int PUNK_FRX_TRIED = 0;
88  
89 63 static const frx_abi *punk_frx(pTHX) {
90 63 ▶ if (!PUNK_FRX && !PUNK_FRX_TRIED) { /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (!PUNK_FRX && !PUNK_FRX_TRIED) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 4 59 63
if (!PUNK_FRX && !PUNK_FRX_TRIED) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 4 0 4
91 4 dSP; int count; IV p = 0;
92 4 PUNK_FRX_TRIED = 1;
93 4 eval_pv("require File::Raw::XML;", FALSE);
94 4 SPAGAIN; /* the require may have moved the stack */
95 /*
96 # uncoverable branch false
97 # uncoverable condition right count:1 class:ignore_covered_err
98 # uncoverable condition right count:2 class:ignore_covered_err */
99 4 ▶ if (!SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV)) { 4 0 4
if (!SvTRUE(ERRSV)) { 4 0 4
100 4 ▶ ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; 0 4 4
101 4 count = call_pv("File::Raw::XML::_abi_ptr", G_SCALAR | G_EVAL);
102 4 SPAGAIN;
103 /*
104 # uncoverable branch false
105 # uncoverable condition right count:1 class:ignore_covered_err
106 # uncoverable condition right count:2 class:ignore_covered_err */
107 4 ▶ if (!SvTRUE(ERRSV) && count > 0) p = POPi;
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 4 0 4
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 4 0 4
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 4 0 4
108 /*
109 # uncoverable statement
110 # uncoverable branch true
111 # uncoverable branch false
112 # uncoverable condition left count:1
113 # uncoverable condition right count:1 */
114 0 ▶ else if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) (void)POPs; 0 0 0
115 4 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 4 0 4
116 /*
117 # uncoverable branch false
118 # uncoverable condition right count:1 class:ignore_covered_err */
119 4 ▶ if (p) {
Branch: 1 branch
BranchTrueFalseTotal
if (p) { 4 0 4
120 4 const frx_abi *a = INT2PTR(const frx_abi *, p);
121 /*
122 # uncoverable branch false
123 # uncoverable condition right count:1 class:ignore_covered_err
124 # uncoverable condition right count:2 class:ignore_covered_err */
125 4 ▶ if (a && a->abi_version >= FRX_ABI_VERSION) PUNK_FRX = a;
Branch: 2 branches
BranchTrueFalseTotal
if (a && a->abi_version >= FRX_ABI_VERSION) PUNK_FRX = a; 4 0 4
if (a && a->abi_version >= FRX_ABI_VERSION) PUNK_FRX = a; 4 0 4
126 }
127 }
128 }
129 /*
130 # uncoverable branch true
131 # uncoverable condition left count:1 class:ignore_covered_err */
132 63 ▶ if (!PUNK_FRX)
Branch: 1 branch
BranchTrueFalseTotal
if (!PUNK_FRX) 0 63 63
133 0 croak("Punk: the XML path needs File::Raw::XML with a compatible " /* # uncoverable statement */
134 "C ABI (FRX_ABI_VERSION %d)", FRX_ABI_VERSION);
135 63 return PUNK_FRX;
136 }
137  
138 #include "punk/punk_names.h" /* fixed module/slot/key strings, named once */
139 #include "punk/punk_escape.h" /* HTML escaping, shared, and $c->escape_html */
140 #include "punk/punk_xml.h" /* the XML body path, on frx_abi's SV bridge */
141 #include "punk/punk_obs.h" /* the C ABI's observer registry - early,
142 * because punk_context.h and punk_serve.h
143 * both fire from it (pk_abi_impl.h, which
144 * needs the context slots, comes after) */
145 #include "punk/punk_route.h"
146 #include "punk/punk_response.h"
147 #include "punk/punk_request.h"
148 #include "punk/punk_accept.h" /* Accept negotiation for respond_to */
149 #include "punk/punk_multipart.h" /* multipart/form-data + uploads */
150 #include "punk/punk_context.h" /* the per-request context object */
151 #include "punk/pk_abi_impl.h" /* Punk's own C ABI table (needs PCX_*) */
152 #include "punk/punk_obs_selftest.h" /* a C consumer of that table, for t/ */
153 #include "punk/punk_cookie.h" /* build a Set-Cookie value */
154 #include "punk/punk_session.h" /* signed cookie sessions (SHA-256/HMAC) */
155 #include "punk/punk_flash.h" /* one-request messages over the session */
156 #include "punk/punk_ua.h" /* the shared outbound Fetch agent */
157 #include "punk/punk_log.h" /* the level-based logger */
158 #include "punk/punk_dispatch.h" /* the Open::API C ABI consumer */
159 #include "punk/punk_views.h" /* the view-engine registry */
160 #include "punk/punk_scope.h" /* the `under` handle (needs context) */
161 #include "punk/punk_app.h" /* the Punk::App registrar (needs context) */
162 #include "punk/punk_host.h" /* the origin + host allowlist (needs app) */
163 #include "punk/punk_proxy.h" /* reverse-proxy trust (used by serve) */
164 #include "punk/punk_state.h" /* the compiled app as a C struct */
165 #include "punk/punk_serve.h" /* the request dispatcher */
166 #include "punk/punk_ws.h" /* the RFC 6455 frame codec */
167 #include "punk/punk_config.h" /* layered YAML config + resolved secrets */
168 #include "punk/punk_asset.h" /* content-addressed asset URLs (needs sha256) */
169 #include "punk/punk_filecache.h" /* static files by content + their stat: the
170 syscalls were 2/3 of a static hit */
171 #include "punk/punk_static.h" /* the static-file app (a magic-CV closure) */
172 #include "punk/punk_url.h" /* named routes: names, url_for, the filter */
173 #include "punk/punk_sendfile.h" /* $c->send_file: validators + ranges */
174 #include "punk/punk_cget.h" /* conditional GET (needs sendfile+context) */
175 #include "punk/punk_favicon.h" /* GET /favicon.ico, frozen at to_app */
176 #include "punk/punk_oamount.h" /* the `api` mount, boot half (needs static) */
177 #include "punk/punk_dbi.h" /* the shipped DBI model backend */
178 #include "punk/punk_dbiobs.h" /* Punk::DBI, the observed handle */
179 #include "punk/punk_dbq.h" /* the query shapes both backends share */
180 #include "punk/punk_model.h" /* the model tier: DSL, metadata, contract */
181 #include "punk/punk_csrf.h" /* single-use tokens over the session */
182 #include "punk/punk_entropy.h" /* sliced, pid-guarded entropy (needs csrf) */
183 #include "punk/punk_mpstream.h" /* multipart, parsed as it arrives */
184 #include "punk/punk_csp.h" /* CSP nonce + policy (needs entropy) */
185 #include "punk/punk_reqid.h" /* an id per request (uuidv7, buffered) */
186 #include "punk/punk_frozen.h" /* Frozen's C ABI, resolved on first use */
187 #include "punk/punk_plural.h" /* CLDR plural categories (before i18n) */
188 #include "punk/punk_i18n.h" /* the catalogue arena, loaded at boot */
189 #include "punk/punk_lang.h" /* Accept-Language (needs accept + context) */
190 #include "punk/punk_password.h" /* PBKDF2 password hashing (needs session+csrf) */
191 #include "punk/punk_auth.h" /* the auth battery's guard + denial path */
192 #include "punk/punk_validate.h" /* collecting validation, on the jsf ABI */
193 #include "punk/punk_stencil.h" /* the shipped view engine, on Stencil's ABI */
194 #include "punk/punk_markdown.h" /* the `markdown` docs mount (needs static,
195 * stencil and request) */
196 #include "hm_abi.h" /* Hyperman's C ABI, via EU::Depends */
197 #include "punk/punk_wsconn.h" /* the live WebSocket connection */
198 #include "punk/punk_wshandshake.h" /* the upgrade handshake (SHA-1 + base64) */
199 #include "punk/punk_sse.h" /* Server-Sent Events streams */
200 #include "punk/punk_afterres.h" /* after_response: the loop timer needs the
201 ABI, so it lands below hm_abi.h */
202 #include "punk/punk_ratelimit.h" /* rate_limit: a C before_dispatch closure */
203 #include "punk/punk_wsroom.h" /* per-worker pub/sub rooms */
204 #include "punk/punk_cache.h" /* the in-memory cache, bounded by BYTES */
205 #include "punk/punk_cachefile.h" /* ... and the file store, one copy per pool */
206 #include "punk/punk_bus.h" /* ... and across the pool, on hm_abi v5 */
207 #include "punk/punk_cachefront.h" /* Punk::Cache: the tier over both stores */
208 #include "punk/punk_sessionstore.h" /* where a server-side session lives */
209 #include "punk/punk_idem.h" /* Idempotency-Key (needs cache+request) */
210 #include "punk/punk_future.h" /* async result: loop when live, else block */
211 #include "punk/punk_dbil.h" /* the async model backend, on DBIx::Loop's
212 C ABI (needs punk_dbi.h + punk_future.h) */
213 #include "punk/punk_txn.h" /* $c->txn on either backend (needs dbil) */
214 #include "punk/punk_stream.h" /* $c->stream: a body of unknown length
215 (needs wsconn + wshandshake + future) */
216 #include "punk/punk_import.h" /* `use Punk` and the DSL table */
217 #include "punk/punk_cors.h" /* cross-origin: preflight + headers */
218 #include "punk/punk_headers.h" /* security headers on every response */
219 #include "punk/punk_blob.h" /* content-addressed uploads, on Apophis */
220 #include "punk/punk_sitemap.h" /* which routes are URLs (needs route+app) */
221 #include "punk/punk_mrows.h" /* JSONFile + Markdown model backends (needs dbq, markdown, app) */
222 #include "punk/punk_computed.h" /* computed read-only backends (needs dbq, mrows) */
223 #include "punk/punk_health.h" /* /healthz and /readyz (needs response+app) */
224 #include "punk/punk_metrics.h" /* Prometheus /metrics (needs pk_abi_impl+obs) */
225 #include "punk/punk_compile.h" /* the boot compiler (needs static+serve) */
226  
227 /* Every Punk::Router is an IV-ref to a pr_router (new through compile through
228 * match); the whole class is XS. */
229 65126 static pr_router *punk_router_of(pTHX_ SV *self) {
230 /*
231 # uncoverable branch true
232 # uncoverable condition left count:1 class:ignore_covered_err
233 # uncoverable condition left count:2 class:ignore_covered_err */
234 65126 ▶ if (!SvROK(self) || !SvIOK(SvRV(self)))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(self) || !SvIOK(SvRV(self))) 65126 0 65126
if (!SvROK(self) || !SvIOK(SvRV(self))) 0 65126 65126
235 0 croak("Punk::Router: not a compiled C router handle"); /* # uncoverable statement */
236 65126 return (pr_router *)INT2PTR(void *, SvIV(SvRV(self)));
237 }
238  
239 MODULE = Punk PACKAGE = Punk
240  
241 PROTOTYPES: DISABLE
242  
243 INCLUDE: xs/core.xs
244 INCLUDE: xs/abi.xs
245 INCLUDE: xs/router.xs
246 INCLUDE: xs/request.xs
247 INCLUDE: xs/upload.xs
248 INCLUDE: xs/response.xs
249 INCLUDE: xs/dispatch.xs
250 INCLUDE: xs/context.xs
251 INCLUDE: xs/session.xs
252 INCLUDE: xs/log.xs
253 INCLUDE: xs/scope.xs
254 INCLUDE: xs/app.xs
255 INCLUDE: xs/ratelimit.xs
256 INCLUDE: xs/serve.xs
257 INCLUDE: xs/views.xs
258 INCLUDE: xs/stencil.xs
259 INCLUDE: xs/csrf.xs
260 INCLUDE: xs/reqid.xs
261 INCLUDE: xs/password.xs
262 INCLUDE: xs/auth.xs
263 INCLUDE: xs/validate.xs
264 INCLUDE: xs/cors.xs
265 INCLUDE: xs/headers.xs
266 INCLUDE: xs/websocket.xs
267 INCLUDE: xs/wshandshake.xs
268 INCLUDE: xs/sse.xs
269 INCLUDE: xs/wsroom.xs
270 INCLUDE: xs/future.xs
271 INCLUDE: xs/stream.xs
272 INCLUDE: xs/config.xs
273 INCLUDE: xs/static.xs
274 INCLUDE: xs/sendfile.xs
275 INCLUDE: xs/markdown.xs
276 INCLUDE: xs/model.xs
277 INCLUDE: xs/oamount.xs
278 INCLUDE: xs/dbi.xs
279 INCLUDE: xs/dbil.xs
280 INCLUDE: xs/mrows.xs
281 INCLUDE: xs/computed.xs
282 INCLUDE: xs/txn.xs
283 INCLUDE: xs/cache.xs
284 INCLUDE: xs/blob.xs
285 INCLUDE: xs/sitemap.xs
286 INCLUDE: xs/health.xs
287 INCLUDE: xs/metrics.xs
288 INCLUDE: xs/conditionalget.xs
289 INCLUDE: xs/idempotency.xs
290 INCLUDE: xs/csp.xs
291 INCLUDE: xs/i18n.xs
292 INCLUDE: xs/url.xs
293 INCLUDE: xs/compile.xs
« include/punk/punk_filecache.h ↑ Summary xs/router.xs »