xs/context.xs

filter: Statementstmt 96.1% 25 / 26 Branchbran 63.3% 19 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 78.5% 44 / 56 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/context_vars/context_vars_abi_impl.h ↑ Summary Vars.xs »
1 # Capturing a context, running code in one, and the object that holds one.
2  
3 MODULE = Context::Vars PACKAGE = Context::Vars
4  
5 # What is current now, kept: a Context::Vars::Context.
6 void
7 capture(klass)
8 SV *klass
9 PPCODE:
10 PERL_UNUSED_VAR(klass);
11 16 ▶ XPUSHs(context_vars_obj_new(aTHX_ context_vars_capture(aTHX)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(context_vars_obj_new(aTHX_ context_vars_capture(aTHX))); 0 16 16
12  
13 # The current context itself, not a copy of it.
14 void
15 current(klass)
16 SV *klass
17 PPCODE:
18 PERL_UNUSED_VAR(klass);
19 1 ▶ XPUSHs(context_vars_obj_new(aTHX_
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(context_vars_obj_new(aTHX_ 0 1 1
20 context_vars_retain(aTHX_ context_vars_current(aTHX))));
21  
22 # A code reference that runs `code` in a fresh copy of what is current now,
23 # each time it is called.
24 void
25 wrap(klass, code)
26 SV *klass
27 SV *code
28 PPCODE:
29 PERL_UNUSED_VAR(klass);
30 5037 SvGETMAGIC(code);
31 5037 ▶ if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 5036 1 5037
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 0 5036 5036
32 1 croak("Context::Vars::wrap: not a code reference");
33 5036 ▶ XPUSHs(context_vars_wrap_new(aTHX_ context_vars_capture(aTHX), code));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(context_vars_wrap_new(aTHX_ context_vars_capture(aTHX), code)); 0 5036 5036
34  
35 MODULE = Context::Vars PACKAGE = Context::Vars::Context
36  
37 void
38 run(self, code, ...)
39 SV *self
40 SV *code
41 PPCODE:
42 {
43 32 context_vars_ctx *c = context_vars_obj(aTHX_ self, "Context::Vars::Context::run");
44 I32 count;
45 25 SvGETMAGIC(code);
46 25 ▶ if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 24 1 25
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 0 24 24
47 1 croak("Context::Vars::Context::run: not a code reference");
48 24 PUTBACK;
49 24 count = context_vars_call_in(aTHX_ c, 0, code, &ST(2), items - 2, GIMME_V, ax);
50 23 XSRETURN(count);
51 }
52  
53 # The names set in the context, sorted, without their sigils.
54 void
55 names(self)
56 SV *self
57 PPCODE:
58 {
59 12 context_vars_ctx *c = context_vars_obj(aTHX_ self, "Context::Vars::Context::names");
60 5 AV *av = (AV *)sv_2mortal((SV *)newAV());
61 I32 i, n;
62 5 (CONTEXT_VARS_HAMT->map_walk)(aTHX_ c->map, context_vars_names_cb, av);
63 5 sortsv(AvARRAY(av), av_len(av) + 1, Perl_sv_cmp);
64 5 n = (I32)(av_len(av) + 1);
65 5 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 5 0 5
EXTEND(SP, n); 0 5 5
66 14 ▶ for (i = 0; i < n; i++) PUSHs(sv_2mortal(newSVsv(AvARRAY(av)[i])));
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) PUSHs(sv_2mortal(newSVsv(AvARRAY(av)[i]))); 9 5 14
67 }
68  
69 # The value of one name in the context, without entering it. The name may be
70 # given with or without its sigil.
71 void
72 get(self, name)
73 SV *self
74 SV *name
75 PPCODE:
76 {
77 27 context_vars_ctx *c = context_vars_obj(aTHX_ self, "Context::Vars::Context::get");
78 STRLEN len;
79 20 const char *p = SvPV(name, len);
80 SV *held;
81 20 ▶ if (len && p[0] == '$') { p++; len--; }
Branch: 2 branches
BranchTrueFalseTotal
if (len && p[0] == '$') { p++; len--; } 20 0 20
if (len && p[0] == '$') { p++; len--; } 1 19 20
82 20 held = (CONTEXT_VARS_HAMT->map_fetch)(aTHX_ c->map, p, len, 0);
83 20 ▶ XPUSHs(held ? sv_2mortal(newSVsv(held)) : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(held ? sv_2mortal(newSVsv(held)) : &PL_sv_undef); 0 20 20
XPUSHs(held ? sv_2mortal(newSVsv(held)) : &PL_sv_undef); 18 2 20
84 }
85  
86 int
87 CLONE_SKIP(...)
88 CODE:
89 PERL_UNUSED_VAR(items);
90 0 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 0 0
91 OUTPUT:
92 RETVAL
« include/context_vars/context_vars_abi_impl.h ↑ Summary Vars.xs »