include/punk/punk_lang.h

filter: Statementstmt 98.3% 234 / 238 Branchbran 70.6% 267 / 378 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 81.3% 501 / 616 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_headers.h ↑ Summary xs/csp.xs »
1 #ifndef PUNK_LANG_H
2 #define PUNK_LANG_H
3  
4 /* Accept-Language negotiation.
5 *
6 * ---- why this is not punk_accept.h ----------------------------------------
7 *
8 * punk_accept.h looks like it already does this, and it does the hard half:
9 * q-values, the ordering they imply, and the rule that `q=0` is an EXCLUSION
10 * rather than an absence. All of that is reused - pa_q_of is called directly.
11 *
12 * What it cannot do is parse the header. pa_parse accepts a segment only when
13 * it finds a slash in it, or when the segment is a bare `*`:
14 *
15 * if (slash < sub_end && slash > p && sub_end > slash + 1) { ... }
16 * else if (sub_end == p + 1 && *p == '*') { ... }
17 *
18 * A language tag has no slash, so `Accept-Language: en-GB,en;q=0.9` parses to
19 * ZERO ranges through it, and pa_range has nowhere to put a tag that is not
20 * type/subtype. Hence a sibling parser, in the same style: parse in place, a
21 * bounded number of stack entries, no allocation, and a malformed header
22 * ignored rather than fatal - a client must not be able to error a response
23 * with a bad header.
24 *
25 * ---- and why the MATCH is not the same either -----------------------------
26 *
27 * Media ranges have a three-rung specificity ladder: exact, "type slash star", and the bare wildcard.
28 * Language tags have prefix fallback, which is asymmetric:
29 *
30 * - `en-GB` requested matches a catalogue holding `en`. Truncate the
31 * request at `-` and try again: zh-Hant-TW, zh-Hant, zh.
32 * - `en` requested does NOT match a catalogue holding only `en-GB`. Serving
33 * pt-BR to a request for pt is how a Portuguese speaker gets Brazilian
34 * spelling with no way to refuse. An application that wants that can
35 * configure an alias.
36 * - The truncation is on SUBTAG BOUNDARIES, never a byte prefix. `en` must
37 * not match `ens`, which is what a bare strncmp would do.
38 */
39  
40 #define PL_TAG_MAX_N 32 /* the sibling of PA_RANGE_MAX */
41  
42 typedef struct pl_tag {
43 const char *t; STRLEN tl; /* the tag, pointing into the header */
44 int q; /* per mille: 0..1000 */
45 } pl_tag;
46  
47 /* Parse an Accept-Language into `out`. Returns how many tags were taken.
48 * Anything past PL_TAG_MAX_N is ignored; so is a segment with no shape. */
49 98 static int pl_parse(const char *a, STRLEN al, pl_tag *out, int max) {
50 98 const char *p = a, *end = a + al;
51 98 int n = 0;
52 298 ▶ while (p < end && n < max) {
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && n < max) { 203 95 298
while (p < end && n < max) { 200 3 203
53 200 const char *seg_end = p, *tag_end, *par;
54 1712 ▶ while (seg_end < end && *seg_end != ',') seg_end++;
Branch: 2 branches
BranchTrueFalseTotal
while (seg_end < end && *seg_end != ',') seg_end++; 1618 94 1712
while (seg_end < end && *seg_end != ',') seg_end++; 1512 106 1618
55 205 ▶ while (p < seg_end && pa_ws(*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < seg_end && pa_ws(*p)) p++; 202 3 205
while (p < seg_end && pa_ws(*p)) p++; 5 197 202
56 200 par = p;
57 1643 ▶ while (par < seg_end && *par != ';') par++;
Branch: 2 branches
BranchTrueFalseTotal
while (par < seg_end && *par != ';') par++; 1456 187 1643
while (par < seg_end && *par != ';') par++; 1443 13 1456
58 200 tag_end = par;
59 200 ▶ while (tag_end > p && pa_ws(tag_end[-1])) tag_end--;
Branch: 2 branches
BranchTrueFalseTotal
while (tag_end > p && pa_ws(tag_end[-1])) tag_end--; 196 4 200
while (tag_end > p && pa_ws(tag_end[-1])) tag_end--; 0 196 196
60  
61 200 ▶ if (tag_end > p && (STRLEN)(tag_end - p) <= PI_TAG_MAX) {
Branch: 2 branches
BranchTrueFalseTotal
if (tag_end > p && (STRLEN)(tag_end - p) <= PI_TAG_MAX) { 196 4 200
if (tag_end > p && (STRLEN)(tag_end - p) <= PI_TAG_MAX) { 194 2 196
62 /* A tag is alphanumerics and hyphens, or the wildcard. Anything
63 * else is a header this code should not be guessing about. */
64 const char *q;
65 194 int ok = 1;
66 194 ▶ if (!(tag_end == p + 1 && *p == '*')) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(tag_end == p + 1 && *p == '*')) { 6 188 194
if (!(tag_end == p + 1 && *p == '*')) { 2 4 6
67 607 ▶ for (q = p; q < tag_end; q++) {
Branch: 1 branch
BranchTrueFalseTotal
for (q = p; q < tag_end; q++) { 423 184 607
68 423 char c = *q;
69 446 ▶ if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
Branch: 5 branches
BranchTrueFalseTotal
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 377 46 423
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 0 377 377
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 23 23 46
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 0 23 23
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 6 17 23
70 29 ▶ || (c >= '0' && c <= '9') || c == '-')) { ok = 0; break; }
Branch: 2 branches
BranchTrueFalseTotal
|| (c >= '0' && c <= '9') || c == '-')) { ok = 0; break; } 3 20 23
|| (c >= '0' && c <= '9') || c == '-')) { ok = 0; break; } 3 0 3
71 }
72 }
73 194 ▶ if (ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (ok) { 188 6 194
74 188 out[n].t = p;
75 188 out[n].tl = (STRLEN)(tag_end - p);
76 188 out[n].q = pa_q_of(par, seg_end);
77 188 n++;
78 }
79 }
80 200 p = seg_end + 1;
81 }
82 98 return n;
83 }
84  
85 653 ▶static int pl_star(const char *s, STRLEN l) { return l == 1 && *s == '*'; }
Branch: 2 branches
BranchTrueFalseTotal
static int pl_star(const char *s, STRLEN l) { return l == 1 && *s == '*'; } 10 643 653
static int pl_star(const char *s, STRLEN l) { return l == 1 && *s == '*'; } 8 2 10
86  
87 /* Does the catalogue tag `c` satisfy the requested tag `t`?
88 *
89 * Returns the specificity of the match - 2 exact, 1 through prefix fallback,
90 * 0 the wildcard, -1 no match - mirroring pa_match, because the RFC rule that
91 * the MOST SPECIFIC match decides the q-value is the same rule here. */
92 653 static int pl_spec(const char *t, STRLEN tl, const char *c, STRLEN cl) {
93 653 ▶ if (pl_star(t, tl)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (pl_star(t, tl)) return 0; 8 645 653
94 645 ▶ if (pi_tag_eq(t, tl, c, cl)) return 2;
Branch: 1 branch
BranchTrueFalseTotal
if (pi_tag_eq(t, tl, c, cl)) return 2; 116 529 645
95 /* The catalogue tag must be a prefix of the REQUESTED one, on a subtag
96 * boundary. Never the other way round. */
97 529 ▶ if (cl < tl && t[cl] == '-' && pi_tag_eq(t, cl, c, cl)) return 1;
Branch: 3 branches
BranchTrueFalseTotal
if (cl < tl && t[cl] == '-' && pi_tag_eq(t, cl, c, cl)) return 1; 52 477 529
if (cl < tl && t[cl] == '-' && pi_tag_eq(t, cl, c, cl)) return 1; 51 1 52
if (cl < tl && t[cl] == '-' && pi_tag_eq(t, cl, c, cl)) return 1; 12 39 51
98 517 return -1;
99 }
100  
101 /* Which catalogue does this header ask for? Returns an index into the arena,
102 * or -1 when nothing is acceptable.
103 *
104 * A catalogue's score is the q of the most specific tag that matches it, and
105 * a q of 0 there is an exclusion: `fr;q=0, *` means never French, including
106 * through the wildcard, which is the case naive negotiators get wrong.
107 * Ties break on specificity, then on the order the tags appeared. */
108 88 static int pl_pick(const pl_tag *tags, int n, const pi_arena *ar) {
109 88 int i, best = -1, best_q = 0, best_spec = -1, best_order = 0;
110  
111 88 ▶ if (!ar) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!ar) return -1; 0 88 88
112 590 ▶ for (i = 0; i < ar->ncat; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ar->ncat; i++) { 502 88 590
113 502 const pi_cat *c = &ar->cat[i];
114 502 int j, q = -1, spec = -1, order = 0;
115  
116 1141 ▶ for (j = 0; j < n; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < n; j++) { 639 502 1141
117 639 int s = pl_spec(tags[j].t, tags[j].tl, c->tag, c->taglen);
118 639 ▶ if (s > spec) { spec = s; q = tags[j].q; order = j; }
Branch: 1 branch
BranchTrueFalseTotal
if (s > spec) { spec = s; q = tags[j].q; order = j; } 98 541 639
119 }
120 502 ▶ if (spec < 0 || q <= 0) continue; /* unmentioned, or excluded */
Branch: 2 branches
BranchTrueFalseTotal
if (spec < 0 || q <= 0) continue; /* unmentioned, or excluded */ 96 406 502
if (spec < 0 || q <= 0) continue; /* unmentioned, or excluded */ 3 93 96
121  
122 93 ▶ if (q > best_q
Branch: 1 branch
BranchTrueFalseTotal
if (q > best_q 12 81 93
123 12 ▶ || (q == best_q && spec > best_spec)
Branch: 2 branches
BranchTrueFalseTotal
|| (q == best_q && spec > best_spec) 11 1 12
|| (q == best_q && spec > best_spec) 5 6 11
124 6 ▶ || (q == best_q && spec == best_spec && order < best_order)) {
Branch: 3 branches
BranchTrueFalseTotal
|| (q == best_q && spec == best_spec && order < best_order)) { 5 1 6
|| (q == best_q && spec == best_spec && order < best_order)) { 4 1 5
|| (q == best_q && spec == best_spec && order < best_order)) { 1 3 4
125 88 best = i; best_q = q; best_spec = spec; best_order = order;
126 }
127 }
128 88 return best;
129 }
130  
131 /* The whole header to an index, or -1. */
132 100 static int pl_negotiate(const char *hdr, STRLEN hl, const pi_arena *ar) {
133 pl_tag tags[PL_TAG_MAX_N];
134 int n;
135 100 ▶ if (!hdr || !hl || !ar) return -1;
Branch: 3 branches
BranchTrueFalseTotal
if (!hdr || !hl || !ar) return -1; 99 1 100
if (!hdr || !hl || !ar) return -1; 98 1 99
if (!hdr || !hl || !ar) return -1; 0 98 98
136 98 n = pl_parse(hdr, hl, tags, PL_TAG_MAX_N);
137 98 ▶ if (!n) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!n) return -1; 10 88 98
138 88 return pl_pick(tags, n, ar);
139 }
140  
141 /* An explicitly named locale - from ?lang= or a stored choice - to an index.
142 *
143 * Exact first, then the same prefix fallback the header gets, so `?lang=en-GB`
144 * lands on the `en` catalogue rather than falling through to the default. A
145 * name with no catalogue is NOT an error: it falls through to the next source.
146 * A 500 on a hand-edited URL is a worse answer than the default language, and
147 * ?lang= is exactly the parameter people hand-edit.
148 */
149 7 static int pl_named(const char *tag, STRLEN tl, const pi_arena *ar) {
150 7 int i, best = -1;
151 7 STRLEN bestlen = 0;
152 7 ▶ if (!tag || !tl || !ar || tl > PI_TAG_MAX) return -1;
Branch: 4 branches
BranchTrueFalseTotal
if (!tag || !tl || !ar || tl > PI_TAG_MAX) return -1; 7 0 7
if (!tag || !tl || !ar || tl > PI_TAG_MAX) return -1; 7 0 7
if (!tag || !tl || !ar || tl > PI_TAG_MAX) return -1; 7 0 7
if (!tag || !tl || !ar || tl > PI_TAG_MAX) return -1; 0 7 7
153 16 ▶ for (i = 0; i < ar->ncat; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ar->ncat; i++) { 14 2 16
154 14 const pi_cat *c = &ar->cat[i];
155 14 int s = pl_spec(tag, tl, c->tag, c->taglen);
156 14 ▶ if (s == 2) return i;
Branch: 1 branch
BranchTrueFalseTotal
if (s == 2) return i; 5 9 14
157 9 ▶ if (s == 1 && c->taglen > bestlen) { best = i; bestlen = c->taglen; }
Branch: 2 branches
BranchTrueFalseTotal
if (s == 1 && c->taglen > bestlen) { best = i; bestlen = c->taglen; } 1 8 9
if (s == 1 && c->taglen > bestlen) { best = i; bestlen = c->taglen; } 1 0 1
158 }
159 2 return best;
160 }
161  
162 /* ---- the order a language is chosen ---------------------------------------
163 *
164 * Explicit beats implicit, most explicit first:
165 *
166 * 1. ?lang= - an explicit act by the user, on this request
167 * 2. the stored choice (session, or a cookie) - an explicit act on an
168 * earlier one
169 * 3. Accept-Language - what the browser was configured with, which is
170 * frequently not what the user wants and is never something they did on
171 * this site
172 * 4. the configured default
173 *
174 * 2 is what makes a language switcher work on the SECOND page. Without it an
175 * explicit choice loses to the browser on the next link, and the switcher
176 * appears to be broken - which it is.
177 */
178  
179 #define PL_ENV_KEY "punk.i18n_locale"
180  
181 typedef struct pl_choice {
182 int idx; /* catalogue index */
183 int explicit_; /* the request named it, so it is worth persisting */
184 } pl_choice;
185  
186 /* Resolve, given the pieces. Kept free of the context so it can be tested
187 * directly: every interesting case here is a table. */
188 2157 static pl_choice pl_resolve(const char *param, STRLEN paraml,
189 const char *stored, STRLEN storedl,
190 const char *header, STRLEN headerl,
191 const pi_arena *ar) {
192 pl_choice ch;
193 2157 ch.idx = -1;
194 2157 ch.explicit_ = 0;
195  
196 2157 ▶ if (param && paraml) {
Branch: 2 branches
BranchTrueFalseTotal
if (param && paraml) { 4 2153 2157
if (param && paraml) { 4 0 4
197 4 ch.idx = pl_named(param, paraml, ar);
198 4 ▶ if (ch.idx >= 0) { ch.explicit_ = 1; return ch; }
Branch: 1 branch
BranchTrueFalseTotal
if (ch.idx >= 0) { ch.explicit_ = 1; return ch; } 3 1 4
199 /* named a locale with no catalogue: fall through, never 500 */
200 }
201 2154 ▶ if (stored && storedl) {
Branch: 2 branches
BranchTrueFalseTotal
if (stored && storedl) { 3 2151 2154
if (stored && storedl) { 3 0 3
202 3 ch.idx = pl_named(stored, storedl, ar);
203 3 ▶ if (ch.idx >= 0) return ch;
Branch: 1 branch
BranchTrueFalseTotal
if (ch.idx >= 0) return ch; 3 0 3
204 }
205 2151 ▶ if (header && headerl) {
Branch: 2 branches
BranchTrueFalseTotal
if (header && headerl) { 60 2091 2151
if (header && headerl) { 60 0 60
206 60 ch.idx = pl_negotiate(header, headerl, ar);
207 60 ▶ if (ch.idx >= 0) return ch;
Branch: 1 branch
BranchTrueFalseTotal
if (ch.idx >= 0) return ch; 60 0 60
208 }
209 2091 ▶ ch.idx = ar ? ar->def : -1;
Branch: 1 branch
BranchTrueFalseTotal
ch.idx = ar ? ar->def : -1; 2091 0 2091
210 2091 return ch;
211 }
212  
213 /* ---- one lookup, two callers ----------------------------------------------
214 *
215 * `$c->locale` and the template's `locale` hash must agree about what a key
216 * resolves to, what counts as untranslated, and when a missing key warns.
217 * Two implementations of that would drift, and the drift would be silent:
218 * a page whose handler strings are fine and whose template strings are not.
219 */
220 #define PI_HIT 0 /* a translation */
221 #define PI_LEVEL 1 /* a level - keys continue below this one */
222 #define PI_MISSING 2 /* nowhere at all */
223  
224 131 static int pi_lookup(pTHX_ const pi_arena *ar, const pi_cat *cat,
225 const char *k, STRLEN kl, const char **vp, STRLEN *vl,
226 int *utf8) {
227 const pi_cat *d;
228  
229 131 ▶ if (utf8) *utf8 = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (utf8) *utf8 = 0; 131 0 131
230 131 *vp = pi_get(cat, k, kl, vl, utf8);
231 131 ▶ if (*vp) return PI_HIT;
Branch: 1 branch
BranchTrueFalseTotal
if (*vp) return PI_HIT; 80 51 131
232  
233 /* The default catalogue before giving up: a key present in `en` and
234 * missing from `fr-CA` is UNTRANSLATED, not missing. */
235 51 ▶ d = (ar && ar->def >= 0) ? &ar->cat[ar->def] : NULL;
Branch: 2 branches
BranchTrueFalseTotal
d = (ar && ar->def >= 0) ? &ar->cat[ar->def] : NULL; 51 0 51
d = (ar && ar->def >= 0) ? &ar->cat[ar->def] : NULL; 51 0 51
236 51 ▶ if (d && d != cat) {
Branch: 2 branches
BranchTrueFalseTotal
if (d && d != cat) { 51 0 51
if (d && d != cat) { 3 48 51
237 3 *vp = pi_get(d, k, kl, vl, utf8);
238 3 ▶ if (*vp) { pi_n_untranslated++; return PI_HIT; }
Branch: 1 branch
BranchTrueFalseTotal
if (*vp) { pi_n_untranslated++; return PI_HIT; } 2 1 3
239 }
240  
241 49 ▶ if (pi_is_prefix(cat, k, kl) || (d && d != cat && pi_is_prefix(d, k, kl)))
Branch: 4 branches
BranchTrueFalseTotal
if (pi_is_prefix(cat, k, kl) || (d && d != cat && pi_is_prefix(d, k, kl))) 47 2 49
if (pi_is_prefix(cat, k, kl) || (d && d != cat && pi_is_prefix(d, k, kl))) 47 0 47
if (pi_is_prefix(cat, k, kl) || (d && d != cat && pi_is_prefix(d, k, kl))) 1 46 47
if (pi_is_prefix(cat, k, kl) || (d && d != cat && pi_is_prefix(d, k, kl))) 0 1 1
242 2 return PI_LEVEL;
243  
244 47 pi_n_missing++;
245 47 return PI_MISSING;
246 }
247  
248 /* The same three answers, one step at a time.
249 *
250 * pi_lookup takes a whole dotted key and walks it from the catalogue root.
251 * This takes ONE segment and the node the last step reached, which is what
252 * the tied hash needs: a template descends one key per FETCH, and re-walking
253 * the whole path each time is what made the tied door cost six probes for
254 * three segments.
255 *
256 * The default catalogue is probed LAZILY. On a hit in the negotiated
257 * catalogue - the common case - it is not probed at all, so the fast path is
258 * a single probe. It is only consulted to fall back, or to carry the
259 * default's position down into a nested level.
260 *
261 * The counters live here, next to pi_lookup's, so the two doors cannot come
262 * to different conclusions about what is missing and what is merely
263 * untranslated. */
264 2033 static int pi_step(pTHX_ const pi_arena *ar, const pi_cat *cat,
265 uint32_t node, uint32_t dnode,
266 const char *k, STRLEN kl,
267 const char **vp, STRLEN *vl, int *utf8,
268 uint32_t *child, uint32_t *dchild) {
269 2033 ▶ const pi_cat *d = (ar && ar->def >= 0) ? &ar->cat[ar->def] : NULL;
Branch: 2 branches
BranchTrueFalseTotal
const pi_cat *d = (ar && ar->def >= 0) ? &ar->cat[ar->def] : NULL; 2033 0 2033
const pi_cat *d = (ar && ar->def >= 0) ? &ar->cat[ar->def] : NULL; 2033 0 2033
270 2033 uint32_t slot = FZ_NOHANDLE, dslot = FZ_NOHANDLE;
271 2033 int r = FZ_ABSENT, dr = FZ_ABSENT;
272  
273 2033 ▶ if (utf8) *utf8 = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (utf8) *utf8 = 0; 2033 0 2033
274 2033 *child = *dchild = FZ_NOHANDLE;
275  
276 2033 ▶ if (cat && cat->fz && node != FZ_NOHANDLE && PUNK_FZ)
Branch: 4 branches
BranchTrueFalseTotal
if (cat && cat->fz && node != FZ_NOHANDLE && PUNK_FZ) 2033 0 2033
if (cat && cat->fz && node != FZ_NOHANDLE && PUNK_FZ) 2033 0 2033
if (cat && cat->fz && node != FZ_NOHANDLE && PUNK_FZ) 2032 1 2033
if (cat && cat->fz && node != FZ_NOHANDLE && PUNK_FZ) 2032 0 2032
277 2032 r = (PUNK_FZ->probe)(cat->fz, node, k, kl, &slot);
278  
279 2033 ▶ if (r == FZ_LEAF) {
Branch: 1 branch
BranchTrueFalseTotal
if (r == FZ_LEAF) { 2023 10 2033
280 2023 *child = slot;
281 2023 *vp = (PUNK_FZ->str)(cat->fz, slot, vl, utf8);
282 2023 ▶ if (*vp) return PI_HIT;
Branch: 1 branch
BranchTrueFalseTotal
if (*vp) return PI_HIT; 2023 0 2023
283 }
284  
285 /* Only now is the default worth asking. */
286 10 ▶ if (d == cat) { dr = r; dslot = slot; }
Branch: 1 branch
BranchTrueFalseTotal
if (d == cat) { dr = r; dslot = slot; } 7 3 10
287 3 ▶ else if (d && d->fz && dnode != FZ_NOHANDLE && PUNK_FZ)
Branch: 4 branches
BranchTrueFalseTotal
else if (d && d->fz && dnode != FZ_NOHANDLE && PUNK_FZ) 3 0 3
else if (d && d->fz && dnode != FZ_NOHANDLE && PUNK_FZ) 3 0 3
else if (d && d->fz && dnode != FZ_NOHANDLE && PUNK_FZ) 3 0 3
else if (d && d->fz && dnode != FZ_NOHANDLE && PUNK_FZ) 3 0 3
288 3 dr = (PUNK_FZ->probe)(d->fz, dnode, k, kl, &dslot);
289  
290 10 ▶ if (r != FZ_ABSENT) *child = slot;
Branch: 1 branch
BranchTrueFalseTotal
if (r != FZ_ABSENT) *child = slot; 6 4 10
291 10 ▶ if (dr != FZ_ABSENT) *dchild = dslot;
Branch: 1 branch
BranchTrueFalseTotal
if (dr != FZ_ABSENT) *dchild = dslot; 9 1 10
292  
293 10 ▶ if (dr == FZ_LEAF && d != cat) {
Branch: 2 branches
BranchTrueFalseTotal
if (dr == FZ_LEAF && d != cat) { 1 9 10
if (dr == FZ_LEAF && d != cat) { 1 0 1
294 1 *vp = (PUNK_FZ->str)(d->fz, dslot, vl, utf8);
295 1 ▶ if (*vp) { pi_n_untranslated++; return PI_HIT; }
Branch: 1 branch
BranchTrueFalseTotal
if (*vp) { pi_n_untranslated++; return PI_HIT; } 1 0 1
296 }
297 9 ▶ if (r == FZ_BRANCH || dr == FZ_BRANCH) return PI_LEVEL;
Branch: 2 branches
BranchTrueFalseTotal
if (r == FZ_BRANCH || dr == FZ_BRANCH) return PI_LEVEL; 3 6 9
if (r == FZ_BRANCH || dr == FZ_BRANCH) return PI_LEVEL; 2 1 3
298  
299 1 pi_n_missing++;
300 1 return PI_MISSING;
301 }
302  
303 /* ---- the request side ------------------------------------------------------
304 *
305 * Everything below needs punk_context.h, so this header is included after it.
306 */
307  
308 /* The plugin's config, off the app the context carries. */
309 2299 static HV *pi_cfg_of(pTHX_ SV *c) {
310 AV *av;
311 SV *app, **e;
312 2299 ▶ if (!c || !SvROK(c)) return NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (!c || !SvROK(c)) return NULL; 2299 0 2299
if (!c || !SvROK(c)) return NULL; 0 2299 2299
313 2299 av = pcx_av(aTHX_ c);
314 2299 ▶ if (!av) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!av) return NULL; 0 2299 2299
315 2299 app = pcx_get(aTHX_ av, PCX_APP);
316 2299 ▶ if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL;
Branch: 3 branches
BranchTrueFalseTotal
if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL; 2299 0 2299
if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL; 2299 0 2299
if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL; 0 2299 2299
317 2299 e = hv_fetchs((HV *)SvRV(app), K_I18N, 0);
318 2160 ▶ return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) 2160 0 2160
return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) 2160 0 2160
return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) 2160 0 2160
319 4459 ▶ ? (HV *)SvRV(*e) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*e) : NULL; 2160 139 2299
320 }
321  
322 /* Is this application in development?
323 *
324 * Frozen into the config at compile time, the way CSP does it: `plugin` is
325 * written at the top of an application and `config` below it, so at
326 * registration time the answer is not known yet.
327 *
328 * A missing key on a production page is ALREADY visible - it renders as the
329 * key - so warning about it there is a log line per request telling somebody
330 * something they can see and cannot act on at that moment. */
331 48 static int pi_dev(pTHX_ HV *cfg) {
332 48 ▶ SV **e = cfg ? hv_fetchs(cfg, "dev", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **e = cfg ? hv_fetchs(cfg, "dev", 0) : NULL; 48 0 48
333 PERL_UNUSED_CONTEXT;
334 48 ▶ return (e && *e && SvTRUE(*e));
Branch: 3 branches
BranchTrueFalseTotal
return (e && *e && SvTRUE(*e)); 48 0 48
return (e && *e && SvTRUE(*e)); 48 0 48
return (e && *e && SvTRUE(*e)); 21 27 48
335 }
336  
337 /* Warn once per key, through the application's own logger. */
338 21 static void pi_warn_missing(pTHX_ SV *c, const char *k, STRLEN kl) {
339 21 dSP;
340 SV *msg;
341  
342 21 ▶ if (!pi_seen) pi_seen = newHV();
Branch: 1 branch
BranchTrueFalseTotal
if (!pi_seen) pi_seen = newHV(); 1 20 21
343 21 ▶ if (hv_exists(pi_seen, k, (I32)kl)) return;
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(pi_seen, k, (I32)kl)) return; 19 2 21
344 2 (void)hv_store(pi_seen, k, (I32)kl, &PL_sv_yes, 0);
345  
346 2 msg = sv_2mortal(newSVpvf(
347 "i18n: no translation for '%.*s' in any catalogue - it is rendering "
348 "as the key", (int)kl, k));
349  
350 2 ENTER; SAVETMPS;
351 2 ▶ PUSHMARK(SP); EXTEND(SP, 1); PUSHs(c); PUTBACK;
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 1); PUSHs(c); PUTBACK; 0 2 2
PUSHMARK(SP); EXTEND(SP, 1); PUSHs(c); PUTBACK; 0 2 2
352 2 ▶ if (call_method("log", G_SCALAR | G_EVAL) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("log", G_SCALAR | G_EVAL) > 0) { 2 0 2
353 2 SV *lg = SvREFCNT_inc(POPs);
354 2 PUTBACK;
355 2 ▶ if (!SvTRUE(ERRSV) && SvOK(lg)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && SvOK(lg)) { 2 0 2
if (!SvTRUE(ERRSV) && SvOK(lg)) { 2 0 2
if (!SvTRUE(ERRSV) && SvOK(lg)) { 2 0 2
356 2 ▶ PUSHMARK(SP); EXTEND(SP, 2);
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 2); 0 2 2
PUSHMARK(SP); EXTEND(SP, 2); 0 2 2
357 2 PUSHs(lg); PUSHs(msg);
358 2 PUTBACK;
359 2 (void)call_method("warn", G_DISCARD | G_EVAL);
360 2 SPAGAIN;
361 }
362 2 SvREFCNT_dec(lg);
363 }
364 0 else PUTBACK;
365 2 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 2 0 2
366 2 pi_n_warned++;
367 }
368  
369 /* One level of the `locale` hash a template reads. punk_i18n.h says why it is
370 * tied rather than built, and what it needed from Template::Stencil 0.10. */
371 2031 static SV *pi_tied_hash(pTHX_ pi_arena *ar, int idx, SV *prefix, HV *cfg,
372 SV *c, uint32_t node, uint32_t dnode) {
373 2031 AV *o = newAV();
374 2031 HV *h = newHV();
375 SV *obj;
376  
377 2031 av_extend(o, PIT_MAX - 1);
378 2031 av_store(o, PIT_ARENA, newSViv(PTR2IV(ar)));
379 2031 av_store(o, PIT_CAT, newSViv(idx));
380 2031 ▶ av_store(o, PIT_PREFIX, prefix ? newSVsv(prefix) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_store(o, PIT_PREFIX, prefix ? newSVsv(prefix) : newSV(0)); 8 2023 2031
381 2031 ▶ av_store(o, PIT_CFG, cfg ? newRV_inc((SV *)cfg) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_store(o, PIT_CFG, cfg ? newRV_inc((SV *)cfg) : newSV(0)); 2031 0 2031
382 2031 ▶ av_store(o, PIT_CTX, c ? newSVsv(c) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_store(o, PIT_CTX, c ? newSVsv(c) : newSV(0)); 2031 0 2031
383 2031 av_store(o, PIT_NODE, newSVuv((UV)node));
384 2031 av_store(o, PIT_DNODE, newSVuv((UV)dnode));
385 2031 av_store(o, PIT_ITER, newSViv(0));
386  
387 2031 obj = sv_bless(newRV_noinc((SV *)o),
388 gv_stashpv("Punk::Plugin::I18n::Cat", GV_ADD));
389 2031 hv_magic(h, (GV *)obj, PERL_MAGIC_tied);
390 2031 SvREFCNT_dec(obj); /* hv_magic took its own reference */
391 2031 return newRV_noinc((SV *)h);
392 }
393  
394 /* The i'th key of the node a tied hash is sitting on.
395 *
396 * Frozen sorts hash keys when it builds the block, so this order is stable
397 * and IDENTICAL in every process reading the same block. A Perl hash is
398 * neither, which is worth knowing before a template relies on it. */
399 60 static SV *pi_key_at(pTHX_ AV *o, uint32_t i) {
400 60 SV **arsv = av_fetch(o, PIT_ARENA, 0);
401 60 SV **idxs = av_fetch(o, PIT_CAT, 0);
402 60 SV **nds = av_fetch(o, PIT_NODE, 0);
403 60 ▶ pi_arena *ar = (arsv && *arsv) ? INT2PTR(pi_arena *, SvIV(*arsv)) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
pi_arena *ar = (arsv && *arsv) ? INT2PTR(pi_arena *, SvIV(*arsv)) : NULL; 60 0 60
pi_arena *ar = (arsv && *arsv) ? INT2PTR(pi_arena *, SvIV(*arsv)) : NULL; 60 0 60
404 60 ▶ int idx = (idxs && *idxs) ? (int)SvIV(*idxs) : -1;
Branch: 2 branches
BranchTrueFalseTotal
int idx = (idxs && *idxs) ? (int)SvIV(*idxs) : -1; 60 0 60
int idx = (idxs && *idxs) ? (int)SvIV(*idxs) : -1; 60 0 60
405 60 ▶ uint32_t node = (nds && *nds) ? (uint32_t)SvUV(*nds) : FZ_NOHANDLE;
Branch: 2 branches
BranchTrueFalseTotal
uint32_t node = (nds && *nds) ? (uint32_t)SvUV(*nds) : FZ_NOHANDLE; 60 0 60
uint32_t node = (nds && *nds) ? (uint32_t)SvUV(*nds) : FZ_NOHANDLE; 60 0 60
406 60 const char *k = NULL;
407 60 STRLEN kl = 0;
408 60 int u = 0;
409 SV *sv;
410  
411 60 ▶ if (!ar || idx < 0 || idx >= ar->ncat || node == FZ_NOHANDLE || !PUNK_FZ)
Branch: 5 branches
BranchTrueFalseTotal
if (!ar || idx < 0 || idx >= ar->ncat || node == FZ_NOHANDLE || !PUNK_FZ) 60 0 60
if (!ar || idx < 0 || idx >= ar->ncat || node == FZ_NOHANDLE || !PUNK_FZ) 60 0 60
if (!ar || idx < 0 || idx >= ar->ncat || node == FZ_NOHANDLE || !PUNK_FZ) 60 0 60
if (!ar || idx < 0 || idx >= ar->ncat || node == FZ_NOHANDLE || !PUNK_FZ) 59 1 60
if (!ar || idx < 0 || idx >= ar->ncat || node == FZ_NOHANDLE || !PUNK_FZ) 0 59 59
412 1 return newSV(0);
413 59 ▶ if (!(PUNK_FZ->key_at)(ar->cat[idx].fz, node, i, &k, &kl, &u))
Branch: 1 branch
BranchTrueFalseTotal
if (!(PUNK_FZ->key_at)(ar->cat[idx].fz, node, i, &k, &kl, &u)) 9 50 59
414 9 return newSV(0);
415 50 sv = newSVpvn(k, kl);
416 50 ▶ if (u) SvUTF8_on(sv);
Branch: 1 branch
BranchTrueFalseTotal
if (u) SvUTF8_on(sv); 0 50 50
417 50 return sv;
418 }
419  
420 2299 static pi_arena *pi_arena_of(pTHX_ HV *cfg) {
421 2299 ▶ SV **e = cfg ? hv_fetchs(cfg, "_arena", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **e = cfg ? hv_fetchs(cfg, "_arena", 0) : NULL; 2160 139 2299
422 2299 ▶ return (e && *e && SvIOK(*e)) ? INT2PTR(pi_arena *, SvIV(*e)) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return (e && *e && SvIOK(*e)) ? INT2PTR(pi_arena *, SvIV(*e)) : NULL; 2160 139 2299
return (e && *e && SvIOK(*e)) ? INT2PTR(pi_arena *, SvIV(*e)) : NULL; 2160 0 2160
return (e && *e && SvIOK(*e)) ? INT2PTR(pi_arena *, SvIV(*e)) : NULL; 2160 0 2160
423 }
424  
425 4314 static const char *pi_cfg_str(pTHX_ HV *cfg, const char *k, const char *dflt,
426 STRLEN *len) {
427 4314 ▶ SV **e = cfg ? hv_fetch(cfg, k, (I32)strlen(k), 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **e = cfg ? hv_fetch(cfg, k, (I32)strlen(k), 0) : NULL; 4314 0 4314
428 8628 ▶ if (e && *e && SvOK(*e)) return SvPV_const(*e, *len);
Branch: 3 branches
BranchTrueFalseTotal
if (e && *e && SvOK(*e)) return SvPV_const(*e, *len); 4314 0 4314
if (e && *e && SvOK(*e)) return SvPV_const(*e, *len); 4314 0 4314
if (e && *e && SvOK(*e)) return SvPV_const(*e, *len); 4314 0 4314
429 0 *len = strlen(dflt);
430 0 return dflt;
431 }
432  
433 /* One cookie's value out of a Cookie header, or NULL. Points into the
434 * header's own bytes. */
435 5 static const char *pi_cookie(const char *h, STRLEN hl, const char *n,
436 STRLEN nl, STRLEN *vl) {
437 5 STRLEN i = 0;
438 7 ▶ while (i < hl) {
Branch: 1 branch
BranchTrueFalseTotal
while (i < hl) { 6 1 7
439 STRLEN start, eq, end;
440 8 ▶ while (i < hl && (h[i] == ' ' || h[i] == ';' || h[i] == '\t')) i++;
Branch: 4 branches
BranchTrueFalseTotal
while (i < hl && (h[i] == ' ' || h[i] == ';' || h[i] == '\t')) i++; 8 0 8
while (i < hl && (h[i] == ' ' || h[i] == ';' || h[i] == '\t')) i++; 1 7 8
while (i < hl && (h[i] == ' ' || h[i] == ';' || h[i] == '\t')) i++; 1 6 7
while (i < hl && (h[i] == ' ' || h[i] == ';' || h[i] == '\t')) i++; 0 6 6
441 6 start = i;
442 57 ▶ while (i < hl && h[i] != '=' && h[i] != ';') i++;
Branch: 3 branches
BranchTrueFalseTotal
while (i < hl && h[i] != '=' && h[i] != ';') i++; 57 0 57
while (i < hl && h[i] != '=' && h[i] != ';') i++; 51 6 57
while (i < hl && h[i] != '=' && h[i] != ';') i++; 51 0 51
443 6 ▶ if (i >= hl || h[i] != '=') { while (i < hl && h[i] != ';') i++; continue; }
Branch: 4 branches
BranchTrueFalseTotal
if (i >= hl || h[i] != '=') { while (i < hl && h[i] != ';') i++; continue; } 6 0 6
if (i >= hl || h[i] != '=') { while (i < hl && h[i] != ';') i++; continue; } 0 6 6
if (i >= hl || h[i] != '=') { while (i < hl && h[i] != ';') i++; continue; } 0 0 0
if (i >= hl || h[i] != '=') { while (i < hl && h[i] != ';') i++; continue; } 0 0 0
444 6 eq = i++;
445 6 end = i;
446 17 ▶ while (end < hl && h[end] != ';') end++;
Branch: 2 branches
BranchTrueFalseTotal
while (end < hl && h[end] != ';') end++; 13 4 17
while (end < hl && h[end] != ';') end++; 11 2 13
447 6 ▶ if (eq - start == nl && memcmp(h + start, n, nl) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (eq - start == nl && memcmp(h + start, n, nl) == 0) { 4 2 6
if (eq - start == nl && memcmp(h + start, n, nl) == 0) { 4 0 4
448 4 *vl = end - i;
449 4 return h + i;
450 }
451 2 i = end;
452 }
453 1 return NULL;
454 }
455  
456 /* Resolve this request's catalogue, once, and remember it in the env.
457 *
458 * The env rather than a C static: Punk dispatches asynchronously through
459 * Punk::Future, so a worker can have several requests in flight at once and a
460 * "current locale" in a static would render one user's page in another user's
461 * language - invisibly, and only under load.
462 */
463 2160 static const pi_cat *pi_for_request(pTHX_ SV *c, HV *cfg, pi_arena *ar) {
464 AV *av;
465 SV *esv, **cached;
466 HV *env;
467 2160 const char *pp = NULL, *sp = NULL, *hp = NULL;
468 2160 STRLEN pl = 0, sl = 0, hl = 0;
469 2160 SV *pv = NULL;
470 pl_choice ch;
471  
472 2160 ▶ if (!ar || !ar->ncat) return NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (!ar || !ar->ncat) return NULL; 2160 0 2160
if (!ar || !ar->ncat) return NULL; 0 2160 2160
473 2160 av = pcx_av(aTHX_ c);
474 2160 ▶ if (!av) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!av) return NULL; 0 2160 2160
475 2160 esv = pcx_get(aTHX_ av, PCX_ENV);
476 2160 ▶ if (!(esv && SvROK(esv) && SvTYPE(SvRV(esv)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(esv && SvROK(esv) && SvTYPE(SvRV(esv)) == SVt_PVHV)) 2160 0 2160
if (!(esv && SvROK(esv) && SvTYPE(SvRV(esv)) == SVt_PVHV)) 2160 0 2160
if (!(esv && SvROK(esv) && SvTYPE(SvRV(esv)) == SVt_PVHV)) 0 2160 2160
477 0 ▶ return (ar->def >= 0) ? &ar->cat[ar->def] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return (ar->def >= 0) ? &ar->cat[ar->def] : NULL; 0 0 0
478 2160 env = (HV *)SvRV(esv);
479  
480 2160 cached = hv_fetchs(env, PL_ENV_KEY, 0);
481 2160 ▶ if (cached && *cached && SvIOK(*cached)) {
Branch: 3 branches
BranchTrueFalseTotal
if (cached && *cached && SvIOK(*cached)) { 3 2157 2160
if (cached && *cached && SvIOK(*cached)) { 3 0 3
if (cached && *cached && SvIOK(*cached)) { 3 0 3
482 3 IV i = SvIV(*cached);
483 3 ▶ if (i >= 0 && i < ar->ncat) return &ar->cat[i];
Branch: 2 branches
BranchTrueFalseTotal
if (i >= 0 && i < ar->ncat) return &ar->cat[i]; 3 0 3
if (i >= 0 && i < ar->ncat) return &ar->cat[i]; 3 0 3
484 }
485  
486 { /* 1. ?lang= */
487 STRLEN nl;
488 2157 const char *pname = pi_cfg_str(aTHX_ cfg, "param", "lang", &nl);
489 2157 SV *nsv = sv_2mortal(newSVpvn(pname, nl));
490 2157 pv = pcx_param(aTHX_ av, nsv);
491 2161 ▶ if (pv && SvOK(pv)) pp = SvPV_const(pv, pl);
Branch: 2 branches
BranchTrueFalseTotal
if (pv && SvOK(pv)) pp = SvPV_const(pv, pl); 4 2153 2157
if (pv && SvOK(pv)) pp = SvPV_const(pv, pl); 4 0 4
492 }
493 { /* 2. the stored choice */
494 STRLEN nl;
495 2157 const char *cname = pi_cfg_str(aTHX_ cfg, "cookie", "punk.lang", &nl);
496 2157 SV **ck = hv_fetchs(env, "HTTP_COOKIE", 0);
497 2157 ▶ if (ck && *ck && SvOK(*ck)) {
Branch: 3 branches
BranchTrueFalseTotal
if (ck && *ck && SvOK(*ck)) { 5 2152 2157
if (ck && *ck && SvOK(*ck)) { 5 0 5
if (ck && *ck && SvOK(*ck)) { 5 0 5
498 STRLEN chl;
499 5 const char *chp = SvPV_const(*ck, chl);
500 5 sp = pi_cookie(chp, chl, cname, nl, &sl);
501 }
502 }
503 { /* 3. Accept-Language */
504 2157 SV **al = hv_fetchs(env, "HTTP_ACCEPT_LANGUAGE", 0);
505 2221 ▶ if (al && *al && SvOK(*al)) hp = SvPV_const(*al, hl);
Branch: 3 branches
BranchTrueFalseTotal
if (al && *al && SvOK(*al)) hp = SvPV_const(*al, hl); 64 2093 2157
if (al && *al && SvOK(*al)) hp = SvPV_const(*al, hl); 64 0 64
if (al && *al && SvOK(*al)) hp = SvPV_const(*al, hl); 64 0 64
506 }
507  
508 2157 ch = pl_resolve(pp, pl, sp, sl, hp, hl, ar);
509 2157 ▶ if (ch.idx < 0) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (ch.idx < 0) return NULL; 0 2157 2157
510  
511 2157 (void)hv_stores(env, PL_ENV_KEY, newSViv(ch.idx));
512  
513 /* There was a second write here - PL_ENV_KEY "_set" - with a comment
514 * saying "the env flag is what the response path reads to decide whether
515 * to write the cookie". NOTHING EVER READ IT, and no code in this
516 * distribution has ever written a punk.lang cookie. The POD promised the
517 * feature and described its absence as a caveat.
518 *
519 * `ch.explicit_` stays, because it is the fact a future implementation
520 * would derive the decision from: it says the locale came from ?lang= or
521 * the cookie rather than from Accept-Language. Nothing consumes it today.
522 * Writing the cookie is a response-path change with its own SameSite,
523 * Secure, Max-Age and Path decisions, and it belongs in its own release
524 * where a bisect can see it. */
525 2157 return &ar->cat[ch.idx];
526 }
527  
528 /* Put this request's catalogue into the variables a template is about to be
529 * rendered with, so `{% locale.welcome %}` works with nothing passed by the
530 * handler.
531 *
532 * SET, not set-if-absent, for the reason CSP gives about its nonce: a handler
533 * rendering with a hashref it keeps between requests would otherwise serve
534 * the first request's language for ever, and a page in the wrong language
535 * looks like a page, which is the failure nobody reports. */
536 2162 static void pi_bind_vars(pTHX_ SV *c, SV *data) {
537 2162 HV *cfg = pi_cfg_of(aTHX_ c);
538 2162 pi_arena *ar = pi_arena_of(aTHX_ cfg);
539 const pi_cat *cat;
540  
541 2162 ▶ if (!ar) return; /* the plugin is not registered */
Branch: 1 branch
BranchTrueFalseTotal
if (!ar) return; /* the plugin is not registered */ 139 2023 2162
542 2023 ▶ if (!(data && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV)) return;
Branch: 3 branches
BranchTrueFalseTotal
if (!(data && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV)) return; 2023 0 2023
if (!(data && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV)) return; 2023 0 2023
if (!(data && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV)) return; 0 2023 2023
543  
544 2023 cat = pi_for_request(aTHX_ c, cfg, ar);
545 2023 ▶ if (!cat) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!cat) return; 0 2023 2023
546  
547 /* SET, not set-if-absent, for the reason CSP gives about its nonce: a
548 * handler rendering with a hashref it keeps between requests would
549 * otherwise serve the first request's language for ever, and a page in
550 * the wrong language still looks like a page. */
551 {
552 2023 ▶ const pi_cat *d = (ar->def >= 0) ? &ar->cat[ar->def] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const pi_cat *d = (ar->def >= 0) ? &ar->cat[ar->def] : NULL; 2023 0 2023
553 2023 ▶ (void)hv_stores((HV *)SvRV(data), "locale",
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores((HV *)SvRV(data), "locale", 2023 0 2023
554 pi_tied_hash(aTHX_ ar, (int)(cat - ar->cat), NULL,
555 cfg, c, cat->node,
556 d ? d->node : FZ_NOHANDLE));
557 }
558 }
559  
560 #endif /* PUNK_LANG_H */
« include/punk/punk_headers.h ↑ Summary xs/csp.xs »