xs/stencil.xs

filter: Statementstmt 95.4% 21 / 22 Branchbran 55.5% 11 / 18 (1 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 77.5% 32 / 40 (1 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_csp.h ↑ Summary include/punk/punk_scope.h »
1 MODULE = Punk PACKAGE = Punk::View::Stencil
2  
3 PROTOTYPES: DISABLE
4  
5 # The shipped view engine (punk_stencil.h). Two array slots - the options as
6 # registered and the Template::Stencil object built from them - and a render
7 # that reaches the template VM through Template::Stencil's C ABI, so no Perl
8 # frame sits between the dispatcher and the engine. lib/Punk/View/Stencil.pm
9 # is documentation only.
10  
11 # new(\%opts) or new(%opts). Punk::Views (punk_views.h) hands the registered
12 # options as one positional hashref; the list form is for anyone constructing
13 # the view directly. Builds the Template::Stencil engine here and now, so an
14 # option it will not accept fails at boot with the rest of the configuration
15 # rather than on the first render.
16 SV *
17 new(class, ...)
18 SV *class
19 CODE:
20 {
21 HV *opts;
22 SV *opts_rv;
23 AV *av;
24 69 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 68 1 69
# uncoverable condition right count:2 class:ignore_covered_err 68 0 68
# uncoverable condition right count:2 class:ignore_covered_err 68 0 68
25 68 # uncoverable condition right count:3 class:ignore_covered_err
26 68 if (items == 2 && SvROK(ST(1)) && SvTYPE(SvRV(ST(1))) == SVt_PVHV) {
27 opts = (HV *)SvRV(ST(1));
28 SvREFCNT_inc((SV *)opts);
29 }
30 1 ▶ else {
Branch: 1 branch
BranchTrueFalseTotal
else { 0 1 1
31 0 int i;
32 1 # uncoverable branch true
33 2 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 1 1 2
34 1 if (!(items % 2))
35 croak("Punk::View::Stencil->new: odd number of options"); /* # uncoverable statement */
36 69 opts = newHV();
37 for (i = 1; i + 1 < items; i += 2)
38 (void)hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0);
39 }
40 69 opts_rv = sv_2mortal(newRV_noinc((SV *)opts));
41  
42 68 /* resolve the ABI before building anything, so a missing or too-old
43 68 * Template::Stencil is a boot error naming the version it needs */
44 68 (void)punk_st(aTHX);
45 68  
46 67 av = newAV();
47 av_extend(av, PVS_ENGINE);
48 (void)av_store(av, PVS_OPTS, newSVsv(opts_rv));
49 (void)av_store(av, PVS_ENGINE, pvs_build_engine(aTHX_ opts_rv));
50 RETVAL = sv_bless(newRV_noinc((SV *)av), gv_stashsv(class, GV_ADD));
51 }
52 OUTPUT:
53 RETVAL
54  
55 # render($template, \%data, \%opts?) - one indirect call into Template::Stencil
56 # and back. The bytes belong to the caller; Punk::Views copies them into the
57 # response body rather than letting a lexical steal the buffer.
58 SV *
59 render(self, template, data = &PL_sv_undef, opts = &PL_sv_undef)
60 SV *self
61 SV *template
62 SV *data
63 SV *opts
64 CODE:
65 2175 RETVAL = pvs_render(aTHX_ self, template, data, opts);
66 OUTPUT:
67 RETVAL
68  
69 # The registered options, and the Template::Stencil object itself for anything
70 # that wants to reach past the adapter. Both read/write, as the slots were.
71 SV *
72 opts(self, ...)
73 SV *self
74 ALIAS:
75 engine = 1
76 CODE:
77 {
78 2 AV *av = pvs_av(aTHX_ self);
79 2 I32 slot = ix ? PVS_ENGINE : PVS_OPTS;
80 SV **e;
81 2 ▶ # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch true 0 2 2
82 2 # uncoverable condition left count:1 class:ignore_covered_err
83 2 ▶ if (items > 1) (void)av_store(av, slot, newSVsv(ST(1)));
Branch: 2 branches
BranchTrueFalseTotal
if (items > 1) (void)av_store(av, slot, newSVsv(ST(1))); 2 0 2
if (items > 1) (void)av_store(av, slot, newSVsv(ST(1))); 2 0 2
84 e = av_fetch(av, slot, 0);
85 # uncoverable condition right count:1 class:ignore_covered_err
86 # uncoverable condition right count:2 class:ignore_covered_err
87 RETVAL = (e && *e) ? newSVsv(*e) : newSV(0);
88 }
89 OUTPUT:
90 RETVAL
91  
92 # Whether the C ABI resolved - the guard test drives this with
93 # PUNK_FAKE_ST_BAD to prove the boot-time croak, since there is no Perl
94 # render path to fall back to.
95 IV
96 _abi_ok()
97 CODE:
98 7 ▶ RETVAL = punk_st_try(aTHX) ? 1 : 0; /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = punk_st_try(aTHX) ? 1 : 0; /* # uncoverable condition left count:1 class:ignore_covered_err */ 0 7 7
99 OUTPUT:
100 RETVAL
« include/punk/punk_csp.h ↑ Summary include/punk/punk_scope.h »