include/st_abi_impl.h

filter: Statementstmt 82.3% 14 / 17 Branchbran 65.0% 13 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 72.9% 27 / 37 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/stencil_expfix.h ↑ Summary src/stencil_boot.c »
1 #ifndef ST_ABI_IMPL_H
2 #define ST_ABI_IMPL_H
3  
4 /* Template::Stencil-side implementation of the shared C ABI (st_abi.h).
5 * Included by Stencil.xs AFTER stencil_obj_vtbl and stencil_build_engine are
6 * in scope, since the engine hangs off the object as ext magic. Everything
7 * here is private to this translation unit; consumers reach it only through
8 * the ST_ABI table returned by Template::Stencil::_abi_ptr. */
9  
10 #include "st_abi.h"
11  
12 /* Like stencil_engine_of but returns NULL where that croaks: a consumer
13 * probing whether an object is renderable through the ABI must be able to ask
14 * without an eval. The lazy build is the same one the render method does, so
15 * an object that has never rendered - or a clone that dropped its engine on
16 * ithread dup - still hands back a working engine here. */
17 73 static void *st_abi_engine_of(pTHX_ SV *obj_sv)
18 {
19 SV *rv;
20 MAGIC *mg;
21 73 ▶ if (!obj_sv || !SvROK(obj_sv)) return NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (!obj_sv || !SvROK(obj_sv)) return NULL; 73 0 73
if (!obj_sv || !SvROK(obj_sv)) return NULL; 3 70 73
22 70 rv = SvRV(obj_sv);
23 70 ▶ if (SvTYPE(rv) != SVt_PVHV
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(rv) != SVt_PVHV 69 1 70
24 70 ▶ || !sv_derived_from(obj_sv, "Template::Stencil")) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(obj_sv, "Template::Stencil")) return NULL; 1 68 69
25 68 mg = mg_findext(rv, PERL_MAGIC_ext, &stencil_obj_vtbl);
26 68 ▶ if (!mg) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!mg) return NULL; 0 68 68
27 68 ▶ if (!mg->mg_ptr)
Branch: 1 branch
BranchTrueFalseTotal
if (!mg->mg_ptr) 0 68 68
28 0 mg->mg_ptr = (char *)stencil_build_engine(aTHX_ (HV *)rv);
29 68 return (void *)mg->mg_ptr;
30 }
31  
32 /* The whole render path, minus the XS prologue and the croak. Errors come back
33 * through *err exactly as stencil_engine_render sets them (the render, engine
34 * and compile cores never croak), so a consumer can turn a template error into
35 * its own 500 rather than an exception it has to catch. */
36 68 static SV *st_abi_render(pTHX_ void *engine, SV *tmpl, HV *data,
37 SV *opts, SV **err)
38 {
39 68 stencil_engine *e = (stencil_engine *)engine;
40 HV *dhv;
41 68 ▶ if (!e || !tmpl) {
Branch: 2 branches
BranchTrueFalseTotal
if (!e || !tmpl) { 68 0 68
if (!e || !tmpl) { 0 68 68
42 0 ▶ if (err) *err = sv_2mortal(newSVpvs(
Branch: 1 branch
BranchTrueFalseTotal
if (err) *err = sv_2mortal(newSVpvs( 0 0 0
43 "Template::Stencil: render needs an engine and a template"));
44 0 return NULL;
45 }
46 68 ▶ dhv = data ? data : (HV *)sv_2mortal((SV *)newHV());
Branch: 1 branch
BranchTrueFalseTotal
dhv = data ? data : (HV *)sv_2mortal((SV *)newHV()); 4 64 68
47 68 return stencil_engine_render(aTHX_ e, tmpl, dhv, opts, err);
48 }
49  
50 static const st_abi ST_ABI = {
51 ST_ABI_VERSION,
52 st_abi_engine_of,
53 st_abi_render,
54 };
55  
56 #endif /* ST_ABI_IMPL_H */
« include/stencil_expfix.h ↑ Summary src/stencil_boot.c »