xs/compile.xs

filter: Statementstmt 97.9% 698 / 713 Branchbran 60.8% 655 / 1072 (7 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 75.6% 1353 / 1785 (7 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_ua.h ↑ Summary xs/scope.xs »
1 MODULE = Punk PACKAGE = Punk::App
2  
3 PROTOTYPES: DISABLE
4  
5 # The boot compiler, in C (punk_compile.h). compile() freezes the registrar's
6 # accumulation into the state hash punk_serve.h reads and returns the PSGI app;
7 # the resolver, the docs targets, the app itself and the nonblocking Future
8 # chain are all real closures built with the magic-CV primitive.
9  
10 SV *
11 _resolve_target(self, target, what = &PL_sv_undef)
12 SV *self
13 SV *target
14 SV *what
15 CODE:
16 61930 RETVAL = pc_resolve_target(aTHX_ self, target, what);
17 OUTPUT:
18 RETVAL
19  
20 SV *
21 # uncoverable statement
22 # uncoverable subroutine
23 _context_class(self)
24 SV *self
25 CODE:
26 0 RETVAL = pc_context_class(aTHX_ self); /* # uncoverable statement */
27 OUTPUT:
28 RETVAL
29  
30 SV *
31 # uncoverable statement
32 # uncoverable subroutine
33 _db_opts_for(self, class)
34 SV *self
35 SV *class
36 CODE:
37 0 RETVAL = pc_db_opts_for(aTHX_ self, class); /* # uncoverable statement */
38 OUTPUT:
39 RETVAL
40  
41 void
42 _compile_models(self)
43 SV *self
44 CODE:
45 5 pc_compile_models(aTHX_ self);
46  
47 SV *
48 # uncoverable statement
49 # uncoverable subroutine
50 _docs_routes(self, api_mounts)
51 SV *self
52 SV *api_mounts
53 CODE:
54 {
55 0 ▶ AV *am = (SvROK(api_mounts) && SvTYPE(SvRV(api_mounts)) == SVt_PVAV) /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
AV *am = (SvROK(api_mounts) && SvTYPE(SvRV(api_mounts)) == SVt_PVAV) /* # uncoverable statement */ 0 0 0
56 0 ▶ ? (AV *)SvRV(api_mounts) : NULL; /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(api_mounts) : NULL; /* # uncoverable statement */ 0 0 0
57 0 RETVAL = newRV_inc((SV *)pc_docs_routes(aTHX_ self, am)); /* # uncoverable statement */
58 }
59 OUTPUT:
60 RETVAL
61  
62 # The per-worker model instance: built on first use, cached until the pid
63 # changes (fork-safe).
64 SV *
65 model_instance(self, name)
66 SV *self
67 SV *name
68 CODE:
69 {
70 158 HV *h = app_hv(aTHX_ self);
71 158 STRLEN nl; const char *n = SvPV_const(name, nl);
72 158 SV **regp = hv_fetchs(h, K_MODELS_C, 0);
73 HV *reg, *cache; SV **classp, **cachep, **pidp, **inst;
74 158 IV pid = (IV)PerlProc_getpid();
75 158 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 157 1 158
# uncoverable condition left count:2 class:ignore_covered_err 157 0 157
# uncoverable condition left count:2 class:ignore_covered_err 0 157 157
76 1 # uncoverable condition left count:3 class:ignore_covered_err
77 157 if (!(regp && *regp && SvROK(*regp)))
78 157 croak("Punk: no model registered - add database/model keywords");
79 157 ▶ reg = (HV *)SvRV(*regp);
Branch: 3 branches
BranchTrueFalseTotal
reg = (HV *)SvRV(*regp); 155 2 157
reg = (HV *)SvRV(*regp); 155 0 155
reg = (HV *)SvRV(*regp); 0 155 155
80 2 classp = hv_fetch(reg, n, (I32)nl, 0);
81 2 # uncoverable condition left count:2 class:ignore_covered_err
82 7 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 5 2 7
83 5 ▶ if (!(classp && *classp && SvOK(*classp))) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(classp && *classp && SvOK(*classp))) { 3 2 5
84 5 AV *keys = app_sorted_keys(aTHX_ reg);
85 SV *have = sv_2mortal(newSVpvs("")); SSize_t i, m = av_len(keys) + 1;
86 2 for (i = 0; i < m; i++) {
87 if (i) sv_catpvs(have, ", ");
88 sv_catsv(have, *av_fetch(keys, i, 0));
89 155 }
90 155 ▶ croak("Punk: no model '%s' registered (have: %s)", n,
Branch: 3 branches
BranchTrueFalseTotal
croak("Punk: no model '%s' registered (have: %s)", n, 123 32 155
croak("Punk: no model '%s' registered (have: %s)", n, 123 0 123
croak("Punk: no model '%s' registered (have: %s)", n, 123 0 123
91 SvPV_nolen(have));
92 32 }
93 32 cachep = hv_fetchs(h, K_MODEL_CACHE, 0);
94 32 # uncoverable condition right count:2 class:ignore_covered_err
95 # uncoverable condition right count:3 class:ignore_covered_err
96 155 if (cachep && *cachep && SvROK(*cachep)) cache = (HV *)SvRV(*cachep);
97 155 ▶ else {
Branch: 3 branches
BranchTrueFalseTotal
else { 155 0 155
else { 155 0 155
else { 36 119 155
98 36 cache = newHV();
99 36 (void)hv_stores(cache, K_PID, newSViv(-1));
100 (void)hv_stores(h, K_MODEL_CACHE, newRV_noinc((SV *)cache));
101 155 }
102 155 ▶ pidp = hv_fetchs(cache, K_PID, 0);
Branch: 3 branches
BranchTrueFalseTotal
pidp = hv_fetchs(cache, K_PID, 0); 111 44 155
pidp = hv_fetchs(cache, K_PID, 0); 111 0 111
pidp = hv_fetchs(cache, K_PID, 0); 111 0 111
103 # uncoverable condition left count:1 class:ignore_covered_err
104 44 # uncoverable condition left count:2 class:ignore_covered_err
105 if (!(pidp && *pidp && SvIV(*pidp) == pid)) {
106 43 hv_clear(cache);
107 43 (void)hv_stores(cache, K_PID, newSViv(pid));
108 43 }
109 43 ▶ inst = hv_fetch(cache, n, (I32)nl, 0);
Branch: 1 branch
BranchTrueFalseTotal
inst = hv_fetch(cache, n, (I32)nl, 0); 43 0 43
110 # uncoverable condition right count:2 class:ignore_covered_err
111 43 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 0 43 43
112 if (inst && *inst && SvTRUE(*inst)) RETVAL = newSVsv(*inst);
113 else {
114 SV *opts = pc_db_opts_for(aTHX_ self, *classp);
115 SV *argv[2], *obj;
116 argv[0] = sv_2mortal(opts);
117 argv[1] = self;
118 obj = pcx_call_meth(aTHX_ *classp, "_instantiate", argv, 2, 1);
119 (void)hv_store(cache, n, (I32)nl,
120 obj ? SvREFCNT_inc(obj) : newSV(0), 0);
121 RETVAL = obj ? obj : newSV(0); /* # uncoverable condition left count:1 class:ignore_covered_err */
122 }
123 }
124 OUTPUT:
125 RETVAL
126  
127 # $self->render_view($c, @args) -> the view engine's finished response.
128 SV *
129 render_view(self, ...)
130 SV *self
131 CODE:
132 {
133 2176 HV *h = app_hv(aTHX_ self);
134 2176 SV **vc = hv_fetchs(h, K_VIEWS_C, 0);
135 2176 int nargs = items - 1, i;
136 SV **argv;
137 2176 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 2176 0 2176
# uncoverable condition left count:1 class:ignore_covered_err 2176 0 2176
# uncoverable condition left count:1 class:ignore_covered_err 1 2175 2176
138 1 # uncoverable condition left count:2 class:ignore_covered_err
139 2175 ▶ if (!(vc && *vc && SvOK(*vc)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(vc && *vc && SvOK(*vc))) 2175 0 2175
140 6638 ▶ croak("Punk: no view engine configured - add a views keyword");
Branch: 1 branch
BranchTrueFalseTotal
croak("Punk: no view engine configured - add a views keyword"); 4463 2175 6638
141 2175 Newx(argv, nargs > 0 ? nargs : 1, SV *); /* # uncoverable condition right count:1 class:ignore_covered_err */
142 2166 for (i = 0; i < nargs; i++) argv[i] = ST(i + 1);
143 2166 ▶ RETVAL = pcx_call_meth(aTHX_ *vc, "render", argv, nargs, 1);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = pcx_call_meth(aTHX_ *vc, "render", argv, nargs, 1); 0 2166 2166
144 Safefree(argv);
145 # uncoverable branch true
146 # uncoverable condition left count:1 class:ignore_covered_err
147 if (!RETVAL) RETVAL = newSV(0);
148 }
149 OUTPUT:
150 RETVAL
151  
152 # $on_error->($c,$err) coerced, or the 500 default.
153 SV *
154 # uncoverable statement
155 # uncoverable subroutine
156 _handle_error(self, c, err, on_error = &PL_sv_undef)
157 SV *self
158 SV *c
159 SV *err
160 SV *on_error
161 CODE:
162 PERL_UNUSED_VAR(self);
163 0 ▶ # uncoverable statement
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable statement 0 0 0
164 # uncoverable condition left count:1
165 # uncoverable condition right count:1
166 RETVAL = punk_handle_error(aTHX_ c, err, SvOK(on_error) ? on_error : NULL);
167 OUTPUT:
168 RETVAL
169  
170 # The one Perl-shaped piece of the finish path: a handler that returned a
171 # Future. On a nonblocking server hand back the ->then chain (built as two
172 # magic-CV closures); otherwise await it and finish inline.
173 SV *
174 _finish_future(self, c, ret, on_error = &PL_sv_undef, method = &PL_sv_undef, after = &PL_sv_undef)
175 SV *self
176 SV *c
177 SV *ret
178 SV *on_error
179 SV *method
180 SV *after
181 CODE:
182 {
183 51 AV *cav = pcx_av(aTHX_ c);
184 51 SV *envsv = pcx_get(aTHX_ cav, PCX_ENV);
185 51 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 51 0 51
# uncoverable condition right count:1 class:ignore_covered_err 51 0 51
186 51 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 51 0 51
187 51 ▶ HV *env = (envsv && SvROK(envsv)) ? (HV *)SvRV(envsv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *env = (envsv && SvROK(envsv)) ? (HV *)SvRV(envsv) : NULL; 51 0 51
188 51 ▶ SV **nb = env ? hv_fetchs(env, "psgi.nonblocking", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 3 branches
BranchTrueFalseTotal
SV **nb = env ? hv_fetchs(env, "psgi.nonblocking", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 20 31 51
SV **nb = env ? hv_fetchs(env, "psgi.nonblocking", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 20 0 20
SV **nb = env ? hv_fetchs(env, "psgi.nonblocking", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 20 0 20
189 51 ▶ SV **st = env ? hv_fetchs(env, "psgi.streaming", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 3 branches
BranchTrueFalseTotal
SV **st = env ? hv_fetchs(env, "psgi.streaming", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 9 42 51
SV **st = env ? hv_fetchs(env, "psgi.streaming", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 9 0 9
SV **st = env ? hv_fetchs(env, "psgi.streaming", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 9 0 9
190 51 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 51 0 51
191 102 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 51 0 51
# uncoverable condition right count:3 class:ignore_covered_err 50 1 51
192 int nonblocking = (nb && *nb && SvTRUE(*nb));
193 59 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 20 31 51
# uncoverable condition right count:2 class:ignore_covered_err 20 0 20
# uncoverable condition right count:2 class:ignore_covered_err 8 12 20
194 # uncoverable condition right count:3 class:ignore_covered_err
195 int streaming = (st && *st && SvTRUE(*st));
196 int can_then = (SvROK(ret) && SvOBJECT(SvRV(ret))
197 8 && pcx_can(aTHX_ ret, "then"));
198 8 PERL_UNUSED_VAR(self);
199 8 if (nonblocking && can_then && streaming) { /* # uncoverable condition right count:2 class:ignore_covered_err */
200 8 ▶ /* the standard delayed response: middleware between Punk and the
Branch: 1 branch
BranchTrueFalseTotal
/* the standard delayed response: middleware between Punk and the 0 8 8
201 8 * server (plackup's Lint, this app's own `middleware`) passes a
202 8 ▶ * coderef through where a raw Future would kill the request */
Branch: 1 branch
BranchTrueFalseTotal
* coderef through where a raw Future would kill the request */ 8 0 8
203 AV *cap = newAV();
204 8 av_push(cap, newSVsv(c));
205 av_push(cap, newSVsv(ret));
206 av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
207 av_push(cap, newSVsv(method));
208 av_push(cap, SvOK(after) ? newSVsv(after) /* # uncoverable condition right count:1 class:ignore_covered_err */
209 : newRV_noinc((SV *)newAV()));
210 RETVAL = punk_closure(aTHX_ pc_ffs_cb, cap);
211 49 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
} 12 31 43
} 12 0 12
} 6 6 12
212 6 /* One of ours: the class is known, so the two probes above and the
213 * method call below are all answers we already have. Chain it in C -
214 6 * one closure and one capture instead of three of each. A subclass
215 6 * misses the stash compare and takes the general path, which is
216 6 * slower and correct. */
217 6 ▶ else if (nonblocking && can_then && pcx_is_punk_future(aTHX_ ret)) { /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
else if (nonblocking && can_then && pcx_is_punk_future(aTHX_ ret)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 0 6 6
218 6 AV *cap = newAV();
219 6 ▶ SV *clos;
Branch: 1 branch
BranchTrueFalseTotal
SV *clos; 6 0 6
220 punk_future *pg = pf_new(aTHX);
221 6 RETVAL = pf_bless(aTHX_ pg, "Punk::Future");
222 6 av_push(cap, newSVsv(c));
223 6 av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
224 av_push(cap, newSVsv(method));
225 43 ▶ av_push(cap, SvOK(after) ? newSVsv(after) /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
av_push(cap, SvOK(after) ? newSVsv(after) /* # uncoverable condition right count:1 class:ignore_covered_err */ 6 31 37
av_push(cap, SvOK(after) ? newSVsv(after) /* # uncoverable condition right count:1 class:ignore_covered_err */ 6 0 6
226 6 : newRV_noinc((SV *)newAV()));
227 av_push(cap, newSVsv(RETVAL));
228 clos = sv_2mortal(punk_closure(aTHX_ pc_ff_both_cb, cap));
229 pf_react(aTHX_ pf_of(aTHX_ ret), ret, PFR_ON_READY, clos);
230 }
231 else if (nonblocking && can_then) { /* # uncoverable condition right count:2 class:ignore_covered_err */
232 AV *cd = newAV(), *cf = newAV();
233 SV *done, *fail, *argv[2];
234 int j;
235 6 ▶ /* Does the app's future come from CPAN's Future? Then its `then`
Branch: 2 branches
BranchTrueFalseTotal
/* Does the app's future come from CPAN's Future? Then its `then` 6 0 6
/* Does the app's future come from CPAN's Future? Then its `then` 6 0 6
236 18 ▶ * requires the callback to hand back a Future, and older
Branch: 1 branch
BranchTrueFalseTotal
* requires the callback to hand back a Future, and older 12 6 18
237 12 ▶ * releases enforce that strictly (CPAN Testers, 0.16, perls
Branch: 1 branch
BranchTrueFalseTotal
* releases enforce that strictly (CPAN Testers, 0.16, perls 6 6 12
238 12 * 5.20/5.22/5.24). Punk::Future's `then` takes the value
239 12 ▶ * directly and has no class-level `done` to wrap with, so the
Branch: 1 branch
BranchTrueFalseTotal
* directly and has no class-level `done` to wrap with, so the 0 12 12
240 12 * two are told apart once, here, rather than per callback. */
241 12 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 12 0 12
242 # uncoverable condition right count:2 class:ignore_covered_err
243 12 int wrap = (SvROK(ret) && sv_derived_from(ret, "Future"));
244 for (j = 0; j < 2; j++) {
245 6 AV *cap = j ? cf : cd;
246 6 av_push(cap, newSVsv(c));
247 6 av_push(cap, SvOK(on_error) ? newSVsv(on_error) : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
248 6 av_push(cap, newSVsv(method));
249 6 ▶ av_push(cap, SvOK(after) ? newSVsv(after) /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
av_push(cap, SvOK(after) ? newSVsv(after) /* # uncoverable condition right count:1 class:ignore_covered_err */ 0 6 6
250 : newRV_noinc((SV *)newAV()));
251 av_push(cap, newSViv(wrap));
252 31 }
253 31 done = sv_2mortal(punk_closure(aTHX_ pc_ff_done_cb, cd));
254 31 fail = sv_2mortal(punk_closure(aTHX_ pc_ff_fail_cb, cf));
255 31 ▶ argv[0] = done; argv[1] = fail;
Branch: 2 branches
BranchTrueFalseTotal
argv[0] = done; argv[1] = fail; 0 31 31
argv[0] = done; argv[1] = fail; 0 31 31
256 31 RETVAL = pcx_call_meth(aTHX_ ret, "then", argv, 2, 1);
257 31 # uncoverable branch true
258 31 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 31 0 31
259 31 ▶ if (!RETVAL) RETVAL = &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) RETVAL = &PL_sv_undef; 31 0 31
260 31 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
} 31 0 31
261 31 else {
262 8 ▶ dSP; int count; SV *got, *resp; int died, is_head;
Branch: 1 branch
BranchTrueFalseTotal
dSP; int count; SV *got, *resp; int died, is_head; 8 0 8
263 8 ▶ AV *aft = pc_after_of(aTHX_ after);
Branch: 1 branch
BranchTrueFalseTotal
AV *aft = pc_after_of(aTHX_ after); 1 7 8
264 31 ▶ ENTER; SAVETMPS;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; 8 23 31
265 31 PUSHMARK(SP); EXTEND(SP, 1); PUSHs(ret); PUTBACK;
266 31 count = call_method("get", G_SCALAR | G_EVAL);
267 31 ▶ SPAGAIN;
Branch: 1 branch
BranchTrueFalseTotal
SPAGAIN; 23 8 31
268 got = count > 0 ? SvREFCNT_inc(POPs) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */
269 PUTBACK; FREETMPS; LEAVE;
270 died = SvTRUE(ERRSV) ? 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
271 is_head = pc_is_head(aTHX_ method);
272 resp = died ? punk_handle_error(aTHX_ c, ERRSV, /* # uncoverable condition right count:1 class:ignore_covered_err */
273 SvOK(on_error) ? on_error : NULL)
274 : punk_coerce(aTHX_ c, got);
275 RETVAL = punk_deliver(aTHX_ c, resp, is_head, aft);
276 SvREFCNT_dec(resp);
277 if (got != &PL_sv_undef) SvREFCNT_dec(got);
278 }
279 }
280 OUTPUT:
281 RETVAL
282  
283 # compile(): resolve and freeze everything into the state hash and return the
284 # PSGI app (a magic-CV closure over the state).
285 SV *
286 compile(self)
287 SV *self
288 CODE:
289 {
290 898 HV *h = app_hv(aTHX_ self);
291 898 SV *caller = app_get(aTHX_ h, K_CALLER);
292 898 AV *rcap = newAV();
293  
294 /* The on_compile callbacks, FIRST: every keyword has recorded and
295 * nothing is compiled yet, so a callback may still use the registrar
296 * - read the databases, add a route, a hook or a helper - and what
297 * it adds is compiled below with the rest. In registration order; a
298 * die is this boot croak, naming the owner. */
299 {
300 898 SV **lp = hv_fetchs(h, K_ON_COMPILE, 0);
301 898 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 6 892 898
# uncoverable condition right count:2 class:ignore_covered_err 6 0 6
# uncoverable condition right count:2 class:ignore_covered_err 6 0 6
# uncoverable condition right count:2 class:ignore_covered_err 6 0 6
302 6 # uncoverable condition right count:3 class:ignore_covered_err
303 6 # uncoverable condition right count:4 class:ignore_covered_err
304 11 ▶ if (lp && *lp && SvROK(*lp) && SvTYPE(SvRV(*lp)) == SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
if (lp && *lp && SvROK(*lp) && SvTYPE(SvRV(*lp)) == SVt_PVAV) { 7 4 11
305 7 AV *list = (AV *)SvRV(*lp);
306 SSize_t i, n = av_len(list) + 1;
307 7 for (i = 0; i < n; i++) {
308 7 ▶ SV **rp = av_fetch(list, i, 0);
Branch: 3 branches
BranchTrueFalseTotal
SV **rp = av_fetch(list, i, 0); 7 0 7
SV **rp = av_fetch(list, i, 0); 7 0 7
SV **rp = av_fetch(list, i, 0); 0 7 7
309 7 AV *rec; SV **code, **owner;
310 7 dSP; int count;
311 7 # uncoverable branch true
312 7 # uncoverable condition left count:1 class:ignore_covered_err
313 7 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 0 7 7
314 7 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 0 7 7
315 7 if (!(rp && *rp && SvROK(*rp))) continue;
316 7 rec = (AV *)SvRV(*rp);
317 7 code = av_fetch(rec, 0, 0);
318 7 owner = av_fetch(rec, 1, 0);
319 7 ENTER; SAVETMPS;
320 7 ▶ PUSHMARK(SP);
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); 7 0 7
PUSHMARK(SP); 2 5 7
321 XPUSHs(self);
322 PUTBACK;
323 count = call_sv(*code, G_VOID | G_EVAL);
324 2 ▶ SPAGAIN;
Branch: 1 branch
BranchTrueFalseTotal
SPAGAIN; 2 0 2
325 2 ▶ SP -= count;
Branch: 1 branch
BranchTrueFalseTotal
SP -= count; 2 0 2
326 2 PUTBACK;
327 4 ▶ if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 2 0 2
if (SvTRUE(ERRSV)) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 2 0 2
328 /* copied BEFORE the frame closes, made mortal AFTER:
329 * a mortal made inside the frame is freed by this
330 * FREETMPS before croak reads it */
331 5 ▶ SV *e = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *e = newSVsv(ERRSV); 3 2 5
332 FREETMPS; LEAVE;
333 sv_2mortal(e);
334 croak("Punk: on_compile callback registered by %s died: %s",
335 owner && *owner ? SvPV_nolen(*owner) : "?",
336 SvPV_nolen(e));
337 }
338 FREETMPS; LEAVE;
339 }
340 }
341 }
342  
343 /* Register the cross-worker bus subscription for every worker.
344 *
345 896 * HERE, at compile, because this runs in the PARENT before the server
346 * forks - which is the only place a registration can be made that
347 * every worker will inherit. The callback itself runs after the fork,
348 * on the process that will serve, which is the only place a
349 * subscription can usefully live.
350 *
351 * A no-op when there is no Hyperman, or one too old for the bus. */
352 punk_bus_register(aTHX);
353 896  
354 896 ▶ /* The cache stores, built HERE so a bad backend name, an
Branch: 3 branches
BranchTrueFalseTotal
/* The cache stores, built HERE so a bad backend name, an 64 832 896
/* The cache stores, built HERE so a bad backend name, an 64 0 64
/* The cache stores, built HERE so a bad backend name, an 64 0 64
355 64 ▶ * unparseable max_bytes or an unwritable directory croak at boot
Branch: 1 branch
BranchTrueFalseTotal
* unparseable max_bytes or an unwritable directory croak at boot 64 0 64
356 64 * rather than on the first miss - and so every request on this
357 64 * worker shares one store per name, since a cache constructed per
358 * request never hits. */
359 64 {
360 129 ▶ SV **spec = hv_fetchs(h, "cache_spec", 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **spec = hv_fetchs(h, "cache_spec", 0); 68 61 129
361 68 # uncoverable condition right count:2 class:ignore_covered_err
362 68 # uncoverable condition right count:3 class:ignore_covered_err
363 68 # uncoverable condition right count:4 class:ignore_covered_err
364 if (spec && *spec && SvROK(*spec)
365 68 ▶ && SvTYPE(SvRV(*spec)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
&& SvTYPE(SvRV(*spec)) == SVt_PVHV) { 68 0 68
&& SvTYPE(SvRV(*spec)) == SVt_PVHV) { 68 0 68
366 68 ▶ HV *specs = (HV *)SvRV(*spec);
Branch: 2 branches
BranchTrueFalseTotal
HV *specs = (HV *)SvRV(*spec); 68 0 68
HV *specs = (HV *)SvRV(*spec); 68 0 68
367 HV *built = newHV();
368 HE *e;
369 hv_iterinit(specs);
370 while ((e = hv_iternext(specs))) {
371 68 AV *rec = (AV *)SvRV(HeVAL(e));
372 68 SV **backend = av_fetch(rec, 0, 0);
373 68 SV **opts = av_fetch(rec, 1, 0);
374 SV *argv[3], *store;
375 # uncoverable condition right count:1 class:ignore_covered_err
376 65 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 0 65 65
377 argv[0] = backend && *backend ? *backend : &PL_sv_undef;
378 # uncoverable condition right count:1 class:ignore_covered_err
379 61 # uncoverable condition right count:2 class:ignore_covered_err
380 argv[1] = opts && *opts ? *opts : &PL_sv_undef;
381 /* The NAME as well. Without it the store cannot address
382 * its own invalidation topic, and cross-worker
383 * invalidation is silently off in the only case that
384 * matters - the one configured by the keyword. */
385 argv[2] = sv_2mortal(newSVsv(hv_iterkeysv(e)));
386 (void)pk_require_once(aTHX_ "Punk::Cache", TRUE);
387 store = pcx_call_meth(aTHX_
388 sv_2mortal(newSVpvs("Punk::Cache")),
389 893 "_from_spec", argv, 3, 1);
390 (void)hv_store_ent(built, hv_iterkeysv(e),
391 store ? store : newSV(0), 0);
392 }
393 881 (void)hv_stores(h, "cache", newRV_noinc((SV *)built));
394 881 }
395 881 }
396 881  
397 881 /* A server-side session resolves HERE, after those stores exist,
398 881 * because `session store => 'sessions'` names one of them. Going
399 * first would find an empty hash and every declared store would look
400 * like a typo. A bad backend, an undeclared name or a store that is
401 * not shared between workers croak at boot, in front of whoever
402 * deployed it, rather than as a random logout later. */
403 881 ps_store_resolve(aTHX_ h);
404 881  
405 SV *resolve, *router, *xs_router, *all_recs, *ctx, *app_cv, *state_rv;
406 HV *state;
407 881 ▶ AV *api_src = app_av(aTHX_ h, K_API_MOUNTS);
Branch: 1 branch
BranchTrueFalseTotal
AV *api_src = app_av(aTHX_ h, K_API_MOUNTS); 881 0 881
408 912 ▶ AV *api_mounts = (AV *)sv_2mortal((SV *)newAV());
Branch: 1 branch
BranchTrueFalseTotal
AV *api_mounts = (AV *)sv_2mortal((SV *)newAV()); 33 879 912
409 33 AV *state_apims = newAV();
410 33 ▶ AV *mounts_out = newAV();
Branch: 2 branches
BranchTrueFalseTotal
AV *mounts_out = newAV(); 33 0 33
AV *mounts_out = newAV(); 33 0 33
411 AV *before_out = newAV(), *after_out = newAV();
412 33 AV *before_req_out = newAV();
413 33 AV *docs_extra, *mount_src, *mw;
414 31 ▶ SSize_t i, n;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i, n; 0 31 31
415 31 SV **x;
416 31  
417 31 av_push(rcap, newSVsv(self));
418 31 resolve = sv_2mortal(punk_closure(aTHX_ pc_resolve_cb, rcap));
419 31 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
31 0 31
420 /* api mounts: compile each, wrap as {mount,prefix,len}, order longest */
421 31 n = api_src ? av_len(api_src) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
422 for (i = 0; i < n; i++) {
423 879 ▶ SV **mp = av_fetch(api_src, i, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **mp = av_fetch(api_src, i, 0); 29 850 879
424 29 # uncoverable condition right count:1 class:ignore_covered_err
425 # uncoverable condition right count:2 class:ignore_covered_err
426 SV *m = (mp && *mp) ? *mp : &PL_sv_undef;
427 SV *argv[2], *pfx; HV *rec;
428 879 argv[0] = self; argv[1] = resolve;
429 875 { SV *r = pcx_call_meth(aTHX_ m, "compile", argv, 2, 0);
430 # uncoverable branch true
431 # uncoverable condition left count:1 class:ignore_covered_err
432 875 if (r) SvREFCNT_dec(r); }
433 875 pfx = sv_2mortal(pcx_call_meth(aTHX_ m, K_PREFIX, NULL, 0, 1));
434 875 rec = newHV();
435 (void)hv_stores(rec, K_MOUNT, newSVsv(m));
436 (void)hv_stores(rec, K_PREFIX, newSVsv(pfx));
437 858 (void)hv_stores(rec, K_LEN,
438 newSViv(SvOK(pfx) ? (IV)SvCUR(pfx) : 0));
439 858 av_push(api_mounts, newRV_noinc((SV *)rec));
440 }
441 if (av_len(api_mounts) >= 0)
442 858 sortsv(AvARRAY(api_mounts), (STRLEN)(av_len(api_mounts) + 1),
443 858 ▶ pc_cmp_len_desc);
Branch: 4 branches
BranchTrueFalseTotal
pc_cmp_len_desc); 40 818 858
pc_cmp_len_desc); 40 0 40
pc_cmp_len_desc); 40 0 40
pc_cmp_len_desc); 40 0 40
444 40  
445 40 /* router: compile with the docs routes folded in; take its records */
446 40 ▶ docs_extra = pc_docs_routes(aTHX_ self, api_mounts);
Branch: 2 branches
BranchTrueFalseTotal
docs_extra = pc_docs_routes(aTHX_ self, api_mounts); 40 0 40
docs_extra = pc_docs_routes(aTHX_ self, api_mounts); 40 0 40
447 40 router = app_get(aTHX_ h, K_ROUTER);
448 40 {
449 40 SV *argv[2];
450 135 ▶ argv[0] = resolve;
Branch: 1 branch
BranchTrueFalseTotal
argv[0] = resolve; 95 40 135
451 95 argv[1] = sv_2mortal(newRV_inc((SV *)docs_extra));
452 95 xs_router = sv_2mortal(pcx_call_meth(aTHX_ router, "compile",
453 95 argv, 2, 1));
454 95 ▶ }
Branch: 2 branches
BranchTrueFalseTotal
} 95 0 95
} 95 0 95
455 95 ▶ all_recs = sv_2mortal(pcx_call_meth(aTHX_ xs_router, "records",
Branch: 2 branches
BranchTrueFalseTotal
all_recs = sv_2mortal(pcx_call_meth(aTHX_ xs_router, "records", 95 0 95
all_recs = sv_2mortal(pcx_call_meth(aTHX_ xs_router, "records", 95 0 95
456 NULL, 0, 1));
457 95 ▶ ctx = sv_2mortal(pc_context_class(aTHX_ self));
Branch: 4 branches
BranchTrueFalseTotal
ctx = sv_2mortal(pc_context_class(aTHX_ self)); 95 0 95
ctx = sv_2mortal(pc_context_class(aTHX_ self)); 95 0 95
ctx = sv_2mortal(pc_context_class(aTHX_ self)); 95 0 95
ctx = sv_2mortal(pc_context_class(aTHX_ self)); 95 0 95
458 95  
459 95 ▶ /* websocket routes: mark the records, check the server can upgrade */
Branch: 3 branches
BranchTrueFalseTotal
/* websocket routes: mark the records, check the server can upgrade */ 43 52 95
/* websocket routes: mark the records, check the server can upgrade */ 43 0 43
/* websocket routes: mark the records, check the server can upgrade */ 43 0 43
460 x = hv_fetchs(h, K_WS_ROUTES, 0);
461 # uncoverable condition right count:2 class:ignore_covered_err
462 40 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 40 0 40
463 245 ▶ # uncoverable condition right count:4 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:4 class:ignore_covered_err 205 40 245
464 205 if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) {
465 205 AV *wsr = (AV *)SvRV(*x);
466 205 HV *wsmap = (HV *)sv_2mortal((SV *)newHV());
467 # uncoverable condition right count:1 class:ignore_covered_err
468 410 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 205 0 205
# uncoverable condition right count:2 class:ignore_covered_err 205 0 205
# uncoverable condition right count:2 class:ignore_covered_err 45 160 205
469 160 ▶ AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 160 0 160
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 160 0 160
470 160 ▶ SSize_t wi, wn = av_len(wsr) + 1;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t wi, wn = av_len(wsr) + 1; 95 65 160
471 int any_blocking = 0, ok;
472 40 (void)pk_require_once(aTHX_ PK_WEBSOCKET, TRUE);
473 40 ▶ for (wi = 0; wi < wn; wi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (wi = 0; wi < wn; wi++) { 0 40 40
474 40 HV *w = (HV *)SvRV(*av_fetch(wsr, wi, 0));
475 40 SV **pp = hv_fetchs(w, K_PATH, 0);
476 40 ▶ SV **op = hv_fetchs(w, K_OPTS, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **op = hv_fetchs(w, K_OPTS, 0); 40 0 40
477 40 ▶ # uncoverable branch false
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch false 40 0 40
478 40 # uncoverable condition right count:1 class:ignore_covered_err
479 40 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 0 40 40
# uncoverable condition right count:2 class:ignore_covered_err 0 0 0
480 0 if (pp && *pp)
481 (void)hv_store_ent(wsmap, *pp,
482 newSVsv(op && *op ? *op : &PL_sv_undef), 0);
483 # uncoverable branch false
484 # uncoverable condition right count:1 class:ignore_covered_err
485 # uncoverable condition right count:2 class:ignore_covered_err
486 # uncoverable condition right count:3 class:ignore_covered_err
487 # uncoverable condition right count:4 class:ignore_covered_err
488 if (op && *op && SvROK(*op) && SvTYPE(SvRV(*op)) == SVt_PVHV) {
489 SV **b = hv_fetchs((HV *)SvRV(*op), K_BLOCKING, 0);
490 858 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 858 0 858
# uncoverable condition right count:2 class:ignore_covered_err 858 0 858
491 # uncoverable condition right count:3 class:ignore_covered_err
492 858 if (b && *b && SvTRUE(*b)) any_blocking = 1;
493 858 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
} 30 828 858
} 30 0 30
} 30 0 30
} 30 0 30
494 30 }
495 30 n = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
496 67 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 37 30 67
497 37 HV *rr = (HV *)SvRV(*av_fetch(recs, i, 0));
498 37 SV **meth = hv_fetchs(rr, K_METHOD, 0);
499 37 SV **pth = hv_fetchs(rr, K_PATH, 0);
500 37 HE *he;
501 37 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 37 0 37
502 37 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 6 branches
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 37 0 37
# uncoverable condition left count:2 class:ignore_covered_err 37 0 37
# uncoverable condition left count:2 class:ignore_covered_err 37 0 37
# uncoverable condition left count:2 class:ignore_covered_err 37 0 37
# uncoverable condition left count:2 class:ignore_covered_err 37 0 37
# uncoverable condition left count:2 class:ignore_covered_err 0 37 37
503 158 ▶ if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; 121 37 158
504 121 # uncoverable condition right count:1 class:ignore_covered_err
505 121 # uncoverable condition right count:2 class:ignore_covered_err
506 121 he = pth && *pth ? hv_fetch_ent(wsmap, *pth, 0, 0) : NULL;
507 121 ▶ if (he) (void)hv_stores(rr, K_WS, newSVsv(HeVAL(he)));
Branch: 4 branches
BranchTrueFalseTotal
if (he) (void)hv_stores(rr, K_WS, newSVsv(HeVAL(he))); 121 0 121
if (he) (void)hv_stores(rr, K_WS, newSVsv(HeVAL(he))); 121 0 121
if (he) (void)hv_stores(rr, K_WS, newSVsv(HeVAL(he))); 121 0 121
if (he) (void)hv_stores(rr, K_WS, newSVsv(HeVAL(he))); 121 0 121
508 121 ▶ }
Branch: 2 branches
BranchTrueFalseTotal
} 88 33 121
} 37 51 88
509 37 { dSP; int c2;
510 PUSHMARK(SP);
511 c2 = call_pv(PK_WEBSOCKET "::_hm_available", G_SCALAR);
512 SPAGAIN;
513 ok = c2 > 0 ? SvTRUE(TOPs) : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
514 # uncoverable branch false
515 # uncoverable condition right count:1 class:ignore_covered_err
516 if (c2 > 0) (void)POPs;
517 PUTBACK; }
518 # uncoverable branch true
519 858 # uncoverable condition left count:1 class:ignore_covered_err
520 858 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 858 0 858
# uncoverable condition left count:2 class:ignore_covered_err 858 0 858
521 858 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 3 855 858
# uncoverable condition right count:2 class:ignore_covered_err 3 0 3
# uncoverable condition right count:2 class:ignore_covered_err 3 0 3
# uncoverable condition right count:2 class:ignore_covered_err 3 0 3
522 3 if (!ok && !any_blocking)
523 3 croak("Punk: websocket routes need Hyperman 0.11 or later " /* # uncoverable statement */
524 9 ▶ "(for its detach ABI), or blocking => 1 on the route "
Branch: 1 branch
BranchTrueFalseTotal
"(for its detach ABI), or blocking => 1 on the route " 6 3 9
525 6 "for other PSGI servers that provide psgix.io");
526 6 }
527 6  
528 6 ▶ { /* max_body: the app-wide ceiling into the compiled state, and
Branch: 1 branch
BranchTrueFalseTotal
{ /* max_body: the app-wide ceiling into the compiled state, and 6 0 6
529 6 ▶ * the per-route overrides stamped onto their records. A route's
Branch: 4 branches
BranchTrueFalseTotal
* the per-route overrides stamped onto their records. A route's 6 0 6
* the per-route overrides stamped onto their records. A route's 6 0 6
* the per-route overrides stamped onto their records. A route's 6 0 6
* the per-route overrides stamped onto their records. A route's 0 6 6
530 28 ▶ * own value wins, including 0, which legitimately means "do not
Branch: 1 branch
BranchTrueFalseTotal
* own value wins, including 0, which legitimately means "do not 22 6 28
531 22 * check here" - unlike the server's ceiling, this one is policy
532 22 * and not the memory backstop. */
533 22 # uncoverable condition right count:1 class:ignore_covered_err
534 22 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 22 0 22
# uncoverable condition right count:2 class:ignore_covered_err 22 0 22
# uncoverable condition right count:2 class:ignore_covered_err 22 0 22
# uncoverable condition right count:2 class:ignore_covered_err 22 0 22
535 22 ▶ AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 15 7 22
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 6 9 15
536 6 {
537 SV **mr = hv_fetchs(h, K_MAXBODY_ROUTES, 0);
538 # uncoverable condition right count:2 class:ignore_covered_err
539 # uncoverable condition right count:3 class:ignore_covered_err
540 # uncoverable condition right count:4 class:ignore_covered_err
541 if (mr && *mr && SvROK(*mr) && SvTYPE(SvRV(*mr)) == SVt_PVAV) {
542 AV *mrr = (AV *)SvRV(*mr);
543 SSize_t mi, mn = av_len(mrr) + 1;
544 for (mi = 0; mi < mn; mi++) {
545 858 HV *w = (HV *)SvRV(*av_fetch(mrr, mi, 0));
546 858 ▶ SV **wm = hv_fetchs(w, K_METHOD, 0);
Branch: 2 branches
BranchTrueFalseTotal
SV **wm = hv_fetchs(w, K_METHOD, 0); 858 0 858
SV **wm = hv_fetchs(w, K_METHOD, 0); 858 0 858
547 858 ▶ SV **wp = hv_fetchs(w, K_PATH, 0);
Branch: 4 branches
BranchTrueFalseTotal
SV **wp = hv_fetchs(w, K_PATH, 0); 20 838 858
SV **wp = hv_fetchs(w, K_PATH, 0); 20 0 20
SV **wp = hv_fetchs(w, K_PATH, 0); 20 0 20
SV **wp = hv_fetchs(w, K_PATH, 0); 20 0 20
548 20 SV **wv = hv_fetchs(w, K_MAX_BODY, 0);
549 20 SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
550 63 ▶ # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch true 43 20 63
551 43 # uncoverable condition left count:1 class:ignore_covered_err
552 43 # uncoverable condition left count:2 class:ignore_covered_err
553 43 # uncoverable condition left count:3 class:ignore_covered_err
554 43 # uncoverable condition left count:4 class:ignore_covered_err
555 43 ▶ # uncoverable condition left count:5 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:5 class:ignore_covered_err 43 0 43
556 43 ▶ # uncoverable condition left count:6 class:ignore_covered_err
Branch: 6 branches
BranchTrueFalseTotal
# uncoverable condition left count:6 class:ignore_covered_err 43 0 43
# uncoverable condition left count:6 class:ignore_covered_err 43 0 43
# uncoverable condition left count:6 class:ignore_covered_err 43 0 43
# uncoverable condition left count:6 class:ignore_covered_err 43 0 43
# uncoverable condition left count:6 class:ignore_covered_err 43 0 43
# uncoverable condition left count:6 class:ignore_covered_err 0 43 43
557 234 ▶ if (!(wm && *wm && wp && *wp && wv && *wv)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!(wm && *wm && wp && *wp && wv && *wv)) continue; 191 43 234
558 191 for (ri = 0; ri < rn; ri++) {
559 191 HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0));
560 191 SV **rm = hv_fetchs(rr, K_METHOD, 0);
561 191 ▶ SV **rp = hv_fetchs(rr, K_PATH, 0);
Branch: 4 branches
BranchTrueFalseTotal
SV **rp = hv_fetchs(rr, K_PATH, 0); 191 0 191
SV **rp = hv_fetchs(rr, K_PATH, 0); 191 0 191
SV **rp = hv_fetchs(rr, K_PATH, 0); 191 0 191
SV **rp = hv_fetchs(rr, K_PATH, 0); 191 0 191
562 191 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 180 11 191
# uncoverable condition right count:1 class:ignore_covered_err 43 137 180
563 43 # uncoverable condition right count:2 class:ignore_covered_err
564 # uncoverable condition right count:3 class:ignore_covered_err
565 # uncoverable condition right count:4 class:ignore_covered_err
566 if (rm && *rm && rp && *rp
567 && sv_eq(*rm, *wm) && sv_eq(*rp, *wp))
568 (void)hv_stores(rr, K_MAX_BODY, newSVsv(*wv));
569 }
570 858 }
571 858 ▶ }
Branch: 2 branches
BranchTrueFalseTotal
} 858 0 858
} 858 0 858
572 858 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
} 3 855 858
} 3 0 3
} 3 0 3
} 3 0 3
573 3 }
574 3  
575 10 ▶ { /* compress => 0 routes: stamp the compiled record, the same way
Branch: 1 branch
BranchTrueFalseTotal
{ /* compress => 0 routes: stamp the compiled record, the same way 7 3 10
576 7 * ws and sse are stamped. punk_serve then adds the header on the
577 7 * way out, where it knows which route answered. */
578 7 SV **nc = hv_fetchs(h, K_NOCOMPRESS_ROUTES, 0);
579 7 # uncoverable condition right count:1 class:ignore_covered_err
580 7 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 7 0 7
581 7 ▶ AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
Branch: 6 branches
BranchTrueFalseTotal
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 7 0 7
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 7 0 7
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 7 0 7
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 7 0 7
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 7 0 7
AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL; 0 7 7
582 41 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 34 7 41
583 34 # uncoverable condition right count:3 class:ignore_covered_err
584 34 # uncoverable condition right count:4 class:ignore_covered_err
585 34 if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) {
586 34 ▶ AV *ncr = (AV *)SvRV(*nc);
Branch: 4 branches
BranchTrueFalseTotal
AV *ncr = (AV *)SvRV(*nc); 34 0 34
AV *ncr = (AV *)SvRV(*nc); 34 0 34
AV *ncr = (AV *)SvRV(*nc); 34 0 34
AV *ncr = (AV *)SvRV(*nc); 34 0 34
587 34 ▶ SSize_t ci, cn = av_len(ncr) + 1;
Branch: 2 branches
BranchTrueFalseTotal
SSize_t ci, cn = av_len(ncr) + 1; 34 0 34
SSize_t ci, cn = av_len(ncr) + 1; 7 27 34
588 7 for (ci = 0; ci < cn; ci++) {
589 HV *w = (HV *)SvRV(*av_fetch(ncr, ci, 0));
590 SV **wm = hv_fetchs(w, K_METHOD, 0);
591 SV **wp = hv_fetchs(w, K_PATH, 0);
592 SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
593 # uncoverable branch true
594 # uncoverable condition left count:1 class:ignore_covered_err
595 858 # uncoverable condition left count:2 class:ignore_covered_err
596 858 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 858 0 858
# uncoverable condition left count:3 class:ignore_covered_err 858 0 858
597 858 ▶ # uncoverable condition left count:4 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition left count:4 class:ignore_covered_err 30 828 858
# uncoverable condition left count:4 class:ignore_covered_err 30 0 30
# uncoverable condition left count:4 class:ignore_covered_err 30 0 30
# uncoverable condition left count:4 class:ignore_covered_err 30 0 30
598 30 if (!(wm && *wm && wp && *wp)) continue;
599 30 for (ri = 0; ri < rn; ri++) {
600 70 ▶ HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0));
Branch: 1 branch
BranchTrueFalseTotal
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 40 30 70
601 40 SV **rm = hv_fetchs(rr, K_METHOD, 0);
602 40 SV **rp = hv_fetchs(rr, K_PATH, 0);
603 40 # uncoverable condition right count:1 class:ignore_covered_err
604 40 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 40 0 40
605 40 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 40 0 40
# uncoverable condition right count:3 class:ignore_covered_err 40 0 40
# uncoverable condition right count:3 class:ignore_covered_err 40 0 40
# uncoverable condition right count:3 class:ignore_covered_err 0 40 40
606 139 ▶ # uncoverable condition right count:4 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:4 class:ignore_covered_err 99 40 139
607 99 if (rm && *rm && rp && *rp
608 99 && sv_eq(*rm, *wm) && sv_eq(*rp, *wp))
609 99 (void)hv_stores(rr, K_COMPRESS, newSViv(0));
610 99 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
} 99 0 99
} 99 0 99
} 99 0 99
} 99 0 99
611 99 ▶ }
Branch: 2 branches
BranchTrueFalseTotal
} 86 13 99
} 40 46 86
612 40 }
613 }
614  
615 { /* etag routes: stamp the validator onto the compiled record, so
616 * the dispatcher finds it beside `guards` and `code` rather than
617 * looking anything up per request. Same walk as compress. */
618 SV **ec = hv_fetchs(h, K_ETAG_ROUTES, 0);
619 # uncoverable condition right count:1 class:ignore_covered_err
620 # uncoverable condition right count:2 class:ignore_covered_err
621 AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
622 # uncoverable condition right count:2 class:ignore_covered_err
623 # uncoverable condition right count:3 class:ignore_covered_err
624 # uncoverable condition right count:4 class:ignore_covered_err
625 if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) {
626 858 AV *ecr = (AV *)SvRV(*ec);
627 858 ▶ SSize_t ci, cn = av_len(ecr) + 1;
Branch: 2 branches
BranchTrueFalseTotal
SSize_t ci, cn = av_len(ecr) + 1; 858 0 858
SSize_t ci, cn = av_len(ecr) + 1; 858 0 858
628 858 for (ci = 0; ci < cn; ci++) {
629 858 ▶ HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0));
Branch: 4 branches
BranchTrueFalseTotal
HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0)); 48 810 858
HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0)); 48 0 48
HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0)); 48 0 48
HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0)); 48 0 48
630 48 SV **wm = hv_fetchs(w, K_METHOD, 0);
631 48 SV **wp = hv_fetchs(w, K_PATH, 0);
632 135 ▶ SV **wv = hv_fetchs(w, K_ETAG, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **wv = hv_fetchs(w, K_ETAG, 0); 87 48 135
633 87 SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
634 87 # uncoverable branch true
635 87 # uncoverable condition left count:1 class:ignore_covered_err
636 87 # uncoverable condition left count:2 class:ignore_covered_err
637 87 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 87 0 87
638 87 ▶ # uncoverable condition left count:4 class:ignore_covered_err
Branch: 6 branches
BranchTrueFalseTotal
# uncoverable condition left count:4 class:ignore_covered_err 87 0 87
# uncoverable condition left count:4 class:ignore_covered_err 87 0 87
# uncoverable condition left count:4 class:ignore_covered_err 87 0 87
# uncoverable condition left count:4 class:ignore_covered_err 87 0 87
# uncoverable condition left count:4 class:ignore_covered_err 87 0 87
# uncoverable condition left count:4 class:ignore_covered_err 0 87 87
639 492 ▶ # uncoverable condition left count:5 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:5 class:ignore_covered_err 405 87 492
640 405 # uncoverable condition left count:6 class:ignore_covered_err
641 405 if (!(wm && *wm && wp && *wp && wv && *wv)) continue;
642 405 for (ri = 0; ri < rn; ri++) {
643 405 ▶ HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0));
Branch: 4 branches
BranchTrueFalseTotal
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 405 0 405
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 405 0 405
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 405 0 405
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 405 0 405
644 405 ▶ SV **rm = hv_fetchs(rr, K_METHOD, 0);
Branch: 2 branches
BranchTrueFalseTotal
SV **rm = hv_fetchs(rr, K_METHOD, 0); 354 51 405
SV **rm = hv_fetchs(rr, K_METHOD, 0); 87 267 354
645 87 SV **rp = hv_fetchs(rr, K_PATH, 0);
646 # uncoverable condition right count:1 class:ignore_covered_err
647 # uncoverable condition right count:2 class:ignore_covered_err
648 # uncoverable condition right count:3 class:ignore_covered_err
649 # uncoverable condition right count:4 class:ignore_covered_err
650 if (rm && *rm && rp && *rp
651 858 ▶ && sv_eq(*rm, *wm) && sv_eq(*rp, *wp))
Branch: 1 branch
BranchTrueFalseTotal
&& sv_eq(*rm, *wm) && sv_eq(*rp, *wp)) 858 0 858
652 62664 ▶ (void)hv_stores(rr, K_ETAG, newSVsv(*wv));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(rr, K_ETAG, newSVsv(*wv)); 61809 855 62664
653 61809 }
654 61809 }
655 }
656 61809 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
} 87 61722 61809
} 87 0 87
} 0 87 87
657 87  
658 87 ▶ { /* last_modified routes: stamp the validator, the etag walk */
Branch: 1 branch
BranchTrueFalseTotal
{ /* last_modified routes: stamp the validator, the etag walk */ 3 84 87
659 3 SV **ec = hv_fetchs(h, K_LM_ROUTES, 0);
660 # uncoverable condition right count:1 class:ignore_covered_err
661 3 # uncoverable condition right count:2 class:ignore_covered_err
662 3 AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
663 3 # uncoverable condition right count:2 class:ignore_covered_err
664 3 # uncoverable condition right count:3 class:ignore_covered_err
665 3 # uncoverable condition right count:4 class:ignore_covered_err
666 18 ▶ if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) {
Branch: 8 branches
BranchTrueFalseTotal
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
if (ec && *ec && SvROK(*ec) && SvTYPE(SvRV(*ec)) == SVt_PVAV) { 3 0 3
667 AV *ecr = (AV *)SvRV(*ec);
668 SSize_t ci, cn = av_len(ecr) + 1;
669 for (ci = 0; ci < cn; ci++) {
670 HV *w = (HV *)SvRV(*av_fetch(ecr, ci, 0));
671 SV **wm = hv_fetchs(w, K_METHOD, 0);
672 SV **wp = hv_fetchs(w, K_PATH, 0);
673 SV **wv = hv_fetchs(w, K_LAST_MODIFIED, 0);
674 SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
675 84 # uncoverable branch true
676 # uncoverable condition left count:1 class:ignore_covered_err
677 # uncoverable condition left count:2 class:ignore_covered_err
678 # uncoverable condition left count:3 class:ignore_covered_err
679 # uncoverable condition left count:4 class:ignore_covered_err
680 # uncoverable condition left count:5 class:ignore_covered_err
681 # uncoverable condition left count:6 class:ignore_covered_err
682 if (!(wm && *wm && wp && *wp && wv && *wv)) continue;
683 for (ri = 0; ri < rn; ri++) {
684 HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0));
685 SV **rm = hv_fetchs(rr, K_METHOD, 0);
686 SV **rp = hv_fetchs(rr, K_PATH, 0);
687 # uncoverable condition right count:1 class:ignore_covered_err
688 # uncoverable condition right count:2 class:ignore_covered_err
689 # uncoverable condition right count:3 class:ignore_covered_err
690 # uncoverable condition right count:4 class:ignore_covered_err
691 # uncoverable condition right count:5 class:ignore_covered_err
692 if (rm && *rm && rp && *rp
693 && sv_eq(*rm, *wm) && sv_eq(*rp, *wp))
694 (void)hv_stores(rr, K_LAST_MODIFIED, newSVsv(*wv));
695 }
696 }
697 }
698 855 }
699 882 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
28 854 882
700 28 { /* idempotent routes: stamp the record, the same walk as etag */
701 28 SV **ic = hv_fetchs(h, K_IDEM_ROUTES, 0);
702 28 # uncoverable condition right count:1 class:ignore_covered_err
703 # uncoverable condition right count:2 class:ignore_covered_err
704 AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
705 # uncoverable condition right count:2 class:ignore_covered_err
706 28 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 28 0 28
# uncoverable condition right count:3 class:ignore_covered_err 0 28 28
707 28 # uncoverable condition right count:4 class:ignore_covered_err
708 if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVAV) {
709 28 ▶ AV *icr = (AV *)SvRV(*ic);
Branch: 3 branches
BranchTrueFalseTotal
AV *icr = (AV *)SvRV(*ic); 28 0 28
AV *icr = (AV *)SvRV(*ic); 28 0 28
AV *icr = (AV *)SvRV(*ic); 0 28 28
710 28 SSize_t ci, cn = av_len(icr) + 1;
711 for (ci = 0; ci < cn; ci++) {
712 28 ▶ HV *w = (HV *)SvRV(*av_fetch(icr, ci, 0));
Branch: 3 branches
BranchTrueFalseTotal
HV *w = (HV *)SvRV(*av_fetch(icr, ci, 0)); 28 0 28
HV *w = (HV *)SvRV(*av_fetch(icr, ci, 0)); 28 0 28
HV *w = (HV *)SvRV(*av_fetch(icr, ci, 0)); 0 28 28
713 0 SV **wm = hv_fetchs(w, K_METHOD, 0);
714 28 SV **wp = hv_fetchs(w, K_PATH, 0);
715 28 SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
716 95 ▶ # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch true 68 27 95
717 68 # uncoverable condition left count:1 class:ignore_covered_err
718 # uncoverable condition left count:2 class:ignore_covered_err
719 # uncoverable condition left count:3 class:ignore_covered_err
720 # uncoverable condition left count:4 class:ignore_covered_err
721 if (!(wm && *wm && wp && *wp)) continue;
722 for (ri = 0; ri < rn; ri++) {
723 68 ▶ HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0));
Branch: 3 branches
BranchTrueFalseTotal
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 68 0 68
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 68 0 68
HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0)); 68 0 68
724 68 ▶ SV **rm = hv_fetchs(rr, K_METHOD, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **rm = hv_fetchs(rr, K_METHOD, 0); 0 68 68
725 68 SV **rp = hv_fetchs(rr, K_PATH, 0);
726 68 # uncoverable condition right count:1 class:ignore_covered_err
727 68 # uncoverable condition right count:2 class:ignore_covered_err
728 68 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 68 0 68
# uncoverable condition right count:3 class:ignore_covered_err 68 0 68
# uncoverable condition right count:3 class:ignore_covered_err 68 0 68
# uncoverable condition right count:3 class:ignore_covered_err 68 0 68
729 68 ▶ # uncoverable condition right count:4 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:4 class:ignore_covered_err 68 0 68
# uncoverable condition right count:4 class:ignore_covered_err 68 0 68
# uncoverable condition right count:4 class:ignore_covered_err 0 68 68
730 68 ▶ if (rm && *rm && rp && *rp
Branch: 1 branch
BranchTrueFalseTotal
if (rm && *rm && rp && *rp 1 67 68
731 1 && sv_eq(*rm, *wm) && sv_eq(*rp, *wp))
732 1 ▶ (void)hv_stores(rr, K_IDEMPOTENT, newSViv(1));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(rr, K_IDEMPOTENT, newSViv(1)); 0 1 1
733 0 }
734 }
735 }
736 }
737  
738 { /* named routes: stamp the name onto the compiled record (the
739 1 * etag walk), then resolve the whole set into ONE name ->
740 * record index table.
741 1 *
742 1 * The table is the one namespace for the application: a plugin
743 5 ▶ * that takes `index` has taken it from the application, and a
Branch: 8 branches
BranchTrueFalseTotal
* that takes `index` has taken it from the application, and a 1 0 1
* that takes `index` has taken it from the application, and a 1 0 1
* that takes `index` has taken it from the application, and a 1 0 1
* that takes `index` has taken it from the application, and a 1 0 1
* that takes `index` has taken it from the application, and a 1 0 1
* that takes `index` has taken it from the application, and a 1 0 1
* that takes `index` has taken it from the application, and a 1 0 1
* that takes `index` has taken it from the application, and a 1 0 1
744 * duplicate croaks here naming BOTH routes, because the person
745 * reading it wants to know which one to rename. */
746 SV **nc = hv_fetchs(h, K_NAMED_ROUTES, 0);
747 # uncoverable condition right count:1 class:ignore_covered_err
748 # uncoverable condition right count:2 class:ignore_covered_err
749 AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
750 HV *names = newHV();
751 # uncoverable condition right count:2 class:ignore_covered_err
752 # uncoverable condition right count:3 class:ignore_covered_err
753 # uncoverable condition right count:4 class:ignore_covered_err
754 if (nc && *nc && SvROK(*nc) && SvTYPE(SvRV(*nc)) == SVt_PVAV) {
755 67 AV *ncr = (AV *)SvRV(*nc);
756 67 SSize_t ci, cn = av_len(ncr) + 1;
757 67 ▶ for (ci = 0; ci < cn; ci++) {
Branch: 2 branches
BranchTrueFalseTotal
for (ci = 0; ci < cn; ci++) { 67 0 67
for (ci = 0; ci < cn; ci++) { 67 0 67
758 67 HV *w = (HV *)SvRV(*av_fetch(ncr, ci, 0));
759 SV **wm = hv_fetchs(w, K_METHOD, 0);
760 67 SV **wp = hv_fetchs(w, K_PATH, 0);
761 SV **wv = hv_fetchs(w, K_NAME, 0);
762 SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
763 # uncoverable branch true
764 # uncoverable condition left count:1 class:ignore_covered_err
765 854 # uncoverable condition left count:2 class:ignore_covered_err
766 # uncoverable condition left count:3 class:ignore_covered_err
767 # uncoverable condition left count:4 class:ignore_covered_err
768 # uncoverable condition left count:5 class:ignore_covered_err
769 # uncoverable condition left count:6 class:ignore_covered_err
770 if (!(wm && *wm && wp && *wp && wv && *wv)) continue;
771 for (ri = 0; ri < rn; ri++) {
772 HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0));
773 SV **rm = hv_fetchs(rr, K_METHOD, 0);
774 SV **rp = hv_fetchs(rr, K_PATH, 0);
775 # uncoverable condition right count:1 class:ignore_covered_err
776 # uncoverable condition right count:2 class:ignore_covered_err
777 # uncoverable condition right count:3 class:ignore_covered_err
778 # uncoverable condition right count:4 class:ignore_covered_err
779 if (rm && *rm && rp && *rp
780 854 && sv_eq(*rm, *wm) && sv_eq(*rp, *wp))
781 854 ▶ (void)hv_stores(rr, K_NAME, newSVsv(*wv));
Branch: 3 branches
BranchTrueFalseTotal
(void)hv_stores(rr, K_NAME, newSVsv(*wv)); 25 829 854
(void)hv_stores(rr, K_NAME, newSVsv(*wv)); 25 0 25
(void)hv_stores(rr, K_NAME, newSVsv(*wv)); 25 0 25
782 }
783 25 }
784 25 }
785 25 { /* one pass over the records, in declaration order, so the
786 25 ▶ * route the croak calls "already" is the earlier one */
Branch: 1 branch
BranchTrueFalseTotal
* route the croak calls "already" is the earlier one */ 3 22 25
787 3 SSize_t ri, rn = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
788 for (ri = 0; ri < rn; ri++) {
789 25 HV *rr = (HV *)SvRV(*av_fetch(recs, ri, 0));
790 SV **nm = hv_fetchs(rr, K_NAME, 0);
791 HE *he;
792 # uncoverable condition left count:2 class:ignore_covered_err
793 # uncoverable condition left count:3 class:ignore_covered_err
794 if (!(nm && *nm && SvOK(*nm))) continue;
795 he = hv_fetch_ent(names, *nm, 0, 0);
796 854 if (he) {
797 854 ▶ HV *first = (HV *)SvRV(*av_fetch(recs,
Branch: 4 branches
BranchTrueFalseTotal
HV *first = (HV *)SvRV(*av_fetch(recs, 30 824 854
HV *first = (HV *)SvRV(*av_fetch(recs, 30 0 30
HV *first = (HV *)SvRV(*av_fetch(recs, 30 0 30
HV *first = (HV *)SvRV(*av_fetch(recs, 30 0 30
798 30 (SSize_t)SvIV(HeVAL(he)), 0));
799 30 SV **fm = hv_fetchs(first, K_METHOD, 0);
800 30 ▶ SV **fp = hv_fetchs(first, K_PATH, 0);
Branch: 2 branches
BranchTrueFalseTotal
SV **fp = hv_fetchs(first, K_PATH, 0); 30 0 30
SV **fp = hv_fetchs(first, K_PATH, 0); 30 0 30
801 30 SV **rm = hv_fetchs(rr, K_METHOD, 0);
802 65 ▶ SV **rp = hv_fetchs(rr, K_PATH, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **rp = hv_fetchs(rr, K_PATH, 0); 35 30 65
803 35 SvREFCNT_dec((SV *)names);
804 35 croak("Punk: route name '%s' is declared twice: "
805 35 "%s %s and %s %s - a name is one route, and "
806 35 ▶ "url_for would have had to choose",
Branch: 2 branches
BranchTrueFalseTotal
"url_for would have had to choose", 35 0 35
"url_for would have had to choose", 35 0 35
807 35 ▶ SvPV_nolen(*nm),
Branch: 2 branches
BranchTrueFalseTotal
SvPV_nolen(*nm), 35 0 35
SvPV_nolen(*nm), 35 0 35
808 fm && *fm ? SvPV_nolen(*fm) : "?",
809 fp && *fp ? SvPV_nolen(*fp) : "?",
810 30 ▶ rm && *rm ? SvPV_nolen(*rm) : "?",
Branch: 1 branch
BranchTrueFalseTotal
rm && *rm ? SvPV_nolen(*rm) : "?", 30 0 30
811 172 ▶ rp && *rp ? SvPV_nolen(*rp) : "?");
Branch: 1 branch
BranchTrueFalseTotal
rp && *rp ? SvPV_nolen(*rp) : "?"); 142 30 172
812 142 }
813 142 (void)hv_store_ent(names, *nm, newSViv((IV)ri), 0);
814 142 }
815 }
816 284 ▶ { /* The API mount is a routing table too.
Branch: 3 branches
BranchTrueFalseTotal
{ /* The API mount is a routing table too. 142 0 142
{ /* The API mount is a routing table too. 142 0 142
{ /* The API mount is a routing table too. 28 114 142
817 114 ▶ *
Branch: 2 branches
BranchTrueFalseTotal
* 114 0 114
* 114 0 114
818 114 ▶ * An operation has an operationId and a path template with
Branch: 1 branch
BranchTrueFalseTotal
* An operation has an operationId and a path template with 35 79 114
819 * {holes} - a named route by another spelling - so an
820 * application with an `api` keyword would be half-named
821 * without this. They go into the SAME table: one namespace
822 * for the whole application, and a route named like an
823 * operation is a duplicate like any other.
824 854 *
825 * The value is a REFERENCE where a route's is an integer,
826 * which is how url_for tells the two apart: [ mount prefix,
827 * parsed template ].
828 *
829 * operationIds are NOT held to the route-name identifier
830 854 * rule.
831 934 ▶ * They are the spec's, and a spec may say `get-book` or
Branch: 1 branch
BranchTrueFalseTotal
* They are the spec's, and a spec may say `get-book` or 80 854 934
832 80 * `book.get`; those are callable from url_for as whatever
833 * they are, and simply absent from the template `url` hash,
834 * which the documentation says. It is the spec's choice,
835 * not Punk's. */
836 80 ▶ SSize_t mi, mn = av_len(api_mounts) + 1;
Branch: 3 branches
BranchTrueFalseTotal
SSize_t mi, mn = av_len(api_mounts) + 1; 80 0 80
SSize_t mi, mn = av_len(api_mounts) + 1; 80 0 80
SSize_t mi, mn = av_len(api_mounts) + 1; 0 80 80
837 80 for (mi = 0; mi < mn; mi++) {
838 80 HV *mrec = (HV *)SvRV(*av_fetch(api_mounts, mi, 0));
839 80 SV **msv = hv_fetchs(mrec, K_MOUNT, 0);
840 80 ▶ SV **psv = hv_fetchs(mrec, K_PREFIX, 0);
Branch: 3 branches
BranchTrueFalseTotal
SV **psv = hv_fetchs(mrec, K_PREFIX, 0); 80 0 80
SV **psv = hv_fetchs(mrec, K_PREFIX, 0); 80 0 80
SV **psv = hv_fetchs(mrec, K_PREFIX, 0); 0 80 80
841 SV *apio, *ops;
842 AV *opav;
843 SSize_t oi, on;
844 # uncoverable branch true
845 80 # uncoverable condition left count:1 class:ignore_covered_err
846 65 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 0 65 65
847 145 ▶ if (!(msv && *msv)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!(msv && *msv)) continue; 65 15 80
if (!(msv && *msv)) continue; 0 15 15
if (!(msv && *msv)) continue; 0 0 0
848 80 ▶ apio = sv_2mortal(pcx_call_meth(aTHX_ *msv, "api",
Branch: 1 branch
BranchTrueFalseTotal
apio = sv_2mortal(pcx_call_meth(aTHX_ *msv, "api", 15 65 80
849 NULL, 0, 1));
850 65 ▶ # uncoverable branch true
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable branch true 65 0 65
# uncoverable branch true 65 0 65
# uncoverable branch true 65 0 65
851 65 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 0 65 65
852 65 # uncoverable condition left count:2 class:ignore_covered_err
853 # uncoverable condition left count:3 class:ignore_covered_err
854 65 if (!(apio && SvOK(apio) && SvROK(apio))) continue;
855 65 ▶ ops = sv_2mortal(pcx_call_meth(aTHX_ apio, "operations",
Branch: 3 branches
BranchTrueFalseTotal
ops = sv_2mortal(pcx_call_meth(aTHX_ apio, "operations", 4 61 65
ops = sv_2mortal(pcx_call_meth(aTHX_ apio, "operations", 4 0 4
ops = sv_2mortal(pcx_call_meth(aTHX_ apio, "operations", 4 0 4
856 4 ▶ NULL, 0, 1));
Branch: 1 branch
BranchTrueFalseTotal
NULL, 0, 1)); 4 0 4
857 4 # uncoverable branch true
858 # uncoverable condition left count:1 class:ignore_covered_err
859 61 # uncoverable condition left count:2 class:ignore_covered_err
860 61 # uncoverable condition left count:3 class:ignore_covered_err
861 if (!(ops && SvROK(ops) && SvTYPE(SvRV(ops)) == SVt_PVAV))
862 continue; /* # uncoverable statement */
863 opav = (AV *)SvRV(ops);
864 65 ▶ on = av_len(opav) + 1;
Branch: 1 branch
BranchTrueFalseTotal
on = av_len(opav) + 1; 64 1 65
865 64 for (oi = 0; oi < on; oi++) {
866 SV **e = av_fetch(opav, oi, 0);
867 HV *op;
868 SV **id, **pth;
869 STRLEN tl;
870 const char *tp;
871 AV *pair;
872 # uncoverable branch true
873 65 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 64 1 65
874 64 # uncoverable condition left count:2 class:ignore_covered_err
875 64 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 0 64 64
876 64 ▶ # uncoverable condition left count:4 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:4 class:ignore_covered_err 64 0 64
877 64 if (!(e && *e && SvROK(*e)
878 64 && SvTYPE(SvRV(*e)) == SVt_PVHV)) continue;
879 op = (HV *)SvRV(*e);
880 64 id = hv_fetchs(op, "operationId", 0);
881 pth = hv_fetchs(op, "path", 0);
882 # uncoverable branch true
883 # uncoverable condition left count:1 class:ignore_covered_err
884 # uncoverable condition left count:2 class:ignore_covered_err
885 854 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 77 777 854
886 # uncoverable condition left count:4 class:ignore_covered_err
887 77 # uncoverable condition left count:5 class:ignore_covered_err
888 77 # uncoverable condition left count:6 class:ignore_covered_err
889 77 # uncoverable condition left count:7 class:ignore_covered_err
890 if (!(id && *id && SvOK(*id) && SvCUR(*id)
891 72 ▶ && pth && *pth && SvOK(*pth))) continue;
Branch: 1 branch
BranchTrueFalseTotal
&& pth && *pth && SvOK(*pth))) continue; 0 72 72
892 if (hv_exists_ent(names, *id, 0)) {
893 777 SV *prev = HeVAL(hv_fetch_ent(names, *id, 0, 0));
894 # uncoverable branch true
895 # uncoverable condition left count:1 class:ignore_covered_err
896 849 if (SvROK(prev))
897 croak("Punk: route name '%s' is declared " /* # uncoverable statement */
898 "twice: two api mounts both have an "
899 846 "operation called that - a name is "
900 846 "one route across the whole "
901 967 ▶ "application", SvPV_nolen(*id)); /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
"application", SvPV_nolen(*id)); /* # uncoverable statement */ 153 814 967
902 153 {
903 153 HV *rr = (HV *)SvRV(*av_fetch(recs,
904 153 (SSize_t)SvIV(prev), 0));
905 153 SV **rm = hv_fetchs(rr, K_METHOD, 0);
906 202 ▶ SV **rp = hv_fetchs(rr, K_PATH, 0);
Branch: 3 branches
BranchTrueFalseTotal
SV **rp = hv_fetchs(rr, K_PATH, 0); 50 103 153
SV **rp = hv_fetchs(rr, K_PATH, 0); 50 0 50
SV **rp = hv_fetchs(rr, K_PATH, 0); 50 0 50
907 croak("Punk: route name '%s' is declared "
908 50 "twice: %s %s and the operation of "
909 50 ▶ "that name in the %s mount - the "
Branch: 2 branches
BranchTrueFalseTotal
"that name in the %s mount - the " 50 0 50
"that name in the %s mount - the " 50 0 50
910 50 ▶ "names are one namespace",
Branch: 1 branch
BranchTrueFalseTotal
"names are one namespace", 50 0 50
911 100 ▶ SvPV_nolen(*id),
Branch: 1 branch
BranchTrueFalseTotal
SvPV_nolen(*id), 50 0 50
912 rm && *rm ? SvPV_nolen(*rm) : "?",
913 rp && *rp ? SvPV_nolen(*rp) : "?",
914 (psv && *psv && SvOK(*psv)
915 && SvCUR(*psv))
916 50 ▶ ? SvPV_nolen(*psv) : "/");
Branch: 1 branch
BranchTrueFalseTotal
? SvPV_nolen(*psv) : "/"); 50 0 50
917 50 }
918 100 ▶ }
Branch: 2 branches
BranchTrueFalseTotal
} 50 0 50
} 0 50 50
919 tp = SvPV_const(*pth, tl);
920 pair = newAV();
921 # uncoverable condition right count:1 class:ignore_covered_err
922 50 # uncoverable condition right count:2 class:ignore_covered_err
923 50 av_push(pair, (psv && *psv) ? newSVsv(*psv) : newSV(0));
924 50 av_push(pair, newRV_noinc((SV *)
925 pk_url_parse_template(aTHX_ tp, tl)));
926 49 ▶ (void)hv_store_ent(names, *id,
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_store_ent(names, *id, 0 49 49
927 newRV_noinc((SV *)pair), 0);
928 103 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
} 85 18 103
} 85 0 85
} 85 0 85
929 }
930 }
931 (void)hv_stores(h, K_NAMES_C, newRV_noinc((SV *)names));
932  
933 { /* The path on `host`, split off once.
934 *
935 85 * A route matches PATH_INFO, and PATH_INFO is what is left
936 85 * after whatever sits in front of the application. Two
937 * things can: SCRIPT_NAME, which the request carries, and
938 * the path on `host` - `host 'https://example.com/app'`,
939 * which is how an application says a proxy strips /app
940 85 ▶ * before Punk ever sees the request. Only configuration
Branch: 3 branches
BranchTrueFalseTotal
* before Punk ever sees the request. Only configuration 85 0 85
* before Punk ever sees the request. Only configuration 85 0 85
* before Punk ever sees the request. Only configuration 85 0 85
941 85 ▶ * knows the second, and $c->origin deliberately drops it
Branch: 1 branch
BranchTrueFalseTotal
* knows the second, and $c->origin deliberately drops it 85 0 85
942 85 * (pk_origin_bare returns scheme://host, which is what an
943 * origin means to a browser), so it is kept here for the
944 85 * URL builder to put back. Empty for the deployments that
945 209 ▶ * have no prefix, which is nearly all of them. */
Branch: 1 branch
BranchTrueFalseTotal
* have no prefix, which is nearly all of them. */ 124 85 209
946 124 SV *host = app_get(aTHX_ h, "host");
947 # uncoverable condition right count:2 class:ignore_covered_err
948 # uncoverable condition right count:3 class:ignore_covered_err
949 85 ▶ if (host && SvOK(host) && SvCUR(host)) {
Branch: 1 branch
BranchTrueFalseTotal
if (host && SvOK(host) && SvCUR(host)) { 84 1 85
950 84 STRLEN hl, hoff, hlen;
951 84 ▶ const char *hp = SvPV_const(host, hl);
Branch: 3 branches
BranchTrueFalseTotal
const char *hp = SvPV_const(host, hl); 2 82 84
const char *hp = SvPV_const(host, hl); 2 0 2
const char *hp = SvPV_const(host, hl); 2 0 2
952 2 SV *bare = pk_origin_bare(aTHX_ hp, hl, &hoff, &hlen);
953 STRLEN bl = SvCUR(bare);
954 85 if (hl > bl)
955 85 (void)hv_stores(h, K_HOST_PATH_C,
956 85 newSVpvn(hp + bl, hl - bl));
957 85 SvREFCNT_dec(bare);
958 }
959 54 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
} 0 54 54
960 }
961  
962 54 /* sse routes: mark the records; the transport is chosen per request
963 * (detach / psgi.streaming / blocking), so no boot capability check */
964 121 x = hv_fetchs(h, K_SSE_ROUTES, 0);
965 # uncoverable condition right count:2 class:ignore_covered_err
966 814 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 110 704 814
967 110 # uncoverable condition right count:4 class:ignore_covered_err
968 if (x && *x && SvROK(*x) && SvTYPE(SvRV(*x)) == SVt_PVAV) {
969 AV *ssr = (AV *)SvRV(*x);
970 HV *ssemap = (HV *)sv_2mortal((SV *)newHV());
971 # uncoverable condition right count:1 class:ignore_covered_err
972 814 # uncoverable condition right count:2 class:ignore_covered_err
973 AV *recs = (all_recs && SvROK(all_recs)) ? (AV *)SvRV(all_recs) : NULL;
974 SSize_t si, sn = av_len(ssr) + 1;
975 for (si = 0; si < sn; si++) {
976 814 HV *w = (HV *)SvRV(*av_fetch(ssr, si, 0));
977 814 SV **pp = hv_fetchs(w, K_PATH, 0);
978 814 SV **op = hv_fetchs(w, K_OPTS, 0);
979 814 # uncoverable branch false
980 814 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 814 0 814
# uncoverable condition right count:1 class:ignore_covered_err 814 0 814
# uncoverable condition right count:1 class:ignore_covered_err 814 0 814
981 814 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 814 0 814
# uncoverable condition right count:2 class:ignore_covered_err 814 0 814
# uncoverable condition right count:2 class:ignore_covered_err 814 0 814
982 814 ▶ if (pp && *pp)
Branch: 3 branches
BranchTrueFalseTotal
if (pp && *pp) 814 0 814
if (pp && *pp) 814 0 814
if (pp && *pp) 814 0 814
983 814 (void)hv_store_ent(ssemap, *pp,
984 814 newSVsv(op && *op ? *op : &PL_sv_undef), 0);
985 814 }
986 814 ▶ n = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
n = recs ? av_len(recs) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ 814 0 814
987 830 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 16 814 830
988 16 HV *rr = (HV *)SvRV(*av_fetch(recs, i, 0));
989 SV **meth = hv_fetchs(rr, K_METHOD, 0);
990 814 ▶ SV **pth = hv_fetchs(rr, K_PATH, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **pth = hv_fetchs(rr, K_PATH, 0); 814 0 814
991 847 ▶ HE *he;
Branch: 1 branch
BranchTrueFalseTotal
HE *he; 33 814 847
992 33 # uncoverable condition left count:1 class:ignore_covered_err
993 # uncoverable condition left count:2 class:ignore_covered_err
994 814 ▶ if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!(meth && *meth && strEQ(SvPV_nolen(*meth), "GET"))) continue; 814 0 814
995 820 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 6 814 820
996 6 # uncoverable condition right count:2 class:ignore_covered_err
997 he = pth && *pth ? hv_fetch_ent(ssemap, *pth, 0, 0) : NULL;
998 if (he) (void)hv_stores(rr, K_SSE, newSVsv(HeVAL(he)));
999 }
1000 }
1001  
1002 /* views */
1003 {
1004 AV *views = app_av(aTHX_ h, K_VIEWS);
1005 814 /* the `asset` filter on the shipped engine, so a template can
1006 814 ▶ * write {% "/static/app.css" | asset %}. Only stencil, because
Branch: 3 branches
BranchTrueFalseTotal
* write {% "/static/app.css" | asset %}. Only stencil, because 814 0 814
* write {% "/static/app.css" | asset %}. Only stencil, because 814 0 814
* write {% "/static/app.css" | asset %}. Only stencil, because 814 0 814
1007 814 * `filters` is its option; only when the application has not
1008 814 ▶ * registered a filter of its own by that name. */
Branch: 1 branch
BranchTrueFalseTotal
* registered a filter of its own by that name. */ 814 0 814
1009 814 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
{ 10 804 814
1010 10 SSize_t vi, vn = av_len(views) + 1;
1011 21 ▶ for (vi = 0; vi < vn; vi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (vi = 0; vi < vn; vi++) { 11 10 21
1012 11 SV **pp = av_fetch(views, vi, 0);
1013 AV *pair;
1014 10 SV **nm, **op;
1015 HV *vopts, *filters;
1016 # uncoverable branch true
1017 # uncoverable condition left count:1 class:ignore_covered_err
1018 # uncoverable condition left count:2 class:ignore_covered_err
1019 # uncoverable condition left count:3 class:ignore_covered_err
1020 if (!(pp && *pp && SvROK(*pp))) continue;
1021 pair = (AV *)SvRV(*pp);
1022 nm = av_fetch(pair, 0, 0);
1023 op = av_fetch(pair, 1, 0);
1024 # uncoverable branch true
1025 814 # uncoverable condition left count:1 class:ignore_covered_err
1026 814 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 814 0 814
# uncoverable condition left count:2 class:ignore_covered_err 814 0 814
# uncoverable condition left count:2 class:ignore_covered_err 814 0 814
1027 814 # uncoverable condition left count:3 class:ignore_covered_err
1028 814 ▶ if (!(nm && *nm && SvOK(*nm))) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!(nm && *nm && SvOK(*nm))) continue; 814 0 814
1029 814 ▶ { /* `views Stencil => {...}` names a class suffix, so
Branch: 1 branch
BranchTrueFalseTotal
{ /* `views Stencil => {...}` names a class suffix, so 2 812 814
1030 2 * it is matched the way pv_load_engine resolves it -
1031 4 ▶ * including the +Punk::View::Stencil spelling */
Branch: 1 branch
BranchTrueFalseTotal
* including the +Punk::View::Stencil spelling */ 2 2 4
1032 2 STRLEN nl;
1033 const char *nv = SvPV_const(*nm, nl);
1034 2 int ok = (nl == 7 && foldEQ(nv, "Stencil", 7))
1035 || (nl == 20 && memEQ(nv, "+Punk::View::Stencil", 20));
1036 if (!ok) continue;
1037 }
1038 # uncoverable branch true
1039 # uncoverable condition left count:1 class:ignore_covered_err
1040 # uncoverable condition left count:2 class:ignore_covered_err
1041 # uncoverable condition left count:3 class:ignore_covered_err
1042 814 # uncoverable condition left count:4 class:ignore_covered_err
1043 814 ▶ if (!(op && *op && SvROK(*op)
Branch: 3 branches
BranchTrueFalseTotal
if (!(op && *op && SvROK(*op) 19 795 814
if (!(op && *op && SvROK(*op) 19 0 19
if (!(op && *op && SvROK(*op) 19 0 19
1044 19 && SvTYPE(SvRV(*op)) == SVt_PVHV)) continue;
1045 19 ▶ vopts = (HV *)SvRV(*op);
Branch: 1 branch
BranchTrueFalseTotal
vopts = (HV *)SvRV(*op); 19 0 19
1046 19 {
1047 19 SV **fp = hv_fetchs(vopts, "filters", 0);
1048 # uncoverable condition right count:2 class:ignore_covered_err
1049 # uncoverable condition right count:3 class:ignore_covered_err
1050 # uncoverable condition right count:4 class:ignore_covered_err
1051 if (fp && *fp && SvROK(*fp)
1052 && SvTYPE(SvRV(*fp)) == SVt_PVHV)
1053 filters = (HV *)SvRV(*fp);
1054 else {
1055 filters = newHV();
1056 814 (void)hv_stores(vopts, "filters",
1057 814 ▶ newRV_noinc((SV *)filters));
Branch: 3 branches
BranchTrueFalseTotal
newRV_noinc((SV *)filters)); 104 710 814
newRV_noinc((SV *)filters)); 104 0 104
newRV_noinc((SV *)filters)); 104 0 104
1058 104 }
1059 104 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
} 104 0 104
1060 if (!hv_exists(filters, "asset", 5))
1061 (void)hv_stores(filters, "asset",
1062 pa_asset_filter(aTHX_ self));
1063 /* ... and `url_for`, on the same terms. The
1064 * application's own filter of either name wins,
1065 814 * silently: `filters` is the application's, and Punk
1066 814 ▶ * adds to it only where it left a gap. The prefix slot
Branch: 3 branches
BranchTrueFalseTotal
* adds to it only where it left a gap. The prefix slot 19 795 814
* adds to it only where it left a gap. The prefix slot 19 0 19
* adds to it only where it left a gap. The prefix slot 19 0 19
1067 * is created once and held by both the closure and the
1068 19 ▶ * app, so the binder can set it per render. */
Branch: 3 branches
BranchTrueFalseTotal
* app, so the binder can set it per render. */ 18 1 19
* app, so the binder can set it per render. */ 18 0 18
* app, so the binder can set it per render. */ 0 18 18
1069 1 if (!hv_exists(filters, "url_for", 7)) {
1070 SV *slot = hv_fetchs(h, K_URL_PREFIX_C, 0)
1071 18 # uncoverable statement class:ignore_covered_err
1072 18 ▶ # uncoverable condition left count:1
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 18 0 18
1073 ? *hv_fetchs(h, K_URL_PREFIX_C, 0) : NULL;
1074 # uncoverable branch false
1075 # uncoverable condition right count:1 class:ignore_covered_err
1076 if (!slot) {
1077 slot = newSVpvs("");
1078 (void)hv_stores(h, K_URL_PREFIX_C, slot);
1079 }
1080 (void)hv_stores(filters, "url_for",
1081 813 pk_url_filter(aTHX_ self, slot));
1082 813 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
} 19 794 813
} 19 0 19
} 19 0 19
1083 19 }
1084 }
1085 if (av_len(views) >= 0) {
1086 SV *argv[1], *vobj;
1087 (void)pk_require_once(aTHX_ PK_VIEWS, TRUE);
1088 argv[0] = sv_2mortal(newRV_inc((SV *)views));
1089 vobj = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_VIEWS)),
1090 "new", argv, 1, 1);
1091 813 (void)hv_stores(h, K_VIEWS_C, vobj ? vobj : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
1092 813 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
} 29 784 813
} 29 0 29
} 29 0 29
} 29 0 29
1093 29 else (void)hv_stores(h, K_VIEWS_C, newSV(0));
1094 29 }
1095 29  
1096 29 ▶ pc_compile_models(aTHX_ self);
Branch: 3 branches
BranchTrueFalseTotal
pc_compile_models(aTHX_ self); 29 0 29
pc_compile_models(aTHX_ self); 29 0 29
pc_compile_models(aTHX_ self); 29 0 29
1097  
1098 29 ▶ /* static / psgi mounts: instantiate the static apps, order longest */
Branch: 3 branches
BranchTrueFalseTotal
/* static / psgi mounts: instantiate the static apps, order longest */ 29 0 29
/* static / psgi mounts: instantiate the static apps, order longest */ 29 0 29
/* static / psgi mounts: instantiate the static apps, order longest */ 29 0 29
1099 mount_src = app_av(aTHX_ h, K_MOUNTS);
1100 29 n = av_len(mount_src) + 1;
1101 for (i = 0; i < n; i++) {
1102 HV *src = (HV *)SvRV(*av_fetch(mount_src, i, 0));
1103 HV *m = newHVhv(src);
1104 813 ▶ SV **dir = hv_fetchs(m, K_DIR, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **dir = hv_fetchs(m, K_DIR, 0); 813 0 813
1105 813 SV **mdir = hv_fetchs(m, K_MD_DIR, 0);
1106 804 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 0 804 804
1107 # uncoverable condition right count:3 class:ignore_covered_err
1108 if (dir && *dir && SvOK(*dir)) {
1109 SV *argv[2], *sapp;
1110 804 SV **sop = hv_fetchs(m, K_OPTS, 0);
1111 831 ▶ HV *sopts = (sop && *sop && SvROK(*sop)
Branch: 1 branch
BranchTrueFalseTotal
HV *sopts = (sop && *sop && SvROK(*sop) 27 804 831
1112 27 && SvTYPE(SvRV(*sop)) == SVt_PVHV)
1113 27 ? newHVhv((HV *)SvRV(*sop)) : newHV();
1114 27 /* whether a cached digest is re-checked against the file is
1115 27 * the app's environment, not the mount's - an app that says
1116 27 * nothing gets the answer $app->env gives, which reads the
1117 27 * config before it reads PUNK_ENV */
1118 27 # uncoverable branch false class:ignore_covered_err
1119 27 # uncoverable condition right count:1 class:ignore_covered_err
1120 27 if (!hv_exists(sopts, "dev", 3)) {
1121 27 ▶ SV *envsv = pc_app_env(aTHX_ self);
Branch: 1 branch
BranchTrueFalseTotal
SV *envsv = pc_app_env(aTHX_ self); 0 27 27
1122 27 ▶ (void)hv_stores(sopts, "dev",
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(sopts, "dev", 0 27 27
1123 27 ▶ newSViv(SvOK(envsv)
Branch: 1 branch
BranchTrueFalseTotal
newSViv(SvOK(envsv) 0 27 27
1124 27 ▶ && strEQ(SvPV_nolen(envsv), "development")));
Branch: 1 branch
BranchTrueFalseTotal
&& strEQ(SvPV_nolen(envsv), "development"))); 0 27 27
1125 27 }
1126 argv[0] = *dir;
1127 argv[1] = sv_2mortal(newRV_noinc((SV *)sopts));
1128 804 sapp = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_STATIC)),
1129 K_APP, argv, 2, 1);
1130 (void)hv_stores(m, K_APP, sapp ? sapp : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
1131 804 }
1132 804 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 2 802 804
# uncoverable condition right count:2 class:ignore_covered_err 2 0 2
# uncoverable condition right count:2 class:ignore_covered_err 2 0 2
1133 2 # uncoverable condition right count:3 class:ignore_covered_err
1134 else if (mdir && *mdir && SvOK(*mdir)) {
1135 804 /* The whole documentation site is built here, at boot: the
1136 804 * tree is walked, every page rendered and frozen, and the
1137 804 * search index filled. A bad template or an unreadable
1138 804 * directory is a configuration error and fails with the rest
1139 804 * of the configuration rather than on the first request. */
1140 804 SV *argv[3], *mapp;
1141 SV **op = hv_fetchs(m, K_OPTS, 0);
1142 HV *mo = newHV();
1143 804 /* A copy, so the app's `host` can ride along for the
1144 804 ▶ * canonical URLs without editing the caller's options. An
Branch: 3 branches
BranchTrueFalseTotal
* canonical URLs without editing the caller's options. An 5 799 804
* canonical URLs without editing the caller's options. An 5 0 5
* canonical URLs without editing the caller's options. An 5 0 5
1145 5 * explicit `host` on the mount wins. */
1146 # uncoverable branch false class:ignore_covered_err
1147 # uncoverable condition right count:1 class:ignore_covered_err
1148 # uncoverable condition right count:2 class:ignore_covered_err
1149 # uncoverable condition right count:3 class:ignore_covered_err
1150 804 # uncoverable condition right count:4 class:ignore_covered_err
1151 if (op && *op && SvROK(*op)
1152 && SvTYPE(SvRV(*op)) == SVt_PVHV) {
1153 HV *src = (HV *)SvRV(*op);
1154 HE *he;
1155 hv_iterinit(src);
1156 803 while ((he = hv_iternext(src)))
1157 803 ▶ (void)hv_store_ent(mo, hv_iterkeysv(he),
Branch: 3 branches
BranchTrueFalseTotal
(void)hv_store_ent(mo, hv_iterkeysv(he), 65 738 803
(void)hv_store_ent(mo, hv_iterkeysv(he), 65 0 65
(void)hv_store_ent(mo, hv_iterkeysv(he), 65 0 65
1158 65 newSVsv(HeVAL(he)), 0);
1159 }
1160 if (!hv_exists(mo, "host", 4)) {
1161 SV *host = app_get(aTHX_ h, "host");
1162 # uncoverable condition right count:2 class:ignore_covered_err
1163 # uncoverable condition right count:3 class:ignore_covered_err
1164 if (host && SvOK(host) && SvCUR(host))
1165 (void)hv_stores(mo, "host", newSVsv(host));
1166 }
1167 argv[0] = *mdir;
1168 65 ▶ argv[1] = sv_2mortal(newRV_noinc((SV *)mo));
Branch: 1 branch
BranchTrueFalseTotal
argv[1] = sv_2mortal(newRV_noinc((SV *)mo)); 65 0 65
1169 65 argv[2] = *hv_fetchs(m, K_PREFIX, 0);
1170 130 ▶ mapp = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_MOUNT_MD)),
Branch: 2 branches
BranchTrueFalseTotal
mapp = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_MOUNT_MD)), 65 0 65
mapp = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs(PK_MOUNT_MD)), 2 63 65
1171 K_APP, argv, 3, 1);
1172 (void)hv_stores(m, K_APP, mapp ? mapp : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
1173 /* what $app->markdown_pages looks for: a closure's capture
1174 * says nothing about whose it is */
1175 (void)hv_stores(m, K_MD_MOUNT, newSViv(1));
1176 }
1177 av_push(mounts_out, newRV_noinc((SV *)m));
1178 }
1179 if (av_len(mounts_out) >= 0)
1180 sortsv(AvARRAY(mounts_out), (STRLEN)(av_len(mounts_out) + 1),
1181 803 pc_cmp_len_desc);
1182 803 ▶ /* the same table on the app, the way the compiled views already sit
Branch: 3 branches
BranchTrueFalseTotal
/* the same table on the app, the way the compiled views already sit 31 772 803
/* the same table on the app, the way the compiled views already sit 31 0 31
/* the same table on the app, the way the compiled views already sit 31 0 31
1183 31 * there: $c->asset walks it to find which mount owns a URL, and the
1184 31 ▶ * request path's copy is not reachable from a context */
Branch: 1 branch
BranchTrueFalseTotal
* request path's copy is not reachable from a context */ 31 0 31
1185 31 (void)hv_stores(h, K_MOUNTS_C, newRV_inc((SV *)mounts_out));
1186 62 ▶ 
Branch: 2 branches
BranchTrueFalseTotal
31 0 31
1 30 31
1187 /* before / after hooks and the app on_error, resolved to coderefs */
1188 {
1189 HV *hooks = app_hash(aTHX_ h, K_HOOKS);
1190 SV **rp = hv_fetchs(hooks, K_BEFORE_R, 0);
1191 SV **bp = hv_fetchs(hooks, K_BEFORE_D, 0);
1192 SV **ap = hv_fetchs(hooks, K_AFTER_D, 0);
1193 # uncoverable condition right count:1 class:ignore_covered_err
1194 # uncoverable condition right count:2 class:ignore_covered_err
1195 # uncoverable condition right count:3 class:ignore_covered_err
1196 AV *rl = (rp && *rp && SvROK(*rp)) ? (AV *)SvRV(*rp) : NULL;
1197 803 # uncoverable condition right count:1 class:ignore_covered_err
1198 803 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 19 784 803
# uncoverable condition right count:2 class:ignore_covered_err 19 0 19
# uncoverable condition right count:2 class:ignore_covered_err 19 0 19
1199 19 # uncoverable condition right count:3 class:ignore_covered_err
1200 AV *bl = (bp && *bp && SvROK(*bp)) ? (AV *)SvRV(*bp) : NULL;
1201 # uncoverable condition right count:1 class:ignore_covered_err
1202 # uncoverable condition right count:2 class:ignore_covered_err
1203 # uncoverable condition right count:3 class:ignore_covered_err
1204 803 AV *al = (ap && *ap && SvROK(*ap)) ? (AV *)SvRV(*ap) : NULL;
1205 803 ▶ SV *whatr = sv_2mortal(newSVpvs("before_request hook"));
Branch: 3 branches
BranchTrueFalseTotal
SV *whatr = sv_2mortal(newSVpvs("before_request hook")); 29 774 803
SV *whatr = sv_2mortal(newSVpvs("before_request hook")); 29 0 29
SV *whatr = sv_2mortal(newSVpvs("before_request hook")); 29 0 29
1206 29 SV *whatb = sv_2mortal(newSVpvs("before_dispatch hook"));
1207 SV *whata = sv_2mortal(newSVpvs("after_dispatch hook"));
1208 803 n = rl ? av_len(rl) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
1209 803 for (i = 0; i < n; i++)
1210 av_push(before_req_out,
1211 pc_resolve_target(aTHX_ self, *av_fetch(rl, i, 0), whatr));
1212 n = bl ? av_len(bl) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
1213 for (i = 0; i < n; i++)
1214 av_push(before_out,
1215 803 ▶ pc_resolve_target(aTHX_ self, *av_fetch(bl, i, 0), whatb));
Branch: 1 branch
BranchTrueFalseTotal
pc_resolve_target(aTHX_ self, *av_fetch(bl, i, 0), whatb)); 14 789 803
1216 14 n = al ? av_len(al) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
1217 for (i = 0; i < n; i++)
1218 av_push(after_out,
1219 789 pc_resolve_target(aTHX_ self, *av_fetch(al, i, 0), whata));
1220  
1221 /* before_render lives on the app rather than in the request
1222 803 * state: a render is reached from a context, and the views object
1223 803 ▶ * has no route to the compiled state the dispatcher carries.
Branch: 3 branches
BranchTrueFalseTotal
* has no route to the compiled state the dispatcher carries. 13 790 803
* has no route to the compiled state the dispatcher carries. 13 0 13
* has no route to the compiled state the dispatcher carries. 13 0 13
1224 13 * Stored only when there is one, so the ordinary render does one
1225 * hv_fetch that misses and nothing else. */
1226 {
1227 SV **np = hv_fetchs(hooks, K_BEFORE_RN, 0);
1228 # uncoverable condition right count:1 class:ignore_covered_err
1229 13 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 0 13 13
1230 0 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 0 0 0
1231 AV *nl = (np && *np && SvROK(*np)) ? (AV *)SvRV(*np) : NULL;
1232 SV *whatn = sv_2mortal(newSVpvs("before_render hook"));
1233 n = nl ? av_len(nl) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
1234 if (n) {
1235 AV *render_out = newAV();
1236 for (i = 0; i < n; i++)
1237 803 av_push(render_out, pc_resolve_target(aTHX_ self,
1238 803 ▶ *av_fetch(nl, i, 0), whatn));
Branch: 3 branches
BranchTrueFalseTotal
*av_fetch(nl, i, 0), whatn)); 6 797 803
*av_fetch(nl, i, 0), whatn)); 6 0 6
*av_fetch(nl, i, 0), whatn)); 6 0 6
1239 6 ▶ (void)hv_stores(h, K_BEFORE_RENDER_C,
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(h, K_BEFORE_RENDER_C, 6 0 6
1240 6 newRV_noinc((SV *)render_out));
1241 6 }
1242 }
1243  
1244 6 ▶ /* after_response lives on the app for the same reason: it is
Branch: 1 branch
BranchTrueFalseTotal
/* after_response lives on the app for the same reason: it is 0 6 6
1245 0 ▶ * reached from a context at delivery, and a delivery from a
Branch: 1 branch
BranchTrueFalseTotal
* reached from a context at delivery, and a delivery from a 0 0 0
1246 * settled future has no route to the compiled state. Stored only
1247 * when there is one, so a response in an application that
1248 * declares none does one hv_fetch that misses. */
1249 {
1250 SV **sp2 = hv_fetchs(hooks, K_AFTER_RES, 0);
1251 # uncoverable condition right count:1 class:ignore_covered_err
1252 # uncoverable condition right count:2 class:ignore_covered_err
1253 803 # uncoverable condition right count:3 class:ignore_covered_err
1254 803 ▶ AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL; 18 785 803
AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL; 18 0 18
AV *sl = (sp2 && *sp2 && SvROK(*sp2)) ? (AV *)SvRV(*sp2) : NULL; 18 0 18
1255 18 ▶ SV *whats = sv_2mortal(newSVpvs("after_response hook"));
Branch: 1 branch
BranchTrueFalseTotal
SV *whats = sv_2mortal(newSVpvs("after_response hook")); 18 0 18
1256 n = sl ? av_len(sl) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */
1257 if (n) {
1258 AV *ares_out = newAV();
1259 for (i = 0; i < n; i++)
1260 18 av_push(ares_out, pc_resolve_target(aTHX_ self,
1261 18 *av_fetch(sl, i, 0), whats));
1262 18 ▶ (void)hv_stores(h, K_AFTER_RES_C,
Branch: 2 branches
BranchTrueFalseTotal
(void)hv_stores(h, K_AFTER_RES_C, 0 18 18
(void)hv_stores(h, K_AFTER_RES_C, 0 18 18
1263 18 newRV_noinc((SV *)ares_out));
1264 18 }
1265 18 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
} 18 0 18
1266 18 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
18 0 18
1267 /* The csrf check goes at the head of before_dispatch: a forged
1268 18 * request should be refused before an application hook sees it. */
1269 18 {
1270 36 ▶ SV **cc = hv_fetchs(h, K_CSRF, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **cc = hv_fetchs(h, K_CSRF, 0); 18 0 18
1271 10 # uncoverable condition right count:2 class:ignore_covered_err
1272 # uncoverable condition right count:3 class:ignore_covered_err
1273 if (cc && *cc && SvROK(*cc)) {
1274 CV *ck = get_cv("Punk::CSRF::_check", 0);
1275 # uncoverable branch false
1276 # uncoverable condition right count:1 class:ignore_covered_err
1277 if (ck) {
1278 795 av_unshift(before_out, 1);
1279 795 ▶ (void)av_store(before_out, 0, newRV_inc((SV *)ck));
Branch: 3 branches
BranchTrueFalseTotal
(void)av_store(before_out, 0, newRV_inc((SV *)ck)); 18 777 795
(void)av_store(before_out, 0, newRV_inc((SV *)ck)); 18 0 18
(void)av_store(before_out, 0, newRV_inc((SV *)ck)); 18 0 18
1280 18 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
} 18 0 18
1281 18 }
1282 18 }
1283 }
1284 18 ▶ 
Branch: 3 branches
BranchTrueFalseTotal
17 1 18
17 0 17
0 17 17
1285 1 /* when sessions are configured, the write-back runs last (it sees the
1286 * finished triplet and adds the signed Set-Cookie) */
1287 17 {
1288 17 ▶ SV **sc = hv_fetchs(h, "session", 0);
Branch: 4 branches
BranchTrueFalseTotal
SV **sc = hv_fetchs(h, "session", 0); 5 12 17
SV **sc = hv_fetchs(h, "session", 0); 5 0 5
SV **sc = hv_fetchs(h, "session", 0); 5 0 5
SV **sc = hv_fetchs(h, "session", 0); 1 4 5
1289 1 # uncoverable condition right count:2 class:ignore_covered_err
1290 1 # uncoverable condition right count:3 class:ignore_covered_err
1291 0 if (sc && *sc && SvROK(*sc)) {
1292 CV *wb = get_cv("Punk::Session::_writeback", 0);
1293 # uncoverable branch false
1294 16 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 0 16 16
1295 0 ▶ if (wb) av_push(after_out, newRV_inc((SV *)wb));
Branch: 1 branch
BranchTrueFalseTotal
if (wb) av_push(after_out, newRV_inc((SV *)wb)); 0 0 0
1296 }
1297 /* csrf rides on the session - the token has nowhere else to live -
1298 * and its mirror cookie goes out after the session's own, on the
1299 * same response */
1300 {
1301 SV **cc = hv_fetchs(h, K_CSRF, 0);
1302 793 # uncoverable condition right count:2 class:ignore_covered_err
1303 793 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 2 791 793
# uncoverable condition right count:3 class:ignore_covered_err 2 0 2
# uncoverable condition right count:3 class:ignore_covered_err 2 0 2
# uncoverable condition right count:3 class:ignore_covered_err 2 0 2
1304 2 if (cc && *cc && SvROK(*cc)) {
1305 2 CV *wb;
1306 2 # uncoverable condition left count:2 class:ignore_covered_err
1307 5 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 3 2 5
1308 3 if (!(sc && *sc && SvROK(*sc)))
1309 croak("Punk: `csrf` needs a session for the token to "
1310 "live in - add a `session` keyword");
1311 3 wb = get_cv("Punk::CSRF::_writeback", 0);
1312 3 ▶ # uncoverable branch false
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable branch false 3 0 3
# uncoverable branch false 3 0 3
# uncoverable branch false 0 3 3
1313 3 # uncoverable condition right count:1 class:ignore_covered_err
1314 3 if (wb) av_push(after_out, newRV_inc((SV *)wb));
1315 3 }
1316 3 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
} 3 0 3
} 3 0 3
} 3 0 3
1317 3 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
} 3 0 3
} 3 0 3
} 3 0 3
1318  
1319 3 { /* the body ETag, last on the chain - after any application hook
1320 3 * that might rewrite the body (or the tag would describe bytes
1321 3 ▶ * nobody was sent) and after the session write-back (whose
Branch: 3 branches
BranchTrueFalseTotal
* nobody was sent) and after the session write-back (whose 3 0 3
* nobody was sent) and after the session write-back (whose 3 0 3
* nobody was sent) and after the session write-back (whose 3 0 3
1322 3 ▶ * Set-Cookie the 304 then carries rather than drops) */
Branch: 1 branch
BranchTrueFalseTotal
* Set-Cookie the 304 then carries rather than drops) */ 3 0 3
1323 3 SV **cg = hv_fetchs(h, K_CGET, 0);
1324 # uncoverable condition right count:2 class:ignore_covered_err
1325 3 # uncoverable condition right count:3 class:ignore_covered_err
1326 if (cg && *cg && SvTRUE(*cg))
1327 2 ▶ av_push(after_out,
Branch: 1 branch
BranchTrueFalseTotal
av_push(after_out, 1 1 2
1328 1 punk_closure(aTHX_ pcg_after_cb, newAV()));
1329 }
1330 2 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
2 0 2
1331 2 { /* the idempotency recorder, also last: what is stored has to be
1332 * what was actually sent, after every application hook has had
1333 2 ▶ * its say. The TTL rides in the capture rather than being read
Branch: 1 branch
BranchTrueFalseTotal
* its say. The TTL rides in the capture rather than being read 0 2 2
1334 0 ▶ * from the state per response. */
Branch: 1 branch
BranchTrueFalseTotal
* from the state per response. */ 0 0 0
1335 SV **ic = hv_fetchs(h, K_IDEM, 0);
1336 # uncoverable condition right count:2 class:ignore_covered_err
1337 0 # uncoverable condition right count:3 class:ignore_covered_err
1338 # uncoverable condition right count:4 class:ignore_covered_err
1339 if (ic && *ic && SvROK(*ic) && SvTYPE(SvRV(*ic)) == SVt_PVHV) {
1340 AV *cap = newAV();
1341 793 SV **t = hv_fetchs((HV *)SvRV(*ic), "ttl", 0);
1342 793 SV **m = hv_fetchs((HV *)SvRV(*ic), "max_record", 0);
1343 793 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 6 787 793
# uncoverable condition right count:1 class:ignore_covered_err 6 0 6
# uncoverable condition right count:1 class:ignore_covered_err 6 0 6
1344 6 # uncoverable condition right count:2 class:ignore_covered_err
1345 6 # uncoverable condition right count:3 class:ignore_covered_err
1346 av_push(cap, (t && *t && SvOK(*t)) ? newSVnv(SvNV(*t))
1347 792 : newSVnv(86400));
1348 # uncoverable condition right count:1 class:ignore_covered_err
1349 # uncoverable condition right count:2 class:ignore_covered_err
1350 792 # uncoverable condition right count:3 class:ignore_covered_err
1351 792 av_push(cap, (m && *m && SvOK(*m)) ? newSViv(SvIV(*m))
1352 792 ▶ : newSViv(1048576));
Branch: 3 branches
BranchTrueFalseTotal
: newSViv(1048576)); 792 0 792
: newSViv(1048576)); 792 0 792
: newSViv(1048576)); 14 778 792
1353 14 av_push(after_out, punk_closure(aTHX_ pi_record_cb, cap));
1354 14 }
1355 }
1356 792  
1357 # uncoverable branch false class:ignore_covered_err
1358 # uncoverable condition right count:1 class:ignore_covered_err
1359 if (pcx_can(aTHX_ self, "compile_extras")) {
1360 792 SV *r = pcx_call_meth(aTHX_ self, "compile_extras", NULL, 0, 0);
1361 # uncoverable branch true
1362 792 # uncoverable condition left count:1 class:ignore_covered_err
1363 792 if (r) SvREFCNT_dec(r);
1364 }
1365  
1366 792 /* flatten the api mounts to the fields the C dispatcher reads */
1367 792 n = av_len(api_mounts) + 1;
1368 for (i = 0; i < n; i++) {
1369 HV *rec = (HV *)SvRV(*av_fetch(api_mounts, i, 0));
1370 SV *m = *hv_fetchs(rec, K_MOUNT, 0);
1371 SV *pfx = *hv_fetchs(rec, K_PREFIX, 0);
1372 HV *flat = newHV();
1373 792 SV *apio = pcx_call_meth(aTHX_ m, K_API, NULL, 0, 1);
1374 841 ▶ SV *opso = pcx_call_meth(aTHX_ m, K_OPS, NULL, 0, 1);
Branch: 1 branch
BranchTrueFalseTotal
SV *opso = pcx_call_meth(aTHX_ m, K_OPS, NULL, 0, 1); 51 790 841
1375 51 SV *mbo = pcx_call_meth(aTHX_ m, "max_body_size", NULL, 0, 1);
1376 51 SV *oeo = pcx_call_meth(aTHX_ m, K_ON_ERROR, NULL, 0, 1);
1377 51 ▶ (void)hv_stores(flat, K_PREFIX, newSVsv(pfx));
Branch: 2 branches
BranchTrueFalseTotal
(void)hv_stores(flat, K_PREFIX, newSVsv(pfx)); 51 0 51
(void)hv_stores(flat, K_PREFIX, newSVsv(pfx)); 0 51 51
1378 51 (void)hv_stores(flat, K_API, apio ? apio : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
1379 51 ▶ (void)hv_stores(flat, K_OPS, opso ? opso : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
(void)hv_stores(flat, K_OPS, opso ? opso : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */ 0 51 51
(void)hv_stores(flat, K_OPS, opso ? opso : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */ 0 51 51
1380 51 (void)hv_stores(flat, K_MAX_BODY, mbo ? mbo : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
1381 51 (void)hv_stores(flat, K_ON_ERROR, oeo ? oeo : newSV(0)); /* # uncoverable condition left count:1 class:ignore_covered_err */
1382 51 av_push(state_apims, newRV_noinc((SV *)flat));
1383 49 }
1384 49 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
49 0 49
1385 49 ▶ state = newHV();
Branch: 1 branch
BranchTrueFalseTotal
state = newHV(); 49 0 49
1386 49 { /* the app-wide body ceiling; a route's own value overrides it,
1387 * and is stamped onto the compiled record further up */
1388 SV **mb = hv_fetchs(h, K_MAX_BODY, 0);
1389 790 # uncoverable condition right count:2 class:ignore_covered_err
1390 790 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 790 0 790
# uncoverable condition right count:3 class:ignore_covered_err 790 0 790
# uncoverable condition right count:3 class:ignore_covered_err 790 0 790
1391 if (mb && *mb && SvOK(*mb))
1392 790 (void)hv_stores(state, K_MAX_BODY, newSViv(SvIV(*mb)));
1393 }
1394 (void)hv_stores(state, K_ROUTER, newSVsv(xs_router));
1395 (void)hv_stores(state, K_RECS, newSVsv(all_recs));
1396 (void)hv_stores(state, K_API_MOUNTS, newRV_noinc((SV *)state_apims));
1397 (void)hv_stores(state, K_MOUNTS, newRV_noinc((SV *)mounts_out));
1398 (void)hv_stores(state, K_CTX, newSVsv(ctx));
1399 (void)hv_stores(state, K_APP, newSVsv(self));
1400 { /* upload_dir, so the multipart parser can reach it: it has the
1401 * request's env and nothing else, and the env is the server's. */
1402 SV **ud = hv_fetchs(h, "upload_dir", 0);
1403 # uncoverable condition right count:2 class:ignore_covered_err
1404 # uncoverable condition right count:3 class:ignore_covered_err
1405 if (ud && *ud && SvOK(*ud))
1406 (void)hv_stores(state, "upload_dir", newSVsv(*ud));
1407 }
1408  
1409 /* The favicon bytes, frozen now: a missing file croaks here, at
1410 * boot, rather than 404ing for as long as nobody notices. */
1411 pfav_freeze(aTHX_ h);
1412  
1413 { /* Punk::Plugin::CSP's policy, copied from the app hash so
1414 * phd_effective can read it once per response without walking
1415 * back to the registrar. Absent when the plugin was never
1416 * registered, which is what keeps the header off. */
1417 SV **cs = hv_fetchs(h, K_CSP, 0);
1418 # uncoverable condition right count:2 class:ignore_covered_err
1419 # uncoverable condition right count:3 class:ignore_covered_err
1420 if (cs && *cs && SvROK(*cs)) {
1421 (void)hv_stores(state, K_CSP, newSVsv(*cs));
1422 /* Freeze whether this is development INTO the policy hash -
1423 * here rather than in register, because `plugin` is written
1424 * at the top of an application and `config` below it, so at
1425 * registration time the answer is not known yet.
1426 *
1427 * Both the state and the app hold the same HV, so writing it
1428 * once is visible from the view path (which has a context)
1429 * and the header path (which has the state), with no second
1430 * copy to drift. */
1431 # uncoverable branch false
1432 # uncoverable condition right count:1 class:ignore_covered_err
1433 if (SvTYPE(SvRV(*cs)) == SVt_PVHV) {
1434 SV *e = pc_app_env(aTHX_ self);
1435 (void)hv_stores((HV *)SvRV(*cs), "dev",
1436 newSViv(SvOK(e) && strEQ(SvPV_nolen(e),
1437 "development")));
1438 }
1439 }
1440 }
1441  
1442 { /* Punk::Plugin::I18n, the same arrangement as CSP above and for
1443 * the same reason: whether this is development decides whether a
1444 * missing key warns, and `plugin` is written above `config`, so
1445 * registration is too early to ask. */
1446 SV **is = hv_fetchs(h, K_I18N, 0);
1447 # uncoverable condition right count:2 class:ignore_covered_err
1448 # uncoverable condition right count:3 class:ignore_covered_err
1449 if (is && *is && SvROK(*is)) {
1450 (void)hv_stores(state, K_I18N, newSVsv(*is));
1451 # uncoverable branch false
1452 # uncoverable condition right count:1 class:ignore_covered_err
1453 if (SvTYPE(SvRV(*is)) == SVt_PVHV) {
1454 SV *e = pc_app_env(aTHX_ self);
1455 (void)hv_stores((HV *)SvRV(*is), "dev",
1456 newSViv(SvOK(e) && strEQ(SvPV_nolen(e),
1457 "development")));
1458 }
1459 }
1460 }
1461  
1462 { /* Punk::Plugin::ConditionalGet's on-switch, copied from the app
1463 * hash where `register` put it. Absent when the plugin was never
1464 * registered, which is what makes the `etag` route option inert
1465 * without it - the `sitemap` arrangement. */
1466 SV **cg = hv_fetchs(h, K_CGET, 0);
1467 # uncoverable condition right count:2 class:ignore_covered_err
1468 # uncoverable condition right count:3 class:ignore_covered_err
1469 if (cg && *cg && SvTRUE(*cg))
1470 (void)hv_stores(state, K_CGET, newSVsv(*cg));
1471 }
1472 { /* Punk::Plugin::Idempotency's config, from where `register`
1473 * put it. Absent when the plugin was never registered, which is
1474 * what makes the `idempotent` route option inert without it. */
1475 SV **ic = hv_fetchs(h, K_IDEM, 0);
1476 # uncoverable condition right count:2 class:ignore_covered_err
1477 # uncoverable condition right count:3 class:ignore_covered_err
1478 if (ic && *ic && SvROK(*ic))
1479 (void)hv_stores(state, K_IDEM, newSVsv(*ic));
1480 }
1481 (void)hv_stores(state, K_BEFORE, newRV_noinc((SV *)before_out));
1482 (void)hv_stores(state, K_AFTER, newRV_noinc((SV *)after_out));
1483 /* The before_request chain is stored only when there is one. punk_serve
1484 * reads it with ps_state_av, which is NULL for a key that was never
1485 * set, so an app without the hook takes the NULL branch: one hv_fetch
1486 * and one test, no context built and no chain walked. Storing an empty
1487 * AV instead would make the common path the slower one. */
1488 if (av_len(before_req_out) >= 0)
1489 (void)hv_stores(state, K_BEFORE_REQ,
1490 newRV_noinc((SV *)before_req_out));
1491 else
1492 SvREFCNT_dec((SV *)before_req_out);
1493 { /* the CORS policy, read once per request by pc_app_cb; absent
1494 * when the keyword was never used, so it costs one failed fetch */
1495 SV **co = hv_fetchs(h, K_CORS, 0);
1496 # uncoverable condition right count:2 class:ignore_covered_err
1497 # uncoverable condition right count:3 class:ignore_covered_err
1498 if (co && *co && SvROK(*co)) {
1499 (void)hv_stores(state, K_CORS, newSVsv(*co));
1500 /* Punk::CORS::_chain is the one Perl piece of the path - it
1501 * chains the decoration onto a Future - and nothing else
1502 * loads the file, so it is required here rather than
1503 * discovered missing on the first nonblocking response. */
1504 # uncoverable branch true
1505 # uncoverable condition left count:1 class:ignore_covered_err
1506 if (!pk_require_once(aTHX_ "Punk::CORS", FALSE))
1507 croak("Punk: cors needs Punk::CORS, which failed to " /* # uncoverable statement */
1508 "load: %s", SvPV_nolen(ERRSV)); /* # uncoverable statement */
1509 }
1510 }
1511 { /* the security-header policy: the defaults and the keyword's
1512 * overrides merged once, so a request only walks a frozen pair
1513 * list; absent when the keyword was never used */
1514 SV **hd = hv_fetchs(h, K_HEADERS, 0);
1515 # uncoverable condition right count:2 class:ignore_covered_err
1516 # uncoverable condition right count:3 class:ignore_covered_err
1517 # uncoverable condition right count:4 class:ignore_covered_err
1518 if (hd && *hd && SvROK(*hd)
1519 && SvTYPE(SvRV(*hd)) == SVt_PVHV) {
1520 AV *pairs = phd_compile(aTHX_ (HV *)SvRV(*hd));
1521 (void)hv_stores(state, K_HEADERS, newRV_noinc((SV *)pairs));
1522 /* Punk::Headers::_chain is the one Perl piece of the path,
1523 * for the Future shape - required here, like Punk::CORS */
1524 # uncoverable branch true
1525 # uncoverable condition left count:1 class:ignore_covered_err
1526 if (!pk_require_once(aTHX_ "Punk::Headers", FALSE))
1527 croak("Punk: headers needs Punk::Headers, which failed " /* # uncoverable statement */
1528 "to load: %s", SvPV_nolen(ERRSV)); /* # uncoverable statement */
1529 }
1530 }
1531 { /* proxy: parse the CIDRs and settle the hop rule once, so a
1532 * request is a header fetch and a walk. The policy is a C struct
1533 * behind a blessed IV-ref (the Punk::Router shape), freed with
1534 * the compiled app. */
1535 SV **px = hv_fetchs(h, K_PROXY, 0);
1536 # uncoverable condition right count:2 class:ignore_covered_err
1537 # uncoverable condition right count:3 class:ignore_covered_err
1538 # uncoverable condition right count:4 class:ignore_covered_err
1539 if (px && *px && SvROK(*px)
1540 && SvTYPE(SvRV(*px)) == SVt_PVHV) {
1541 SV *envsv;
1542 pp_policy *pol;
1543 { /* $app->env - production unless opted out of, which is
1544 * what decides whether trust => 'all' is allowed */
1545 dSP; int count;
1546 ENTER; SAVETMPS;
1547 PUSHMARK(SP); EXTEND(SP, 1); PUSHs(self); PUTBACK;
1548 count = call_method("env", G_SCALAR);
1549 SPAGAIN;
1550 envsv = count > 0 ? newSVsv(POPs) : newSVpvs("production"); /* # uncoverable condition right count:1 class:ignore_covered_err */
1551 PUTBACK; FREETMPS; LEAVE;
1552 }
1553 sv_2mortal(envsv);
1554 pol = pp_compile(aTHX_ (HV *)SvRV(*px),
1555 SvOK(envsv) ? SvPV_nolen(envsv) : "production"); /* # uncoverable condition right count:1 class:ignore_covered_err */
1556 (void)hv_stores(state, K_PROXY,
1557 sv_setref_iv(newSV(0), "Punk::Proxy",
1558 PTR2IV(pol)));
1559 }
1560 }
1561 { /* auth: the battery needs a session for the identity to live in,
1562 * and a roles target resolves now so a typo croaks at boot */
1563 SV **au = hv_fetchs(h, K_AUTH, 0);
1564 # uncoverable condition right count:2 class:ignore_covered_err
1565 # uncoverable condition right count:3 class:ignore_covered_err
1566 # uncoverable condition right count:4 class:ignore_covered_err
1567 if (au && *au && SvROK(*au)
1568 && SvTYPE(SvRV(*au)) == SVt_PVHV) {
1569 HV *acfg = (HV *)SvRV(*au);
1570 SV **sc = hv_fetchs(h, "session", 0);
1571 SV **rl;
1572 # uncoverable condition left count:2 class:ignore_covered_err
1573 # uncoverable condition left count:3 class:ignore_covered_err
1574 if (!(sc && *sc && SvROK(*sc)))
1575 croak("Punk: `auth` needs a session for the identity to "
1576 "live in - add a `session` keyword");
1577 rl = hv_fetchs(acfg, "roles", 0);
1578 # uncoverable condition right count:2 class:ignore_covered_err
1579 # uncoverable condition right count:3 class:ignore_covered_err
1580 if (rl && *rl && SvOK(*rl) && !SvROK(*rl)) {
1581 SV *what = sv_2mortal(newSVpvs("auth roles"));
1582 SV *code = pc_resolve_target(aTHX_ self, *rl, what);
1583 (void)hv_stores(acfg, "roles", code); /* # uncoverable statement class:ignore_covered_err */
1584 }
1585 /* the Perl half: current_user and the role/verified checks */
1586 # uncoverable branch true
1587 # uncoverable condition left count:1 class:ignore_covered_err
1588 if (!pk_require_once(aTHX_ "Punk::Auth", FALSE))
1589 croak("Punk: auth needs Punk::Auth, which failed to " /* # uncoverable statement */
1590 "load: %s", SvPV_nolen(ERRSV)); /* # uncoverable statement */
1591 }
1592 }
1593 { /* scoped header policies ($scope->headers): flattened per record
1594 * and sorted longest-prefix-first, so a request under nested
1595 * scopes reads the most specific mention of a name first */
1596 SV **sh = hv_fetchs(h, K_HEADERS_SCOPED, 0);
1597 # uncoverable condition right count:2 class:ignore_covered_err
1598 # uncoverable condition right count:3 class:ignore_covered_err
1599 # uncoverable condition right count:4 class:ignore_covered_err
1600 if (sh && *sh && SvROK(*sh) && SvTYPE(SvRV(*sh)) == SVt_PVAV) {
1601 AV *src = (AV *)SvRV(*sh);
1602 SSize_t si, sn = av_len(src) + 1;
1603 AV *outav = newAV();
1604 for (si = 0; si < sn; si++) {
1605 SV **rp = av_fetch(src, si, 0);
1606 HV *rec, *out;
1607 SV **x;
1608 STRLEN pfl = 0;
1609 # uncoverable branch true
1610 # uncoverable condition left count:1 class:ignore_covered_err
1611 # uncoverable condition left count:2 class:ignore_covered_err
1612 # uncoverable condition left count:3 class:ignore_covered_err
1613 if (!(rp && *rp && SvROK(*rp))) continue;
1614 rec = (HV *)SvRV(*rp);
1615 out = newHV();
1616 x = hv_fetchs(rec, K_PREFIX, 0);
1617 # uncoverable branch false
1618 # uncoverable condition right count:1 class:ignore_covered_err
1619 # uncoverable condition right count:2 class:ignore_covered_err
1620 # uncoverable condition right count:3 class:ignore_covered_err
1621 if (x && *x && SvOK(*x)) (void)SvPV_const(*x, pfl);
1622 (void)hv_stores(out, K_PREFIX,
1623 (x && *x && SvOK(*x)) ? newSVsv(*x) : newSVpvs(""));
1624 (void)hv_stores(out, K_LEN, newSViv((IV)pfl));
1625 x = hv_fetchs(rec, K_HEADERS, 0);
1626 # uncoverable branch false
1627 # uncoverable condition right count:1 class:ignore_covered_err
1628 # uncoverable condition right count:2 class:ignore_covered_err
1629 # uncoverable condition right count:3 class:ignore_covered_err
1630 # uncoverable condition right count:4 class:ignore_covered_err
1631 if (x && *x && SvROK(*x)
1632 && SvTYPE(SvRV(*x)) == SVt_PVHV)
1633 (void)hv_stores(out, K_HEADERS, newRV_noinc(
1634 (SV *)phd_flat(aTHX_ (HV *)SvRV(*x))));
1635 av_push(outav, newRV_noinc((SV *)out));
1636 }
1637 if (av_len(outav) > 0)
1638 sortsv(AvARRAY(outav), (STRLEN)(av_len(outav) + 1),
1639 pc_cmp_len_desc);
1640 # uncoverable branch false
1641 # uncoverable condition right count:1 class:ignore_covered_err
1642 if (av_len(outav) >= 0) {
1643 (void)hv_stores(state, K_HEADERS_SCOPED,
1644 newRV_noinc((SV *)outav));
1645 # uncoverable branch true
1646 # uncoverable condition left count:1 class:ignore_covered_err
1647 if (!pk_require_once(aTHX_ "Punk::Headers", FALSE))
1648 croak("Punk: headers needs Punk::Headers, which " /* # uncoverable statement */
1649 "failed to load: %s", SvPV_nolen(ERRSV)); /* # uncoverable statement */
1650 }
1651 else SvREFCNT_dec((SV *)outav); /* # uncoverable statement */
1652 }
1653 }
1654 {
1655 SV **nf = hv_fetchs(h, K_ON_NOT_FOUND, 0);
1656 SV *on_nf = &PL_sv_undef;
1657 # uncoverable condition right count:2 class:ignore_covered_err
1658 # uncoverable condition right count:3 class:ignore_covered_err
1659 if (nf && *nf && SvOK(*nf)) {
1660 SV *what = sv_2mortal(newSVpvs(K_ON_NOT_FOUND));
1661 on_nf = sv_2mortal(pc_resolve_target(aTHX_ self, *nf, what));
1662 }
1663 (void)hv_stores(state, K_ON_NOT_FOUND, newSVsv(on_nf));
1664 }
1665 {
1666 SV **oe = hv_fetchs(h, K_ON_ERROR, 0);
1667 SV *on_err = &PL_sv_undef;
1668 # uncoverable condition right count:1 class:ignore_covered_err
1669 # uncoverable condition right count:2 class:ignore_covered_err
1670 if (oe && *oe && SvOK(*oe)) {
1671 SV *what = sv_2mortal(newSVpvs(K_ON_ERROR));
1672 on_err = sv_2mortal(pc_resolve_target(aTHX_ self, *oe, what));
1673 }
1674 (void)hv_stores(state, K_ON_ERROR, newSVsv(on_err));
1675 }
1676 PERL_UNUSED_VAR(caller);
1677  
1678 state_rv = sv_2mortal(newRV_noinc((SV *)state));
1679 {
1680 AV *acap = newAV();
1681 av_push(acap, newSVsv(state_rv));
1682 /* the same state read once into a struct (punk_state.h); it
1683 * borrows from the hash in slot 0, which the capture keeps */
1684 av_push(acap, pk_state_build(aTHX_ state));
1685 app_cv = punk_closure(aTHX_ pc_app_cb, acap);
1686 }
1687  
1688 /* wrap in middleware, innermost last (reverse registration order):
1689 * $app = $mw->($app) - a coderef call, our +1 on the old app handed in
1690 * and released by the call scope. */
1691 mw = app_av(aTHX_ h, K_MIDDLEWARE);
1692 for (i = av_len(mw); i >= 0; i--) {
1693 SV **wp = av_fetch(mw, i, 0);
1694 SV *wrapped; dSP; int count;
1695 # uncoverable branch true class:ignore_covered_err
1696 # uncoverable condition left count:1 class:ignore_covered_err
1697 # uncoverable condition left count:2 class:ignore_covered_err
1698 if (!wp || !*wp) continue;
1699 ENTER; SAVETMPS;
1700 PUSHMARK(SP); EXTEND(SP, 1);
1701 PUSHs(sv_2mortal(app_cv));
1702 PUTBACK;
1703 count = call_sv(*wp, G_SCALAR);
1704 SPAGAIN;
1705 wrapped = count > 0 ? SvREFCNT_inc(POPs) : newSV(0); /* # uncoverable condition right count:1 class:ignore_covered_err */
1706 PUTBACK; FREETMPS; LEAVE;
1707 app_cv = wrapped;
1708 }
1709  
1710 { SV **cp = hv_fetchs(h, K_COMPILED, 0);
1711 (void)hv_stores(h, K_COMPILED,
1712 newSViv((cp && *cp && SvOK(*cp) ? SvIV(*cp) : 0) + 1)); }
1713 RETVAL = app_cv;
1714 }
1715 OUTPUT:
1716 RETVAL
« include/punk/punk_ua.h ↑ Summary xs/scope.xs »