xs/dispatch.xs

filter: Statementstmt 11.1% 2 / 18 Branchbran 7.6% 2 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 9.0% 4 / 44 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/serve.xs ↑ Summary xs/sse.xs »
1 MODULE = Punk PACKAGE = Punk
2  
3 PROTOTYPES: DISABLE
4  
5 # True when Open::API's C ABI (oa_abi.h) resolved at the compiled-against
6 # OA_ABI_VERSION. It always should - Open::API 0.04+ is a hard prerequisite -
7 # so this is really only for the guard test; punk_oa croaks on the request
8 # path if the table is missing. PUNK_FAKE_OA_BAD simulates a version mismatch.
9 int
10 _oa_available()
11 CODE:
12 11 ▶ RETVAL = punk_oa_try(aTHX) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = punk_oa_try(aTHX) ? 1 : 0; 0 11 11
13 OUTPUT:
14 RETVAL
15  
16 # The ABI version this was compiled against, for the guard test.
17 int
18 _oa_abi_version()
19 CODE:
20 5 ▶ RETVAL = OA_ABI_VERSION;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = OA_ABI_VERSION; 0 5 5
21 OUTPUT:
22 RETVAL
23  
24 # Dispatch one matched API operation entirely in C: the before-dispatch hooks
25 # and the operation's guards (short-circuitable), the 413/501 checks, raw-input
26 # assembly and validation through the ABI, stashing the typed params, and the
27 # controller call. Returns ($ret, $err) for Punk::App's finish path - $ret the
28 # controller's value or an early PSGI triplet (400/413/501/guard short-circuit),
29 # $err a die message or undef. The hooks, guards and controller are the only
30 # Perl frames.
31 void
32 _oa_dispatch(c, before, rec, api, op_id, caps, max_body)
33 SV *c
34 SV *before
35 SV *rec
36 SV *api
37 SV *op_id
38 SV *caps
39 IV max_body
40 PPCODE:
41 {
42 AV *before_av;
43 HV *rech;
44 SV *ret, *err;
45 0 ▶ if (!SvROK(rec) || SvTYPE(SvRV(rec)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(rec) || SvTYPE(SvRV(rec)) != SVt_PVHV) 0 0 0
if (!SvROK(rec) || SvTYPE(SvRV(rec)) != SVt_PVHV) 0 0 0
46 0 croak("Punk::_oa_dispatch: rec must be a hashref");
47 0 ▶ before_av = (SvROK(before) && SvTYPE(SvRV(before)) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
before_av = (SvROK(before) && SvTYPE(SvRV(before)) == SVt_PVAV) 0 0 0
48 0 ▶ ? (AV *)SvRV(before) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(before) : NULL; 0 0 0
49 0 rech = (HV *)SvRV(rec);
50 0 punk_oa_dispatch(aTHX_ c, before_av, rech, api, op_id, caps,
51 max_body, &ret, &err);
52 0 SP = PL_stack_base + ax - 1; /* hooks and the controller ran */
53 0 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 0 0
54 0 ▶ PUSHs(ret == &PL_sv_undef ? ret : sv_2mortal(ret));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(ret == &PL_sv_undef ? ret : sv_2mortal(ret)); 0 0 0
55 0 ▶ PUSHs(err == &PL_sv_undef ? err : sv_2mortal(err));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(err == &PL_sv_undef ? err : sv_2mortal(err)); 0 0 0
56 }
57  
58 # Coerce a handler return into a PSGI triplet (triplet passthrough,
59 # Punk::Response, awaited Future, or JSON), folding in the context's pending
60 # status/headers. The response-finish path, in C.
61 SV *
62 _coerce(c, ret)
63 SV *c
64 SV *ret
65 CODE:
66 0 RETVAL = punk_coerce(aTHX_ c, ret);
67 OUTPUT:
68 RETVAL
69  
70 # Finish a response: coerce if needed, run the after-dispatch hooks (each may
71 # replace the triplet), blank the body on HEAD.
72 SV *
73 _deliver(c, resp, method, after)
74 SV *c
75 SV *resp
76 SV *method
77 SV *after
78 CODE:
79 {
80 STRLEN ml;
81 0 const char *m = SvPV_const(method, ml);
82 0 ▶ int is_head = (ml == 4 && memEQ(m, "HEAD", 4));
Branch: 2 branches
BranchTrueFalseTotal
int is_head = (ml == 4 && memEQ(m, "HEAD", 4)); 0 0 0
int is_head = (ml == 4 && memEQ(m, "HEAD", 4)); 0 0 0
83 0 ▶ AV *after_av = (SvROK(after) && SvTYPE(SvRV(after)) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
AV *after_av = (SvROK(after) && SvTYPE(SvRV(after)) == SVt_PVAV) 0 0 0
84 0 ▶ ? (AV *)SvRV(after) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(after) : NULL; 0 0 0
85 0 RETVAL = punk_deliver(aTHX_ c, resp, is_head, after_av);
86 }
87 OUTPUT:
88 RETVAL
« xs/serve.xs ↑ Summary xs/sse.xs »