include/punk/punk_config.h

filter: Statementstmt 94.3% 168 / 178 Branchbran 70.1% 134 / 204 (16 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 81.4% 302 / 382 (16 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_views.h ↑ Summary include/punk/punk_cachefile.h »
1 /* punk_config.h - configuration: layered YAML, resolved secrets.
2 *
3 * Boot-time work, in C for the same reason the rest of Punk is: one
4 * implementation, one place. YAML parsing itself is the exception - it
5 * goes through YAML::XS with a single call per file (the shim Open::API
6 * uses), which at once-per-boot costs nothing worth a parser of our own.
7 *
8 * The rule the design follows: a config file says WHERE a secret comes
9 * from, never what it is. A reference is a single-key hash whose key
10 * starts with '$' - a shape nothing else in a config has, and one that
11 * needs nothing from the parser:
12 *
13 * password: { $env: DB_PASSWORD }
14 *
15 * Resolved values land in `secrets` (dotted path -> value) and in
16 * `resolved`; `public` is the same tree with every secret replaced by
17 * [redacted], so it can be logged or serialised safely.
18 */
19  
20 #ifndef PUNK_CONFIG_H
21 #define PUNK_CONFIG_H
22  
23 typedef struct punk_config {
24 HV *public; /* redacted copy */
25 HV *resolved; /* real values */
26 HV *secrets; /* dotted path -> resolved value */
27 AV *files; /* the layers actually read */
28 SV *file; /* the base path as given */
29 SV *env; /* environment name */
30 } punk_config;
31  
32 182 static punk_config *punk_config_of(pTHX_ SV *self) {
33 /*
34 # uncoverable branch true
35 # uncoverable condition left count:1 class:ignore_covered_err
36 # uncoverable condition left count:2 class:ignore_covered_err */
37 182 ▶ if (!SvROK(self) || !SvIOK(SvRV(self)))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(self) || !SvIOK(SvRV(self))) 182 0 182
if (!SvROK(self) || !SvIOK(SvRV(self))) 0 182 182
38 0 croak("Punk::Config: not a config handle"); /* # uncoverable statement */
39 182 return (punk_config *)INT2PTR(void *, SvIV(SvRV(self)));
40 }
41  
42 /* ---- YAML ---------------------------------------------------------------- */
43  
44 /* One document through YAML::XS. The shim localises the boolean class so
45 * true/false decode like JSON booleans, the way Open::API does it. */
46 75 static SV *pc_yaml_decode(pTHX_ SV *text, const char *path) {
47 75 dSP;
48 int count;
49 SV *ret;
50 static int shim = 0;
51 /*
52 # uncoverable branch true
53 # uncoverable condition left count:1 class:ignore_covered_err */
54 75 ▶ if (!pk_require_once(aTHX_ "YAML::XS", FALSE))
Branch: 1 branch
BranchTrueFalseTotal
if (!pk_require_once(aTHX_ "YAML::XS", FALSE)) 0 75 75
55 0 croak("Punk::Config: reading '%s' needs YAML::XS (not installed)", /* # uncoverable statement */
56 path); /* # uncoverable statement */
57 75 ▶ if (!shim) {
Branch: 1 branch
BranchTrueFalseTotal
if (!shim) { 33 42 75
58 33 eval_pv(
59 "sub Punk::Config::_yaml_load {"
60 " local $YAML::XS::Boolean ="
61 " eval { require JSON::PP; 1 } ? 'JSON::PP' : $YAML::XS::Boolean;"
62 /* a config file is data; an object tag in it must not bless */
63 " local $YAML::XS::LoadBlessed = 0;"
64 " YAML::XS::Load($_[0]);"
65 "}", TRUE);
66 33 shim = 1;
67 }
68 /* Both eval_pv calls above can grow (and so reallocate) the value stack;
69 * SP was captured before them, and the push below would write through
70 * it. */
71 75 SPAGAIN;
72 75 ▶ ENTER; SAVETMPS; PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); 0 75 75
73 75 ▶ XPUSHs(text);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(text); 0 75 75
74 75 PUTBACK;
75 75 count = call_pv("Punk::Config::_yaml_load", G_SCALAR | G_EVAL);
76 75 SPAGAIN;
77 /*
78 # uncoverable branch true
79 # uncoverable condition right count:1 class:ignore_covered_err
80 # uncoverable condition left count:2 class:ignore_covered_err */
81 75 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 75 0 75
if (SvTRUE(ERRSV)) { 0 75 75
82 0 ▶ SV *e = newSVsv(ERRSV); /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
SV *e = newSVsv(ERRSV); /* # uncoverable statement */ 0 0 0
83 0 ▶ PUTBACK; FREETMPS; LEAVE; /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; /* # uncoverable statement */ 0 0 0
84 0 croak("Punk::Config: '%s' is not valid YAML: %s", path, /* # uncoverable statement */
85 SvPV_nolen(sv_2mortal(e))); /* # uncoverable statement */
86 }
87 75 ▶ ret = count > 0 ? newSVsv(POPs) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
ret = count > 0 ? newSVsv(POPs) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ 75 0 75
88 75 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 75 0 75
89 75 return sv_2mortal(ret);
90 }
91  
92 /* Slurp a file into a mortal SV, or NULL when it cannot be opened. */
93 203 static SV *pc_slurp(pTHX_ const char *path) {
94 203 PerlIO *fh = PerlIO_open(path, "rb");
95 SV *sv;
96 char buf[8192];
97 SSize_t n;
98 203 ▶ if (!fh) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) return NULL; 126 77 203
99 77 sv = sv_2mortal(newSVpvs(""));
100 154 ▶ while ((n = PerlIO_read(fh, buf, sizeof buf)) > 0)
Branch: 1 branch
BranchTrueFalseTotal
while ((n = PerlIO_read(fh, buf, sizeof buf)) > 0) 77 77 154
101 77 sv_catpvn(sv, buf, (STRLEN)n);
102 77 PerlIO_close(fh);
103 77 return sv;
104 }
105  
106 /* ---- merge ---------------------------------------------------------------
107 * Later layers win. Hashes merge key by key; anything else replaces, so an
108 * array in an overlay is a replacement rather than an append. */
109 /* How deep a document may nest. A YAML alias cycle is unbounded, and the
110 * walk below copies subtrees, so an alias bomb is exponential: both end
111 * here with a message instead of a stack or the machine. */
112 #define PC_MAX_DEPTH 64
113  
114 20 static SV *pc_merge(pTHX_ SV *base, SV *over, int depth) {
115 HV *bh, *oh, *out;
116 /*
117 # uncoverable branch true
118 # uncoverable condition left count:1 class:ignore_covered_err */
119 20 ▶ if (depth > PC_MAX_DEPTH)
Branch: 1 branch
BranchTrueFalseTotal
if (depth > PC_MAX_DEPTH) 0 20 20
120 0 croak("Punk::Config: nested deeper than %d levels (an alias " /* # uncoverable statement */
121 "cycle?)", PC_MAX_DEPTH);
122 HE *he;
123 /*
124 # uncoverable condition left count:1 class:ignore_covered_err
125 # uncoverable condition left count:4 class:ignore_covered_err
126 # uncoverable condition left count:5 class:ignore_covered_err
127 # uncoverable condition left count:6 class:ignore_covered_err */
128 20 ▶ if (!(base && SvROK(base) && SvTYPE(SvRV(base)) == SVt_PVHV
Branch: 3 branches
BranchTrueFalseTotal
if (!(base && SvROK(base) && SvTYPE(SvRV(base)) == SVt_PVHV 20 0 20
if (!(base && SvROK(base) && SvTYPE(SvRV(base)) == SVt_PVHV 15 5 20
if (!(base && SvROK(base) && SvTYPE(SvRV(base)) == SVt_PVHV 14 1 15
129 14 ▶ && over && SvROK(over) && SvTYPE(SvRV(over)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
&& over && SvROK(over) && SvTYPE(SvRV(over)) == SVt_PVHV)) 14 0 14
&& over && SvROK(over) && SvTYPE(SvRV(over)) == SVt_PVHV)) 14 0 14
&& over && SvROK(over) && SvTYPE(SvRV(over)) == SVt_PVHV)) 0 14 14
130 6 return newSVsv(over);
131 14 bh = (HV *)SvRV(base);
132 14 oh = (HV *)SvRV(over);
133 14 out = newHV();
134 14 hv_iterinit(bh);
135 41 ▶ while ((he = hv_iternext(bh)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(bh))) 27 14 41
136 27 ▶ (void)hv_store_ent(out, HeSVKEY_force(he), newSVsv(HeVAL(he)), 0);
Branch: 2 branches
BranchTrueFalseTotal
(void)hv_store_ent(out, HeSVKEY_force(he), newSVsv(HeVAL(he)), 0); 27 0 27
(void)hv_store_ent(out, HeSVKEY_force(he), newSVsv(HeVAL(he)), 0); 0 27 27
137 14 hv_iterinit(oh);
138 29 ▶ while ((he = hv_iternext(oh))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(oh))) { 15 14 29
139 15 ▶ SV *key = HeSVKEY_force(he);
Branch: 2 branches
BranchTrueFalseTotal
SV *key = HeSVKEY_force(he); 15 0 15
SV *key = HeSVKEY_force(he); 0 15 15
140 15 HE *have = hv_fetch_ent(out, key, 0, 0);
141 10 SV *merged = have ? pc_merge(aTHX_ HeVAL(have), HeVAL(he), depth + 1)
142 15 ▶ : newSVsv(HeVAL(he));
Branch: 1 branch
BranchTrueFalseTotal
: newSVsv(HeVAL(he)); 10 5 15
143 15 (void)hv_store_ent(out, key, merged, 0);
144 }
145 14 return newRV_noinc((SV *)out);
146 }
147  
148 /* ---- secret references ---------------------------------------------------
149 * A single-key hash whose key starts with '$'. Returns the key SV (borrowed)
150 * or NULL, setting *arg to the value. */
151 379 static SV *pc_reference(pTHX_ SV *node, SV **arg) {
152 HV *hv;
153 HE *he;
154 SV *key;
155 379 ▶ if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV)) return NULL; /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 3 branches
BranchTrueFalseTotal
if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV)) return NULL; /* # uncoverable condition left count:1 class:ignore_covered_err */ 379 0 379
if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV)) return NULL; /* # uncoverable condition left count:1 class:ignore_covered_err */ 264 115 379
if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV)) return NULL; /* # uncoverable condition left count:1 class:ignore_covered_err */ 11 253 264
156 253 hv = (HV *)SvRV(node);
157 253 ▶ if (HvUSEDKEYS(hv) != 1) return NULL; /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (HvUSEDKEYS(hv) != 1) return NULL; /* # uncoverable condition left count:1 class:ignore_covered_err */ 0 253 253
if (HvUSEDKEYS(hv) != 1) return NULL; /* # uncoverable condition left count:1 class:ignore_covered_err */ 69 184 253
158 184 hv_iterinit(hv);
159 184 he = hv_iternext(hv);
160 /*
161 # uncoverable branch true
162 # uncoverable condition left count:1 class:ignore_covered_err */
163 184 ▶ if (!he) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!he) return NULL; 0 184 184
164 184 ▶ key = HeSVKEY_force(he);
Branch: 2 branches
BranchTrueFalseTotal
key = HeSVKEY_force(he); 184 0 184
key = HeSVKEY_force(he); 0 184 184
165 184 ▶ if (SvCUR(key) < 2 || *SvPVX(key) != '$') return NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (SvCUR(key) < 2 || *SvPVX(key) != '$') return NULL; 117 67 184
if (SvCUR(key) < 2 || *SvPVX(key) != '$') return NULL; 97 20 117
166 20 *arg = HeVAL(he);
167 20 return key;
168 }
169  
170 /* Trim one trailing newline, the way a secret file or a command's output
171 * carries one. */
172 3 static void pc_chomp(pTHX_ SV *sv) {
173 STRLEN len;
174 char *p;
175 /*
176 # uncoverable branch true
177 # uncoverable condition left count:1 class:ignore_covered_err */
178 3 ▶ if (!SvOK(sv)) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(sv)) return; 0 3 3
179 3 p = SvPV(sv, len);
180 /*
181 # uncoverable branch false
182 # uncoverable condition right count:1 class:ignore_covered_err
183 # uncoverable condition right count:2 class:ignore_covered_err */
184 3 ▶ if (len && p[len - 1] == '\n') len--;
Branch: 2 branches
BranchTrueFalseTotal
if (len && p[len - 1] == '\n') len--; 3 0 3
if (len && p[len - 1] == '\n') len--; 3 0 3
185 /*
186 # uncoverable branch true
187 # uncoverable condition left count:1 class:ignore_covered_err
188 # uncoverable condition right count:1 class:ignore_covered_err
189 # uncoverable condition left count:2 class:ignore_covered_err */
190 3 ▶ if (len && p[len - 1] == '\r') len--;
Branch: 2 branches
BranchTrueFalseTotal
if (len && p[len - 1] == '\r') len--; 3 0 3
if (len && p[len - 1] == '\r') len--; 0 3 3
191 3 SvCUR_set(sv, len);
192 3 p[len] = '\0';
193 }
194  
195 /* Resolve one reference. Returns an owned SV, or croaks - a secret that
196 * cannot be fetched must stop the boot, never become an empty password. */
197 20 static SV *pc_resolve(pTHX_ SV *key, SV *arg, const char *where) {
198 STRLEN klen;
199 20 const char *k = SvPV_const(key, klen);
200  
201 20 ▶ if (klen == 4 && memEQ(k, "$env", 4)) { /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (klen == 4 && memEQ(k, "$env", 4)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 7 13 20
if (klen == 4 && memEQ(k, "$env", 4)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 7 0 7
202 STRLEN nlen;
203 7 const char *name = SvPV_const(arg, nlen);
204 7 const char *val = getenv(name);
205 7 ▶ if (!val)
Branch: 1 branch
BranchTrueFalseTotal
if (!val) 3 4 7
206 3 croak("Punk::Config: %s wants the environment variable '%s', "
207 "which is not set", where, name);
208 4 return newSVpv(val, 0);
209 }
210 13 ▶ if (klen == 5 && memEQ(k, "$file", 5)) {
Branch: 2 branches
BranchTrueFalseTotal
if (klen == 5 && memEQ(k, "$file", 5)) { 7 6 13
if (klen == 5 && memEQ(k, "$file", 5)) { 5 2 7
211 5 const char *path = SvPV_nolen(arg);
212 5 SV *body = pc_slurp(aTHX_ path);
213 SV *out;
214 5 ▶ if (!body)
Branch: 1 branch
BranchTrueFalseTotal
if (!body) 3 2 5
215 3 croak("Punk::Config: %s cannot read '%s': %s", where, path,
216 Strerror(errno));
217 2 out = newSVsv(body);
218 2 pc_chomp(aTHX_ out);
219 2 return out;
220 }
221 8 ▶ if (klen == 5 && memEQ(k, "$exec", 5)) {
Branch: 2 branches
BranchTrueFalseTotal
if (klen == 5 && memEQ(k, "$exec", 5)) { 2 6 8
if (klen == 5 && memEQ(k, "$exec", 5)) { 1 1 2
222 /* list form runs without a shell; a bare string is one command,
223 * which perl hands to the shell when it holds a metacharacter */
224 1 ▶ AV *av = (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
AV *av = (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) 1 0 1
225 2 ▶ ? (AV *)SvRV(arg) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(arg) : NULL; 1 0 1
226 SV *out;
227 1 dSP; int count;
228 1 ENTER; SAVETMPS;
229 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
230 /*
231 # uncoverable branch false
232 # uncoverable condition right count:1 class:ignore_covered_err */
233 1 ▶ if (av) {
Branch: 1 branch
BranchTrueFalseTotal
if (av) { 1 0 1
234 1 SSize_t i, n = av_len(av) + 1;
235 /*
236 # uncoverable branch true
237 # uncoverable condition left count:1 class:ignore_covered_err */
238 1 ▶ if (!n) croak("Punk::Config: %s has an empty $exec", where);
Branch: 1 branch
BranchTrueFalseTotal
if (!n) croak("Punk::Config: %s has an empty $exec", where); 0 1 1
239 1 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 1 0 1
EXTEND(SP, n); 0 1 1
240 3 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 2 1 3
241 2 SV **e = av_fetch(av, i, 0);
242 /*
243 # uncoverable condition right count:1 class:ignore_covered_err
244 # uncoverable condition right count:2 class:ignore_covered_err */
245 2 ▶ PUSHs(e && *e ? *e : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
PUSHs(e && *e ? *e : &PL_sv_undef); 2 0 2
PUSHs(e && *e ? *e : &PL_sv_undef); 2 0 2
246 }
247 }
248 0 ▶ else XPUSHs(arg); /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
else XPUSHs(arg); /* # uncoverable statement */ 0 0 0
249 1 PUTBACK;
250 1 count = call_pv("Punk::Config::_exec", G_SCALAR | G_EVAL);
251 1 SPAGAIN;
252 /*
253 # uncoverable branch true class:ignore_covered_err
254 # uncoverable condition right count:1 class:ignore_covered_err
255 # uncoverable condition left count:2 class:ignore_covered_err */
256 1 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1 0 1
if (SvTRUE(ERRSV)) { 0 1 1
257 0 ▶ SV *e = newSVsv(ERRSV); /* # uncoverable statement class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SV *e = newSVsv(ERRSV); /* # uncoverable statement class:ignore_covered_err */ 0 0 0
258 0 ▶ PUTBACK; FREETMPS; LEAVE; /* # uncoverable statement class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; /* # uncoverable statement class:ignore_covered_err */ 0 0 0
259 0 croak("Punk::Config: %s - %s", where, /* # uncoverable statement class:ignore_covered_err */
260 SvPV_nolen(sv_2mortal(e))); /* # uncoverable statement class:ignore_covered_err */
261 }
262 1 ▶ out = count > 0 ? newSVsv(POPs) : newSVpvs(""); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
out = count > 0 ? newSVsv(POPs) : newSVpvs(""); /* # uncoverable condition right count:1 class:ignore_covered_err */ 1 0 1
263 1 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 1 0 1
264 1 pc_chomp(aTHX_ out);
265 1 return out;
266 }
267 7 ▶ if (klen == 8 && memEQ(k, "$literal", 8)) /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (klen == 8 && memEQ(k, "$literal", 8)) /* # uncoverable condition right count:2 class:ignore_covered_err */ 6 1 7
if (klen == 8 && memEQ(k, "$literal", 8)) /* # uncoverable condition right count:2 class:ignore_covered_err */ 6 0 6
268 6 return newSVsv(arg); /* deliberate plaintext, spelled out */
269  
270 1 croak("Punk::Config: %s uses an unknown resolver '%s' "
271 "(known: $env, $exec, $file, $literal)", where, k);
272 return NULL; /* not reached */
273 }
274  
275 /* ---- the walk ------------------------------------------------------------
276 * One pass: resolve references into `resolved` and `secrets`, and build the
277 * public copy with each secret replaced by [redacted]. Returns the public
278 * node (owned); *resolved_out gets the resolved node (owned). */
279 380 static SV *pc_walk(pTHX_ punk_config *cfg, SV *node, SV *path,
280 SV **resolved_out, int depth) {
281 380 SV *arg = NULL;
282 SV *key;
283 380 ▶ if (depth > PC_MAX_DEPTH)
Branch: 1 branch
BranchTrueFalseTotal
if (depth > PC_MAX_DEPTH) 1 379 380
284 1 croak("Punk::Config: nested deeper than %d levels (an alias "
285 "cycle?)", PC_MAX_DEPTH);
286 379 key = pc_reference(aTHX_ node, &arg);
287  
288 379 ▶ if (key) {
Branch: 1 branch
BranchTrueFalseTotal
if (key) { 20 359 379
289 40 ▶ const char *where_path = SvCUR(path) ? SvPV_nolen(path) : "(root)"; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
const char *where_path = SvCUR(path) ? SvPV_nolen(path) : "(root)"; /* # uncoverable condition right count:1 class:ignore_covered_err */ 20 0 20
290 20 SV *where = sv_2mortal(newSVpvf("'%s'", where_path));
291 20 SV *value = pc_resolve(aTHX_ key, arg, SvPV_nolen(where));
292 13 (void)hv_store_ent(cfg->secrets, path, newSVsv(value), 0);
293 13 *resolved_out = value; /* the real thing */
294 13 return newSVpvs("[redacted]"); /* what the public copy sees */
295 }
296  
297 359 ▶ if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 3 branches
BranchTrueFalseTotal
if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 359 0 359
if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 244 115 359
if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 233 11 244
298 233 HV *src = (HV *)SvRV(node);
299 233 HV *pub = newHV(), *res = newHV();
300 HE *he;
301 233 hv_iterinit(src);
302 466 ▶ while ((he = hv_iternext(src))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(src))) { 306 160 466
303 306 ▶ SV *k = HeSVKEY_force(he);
Branch: 2 branches
BranchTrueFalseTotal
SV *k = HeSVKEY_force(he); 306 0 306
SV *k = HeSVKEY_force(he); 0 306 306
304 STRLEN klen;
305 306 const char *kp = SvPV_const(k, klen);
306 612 SV *child = SvCUR(path)
307 202 ? sv_2mortal(newSVpvf("%s.%s", SvPV_nolen(path), kp))
308 306 ▶ : sv_2mortal(newSVsv(k));
Branch: 1 branch
BranchTrueFalseTotal
: sv_2mortal(newSVsv(k)); 202 104 306
309 306 SV *rnode = NULL;
310 SV *pnode;
311 306 pnode = pc_walk(aTHX_ cfg, HeVAL(he), child, &rnode, depth + 1);
312 233 (void)hv_store_ent(pub, k, pnode, 0);
313 233 ▶ (void)hv_store_ent(res, k, rnode ? rnode : newSVsv(HeVAL(he)), 0); /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_store_ent(res, k, rnode ? rnode : newSVsv(HeVAL(he)), 0); /* # uncoverable condition left count:1 class:ignore_covered_err */ 0 233 233
314 }
315 160 *resolved_out = newRV_noinc((SV *)res);
316 160 return newRV_noinc((SV *)pub);
317 }
318  
319 126 ▶ if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVAV) { /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 3 branches
BranchTrueFalseTotal
if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVAV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 126 0 126
if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVAV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 11 115 126
if (node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVAV) { /* # uncoverable condition right count:1 class:ignore_covered_err */ 5 6 11
320 5 AV *src = (AV *)SvRV(node);
321 5 AV *pub = newAV(), *res = newAV();
322 5 SSize_t i, n = av_len(src) + 1;
323 14 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 9 5 14
324 9 SV **e = av_fetch(src, i, 0);
325 9 SV *child = sv_2mortal(newSVpvf("%s[%" IVdf "]",
326 SvPV_nolen(path), (IV)i));
327 9 SV *rnode = NULL;
328 9 ▶ SV *pnode = pc_walk(aTHX_ cfg, e ? *e : &PL_sv_undef, child, /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SV *pnode = pc_walk(aTHX_ cfg, e ? *e : &PL_sv_undef, child, /* # uncoverable condition right count:1 class:ignore_covered_err */ 9 0 9
329 &rnode, depth + 1);
330 9 av_push(pub, pnode);
331 /*
332 # uncoverable condition left count:1 class:ignore_covered_err
333 # uncoverable condition left count:2 class:ignore_covered_err
334 # uncoverable condition right count:2 class:ignore_covered_err */
335 9 ▶ av_push(res, rnode ? rnode : newSVsv(e ? *e : &PL_sv_undef));
Branch: 2 branches
BranchTrueFalseTotal
av_push(res, rnode ? rnode : newSVsv(e ? *e : &PL_sv_undef)); 0 9 9
av_push(res, rnode ? rnode : newSVsv(e ? *e : &PL_sv_undef)); 0 0 0
336 }
337 5 *resolved_out = newRV_noinc((SV *)res);
338 5 return newRV_noinc((SV *)pub);
339 }
340  
341 121 *resolved_out = newSVsv(node);
342 121 return newSVsv(node);
343 }
344  
345 /* ---- dotted-path lookup --------------------------------------------------- */
346  
347 11 static SV *pc_at_path(pTHX_ SV *root, const char *path, STRLEN plen) {
348 11 SV *node = root;
349 11 STRLEN start = 0, i;
350 134 ▶ for (i = 0; i <= plen; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= plen; i++) { 125 9 134
351 125 ▶ if (i == plen || path[i] == '.') {
Branch: 2 branches
BranchTrueFalseTotal
if (i == plen || path[i] == '.') { 115 10 125
if (i == plen || path[i] == '.') { 10 105 115
352 /*
353 # uncoverable condition left count:1 class:ignore_covered_err
354 # uncoverable condition left count:3 class:ignore_covered_err */
355 20 ▶ if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV)) 20 0 20
if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV)) 19 1 20
if (!(node && SvROK(node) && SvTYPE(SvRV(node)) == SVt_PVHV)) 0 19 19
356 1 return NULL;
357 {
358 19 HE *he = hv_fetch_ent((HV *)SvRV(node),
359 sv_2mortal(newSVpvn(path + start, i - start)), 0, 0);
360 19 ▶ if (!he) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!he) return NULL; 1 18 19
361 18 node = HeVAL(he);
362 }
363 18 start = i + 1;
364 }
365 }
366 9 return node;
367 }
368  
369 58 static void pc_free(pTHX_ punk_config *cfg) {
370 /*
371 # uncoverable branch true
372 # uncoverable condition left count:1 class:ignore_covered_err */
373 58 ▶ if (!cfg) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!cfg) return; 0 58 58
374 58 ▶ if (cfg->public) SvREFCNT_dec((SV *)cfg->public);
Branch: 1 branch
BranchTrueFalseTotal
if (cfg->public) SvREFCNT_dec((SV *)cfg->public); 57 1 58
375 58 ▶ if (cfg->resolved) SvREFCNT_dec((SV *)cfg->resolved);
Branch: 1 branch
BranchTrueFalseTotal
if (cfg->resolved) SvREFCNT_dec((SV *)cfg->resolved); 57 1 58
376 /*
377 # uncoverable branch false
378 # uncoverable condition right count:1 class:ignore_covered_err */
379 58 ▶ if (cfg->secrets) SvREFCNT_dec((SV *)cfg->secrets);
Branch: 1 branch
BranchTrueFalseTotal
if (cfg->secrets) SvREFCNT_dec((SV *)cfg->secrets); 58 0 58
380 /*
381 # uncoverable branch false
382 # uncoverable condition right count:1 class:ignore_covered_err */
383 58 ▶ if (cfg->files) SvREFCNT_dec((SV *)cfg->files);
Branch: 1 branch
BranchTrueFalseTotal
if (cfg->files) SvREFCNT_dec((SV *)cfg->files); 58 0 58
384 /*
385 # uncoverable branch false
386 # uncoverable condition right count:1 class:ignore_covered_err */
387 58 ▶ if (cfg->file) SvREFCNT_dec(cfg->file);
Branch: 1 branch
BranchTrueFalseTotal
if (cfg->file) SvREFCNT_dec(cfg->file); 58 0 58
388 /*
389 # uncoverable branch false
390 # uncoverable condition right count:1 class:ignore_covered_err */
391 58 ▶ if (cfg->env) SvREFCNT_dec(cfg->env);
Branch: 1 branch
BranchTrueFalseTotal
if (cfg->env) SvREFCNT_dec(cfg->env); 58 0 58
392 58 Safefree(cfg);
393 }
394  
395 #endif /* PUNK_CONFIG_H */
« include/punk/punk_views.h ↑ Summary include/punk/punk_cachefile.h »