dds_api.c

filter: Statementstmt 87.5% 367 / 419 Branchbran 77.9% 248 / 318 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 83.4% 615 / 737 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Streamer.xs ↑ Summary dds_emit.c »
1 #define NEED_utf8_to_uvchr_buf
2 #include "dds_engine.h"
3  
4 /* The public facade remains a blessed hash for API compatibility. All
5 * configuration and ordinary entry points are native XSUBs. */
6 /* Create a blessed facade hash with default style values and empty per-class
7 * policies.
8 */
9 1188 SV *dds_new_object(pTHX_ SV *class_name)
10 {
11 1188 HV *object = newHV(), *style = newHV();
12 1188 AV *opts = newAV();
13 1188 SV *self = DDS_TEMP(newRV_noinc((SV *)object));
14  
15 1188 hv_stores(object, "style", newRV_noinc((SV *)style));
16  
17 /* Keep the facade's defaults in the same form as option setters. */
18 #define STR(key, value) hv_stores(style, key, newSVpv(value, 0))
19 #define NUM(key, value) hv_stores(style, key, newSViv(value))
20 1188 STR("hashsep", "=>");
21 1188 STR("arysep", ",");
22 1188 STR("pairsep", ",");
23 1188 STR("optspace", " ");
24 1188 STR("bless", "bless()");
25 1188 STR("freezer", "DDS_freeze");
26 1188 STR("eclipsename", "%s_eclipse_%d");
27 1188 STR("codestub", "sub { Carp::confess \"Dumped code stub!\" }");
28 1188 STR("formatstub", "do{ local *F; eval \"format F =\\nFormat Stub\\n.\\n\"; *F{FORMAT} }");
29  
30 1188 NUM("compress", 0);
31 1188 NUM("indent", 2);
32 1188 NUM("indentcols", 2);
33 1188 NUM("indentkeys", 1);
34 1188 NUM("declare", 0);
35 1188 NUM("verbose", 1);
36 1188 NUM("dumpglob", 1);
37 1188 NUM("deparseglob", 1);
38 1188 NUM("deparse", 1);
39 1188 NUM("rle", 1);
40 1188 NUM("ro", 1);
41 1188 NUM("dualvars", 1);
42 1188 NUM("purity", 1);
43 1188 NUM("terse", 0);
44 1188 NUM("special", 0);
45 #undef STR
46 #undef NUM
47  
48 1188 hv_stores(style, "compressor",
49 newRV_inc((SV *)get_cv("Data::Dump::Streamer::_compressor", GV_ADD)));
50 1188 hv_stores(style, "sortkeys", newRV_noinc((SV *)newHV()));
51 1188 hv_stores(style, "freeze_class", newRV_noinc((SV *)newHV()));
52 1188 hv_stores(style, "ignore", newRV_noinc((SV *)newHV()));
53 1188 av_push(opts, newSVpvs("-sCi2v'Useless const omitted'"));
54 1188 hv_stores(style, "deparseopts", newRV_noinc((SV *)opts));
55  
56 1188 hv_stores(object, "cataloged", newSViv(0));
57 1188 sv_bless(self, gv_stashsv(class_name, GV_ADD));
58  
59 1188 return self;
60 }
61  
62 /* Return an object invocant or call the class's constructor, respecting
63 * inherited and overridden constructors.
64 */
65 3488 SV *dds_safe_self(pTHX_ SV *self)
66 {
67 3488 ▶ if (SvROK(self))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(self)) 3486 2 3488
68 3486 return self;
69  
70 /* Respect an inherited or overridden constructor on class calls. */
71 2 return dds_invoke(aTHX_ NULL, DDS_TEMP(newSVpvs("new")), TRUE, G_SCALAR, 1, &self);
72 }
73  
74 /* Return an idle dumper unchanged, or clone its facade and retained roots so
75 * reentrant callbacks have independent traversal state.
76 */
77 1941 SV *dds_working_self(pTHX_ SV *self)
78 {
79 1941 dds_ctx *ctx = dds_context(aTHX_ self), *working;
80 HV *copy;
81 SV *result;
82 HE *he;
83 UV i;
84  
85 1941 ▶ if (!ctx->busy)
Branch: 1 branch
BranchTrueFalseTotal
if (!ctx->busy) 1924 17 1941
86 1924 return self;
87  
88 /* A callback may reuse this dumper. Give it independent traversal
89 * state while preserving the facade and captured root values. */
90 17 copy = newHV();
91 17 result = DDS_TEMP(sv_bless(newRV_noinc((SV *)copy), SvSTASH((SV *)ctx->object)));
92 17 hv_iterinit(ctx->object);
93 144 ▶ while ((he = hv_iternext(ctx->object)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(ctx->object))) 127 17 144
94 127 hv_store_ent(copy, hv_iterkeysv(he), newSVsv(HeVAL(he)), 0);
95  
96 17 working = dds_context(aTHX_ result);
97 17 ▶ if (ctx->root_count) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->root_count) { 17 0 17
98 17 ▶ Newxz(working->roots, ctx->root_count, dds_root);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(working->roots, ctx->root_count, dds_root); 0 17 17
99 17 working->root_count = working->root_capacity = ctx->root_count;
100 34 ▶ for (i = 0; i < ctx->root_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ctx->root_count; i++) { 17 17 34
101 17 working->roots[i].sv = SvREFCNT_inc(ctx->roots[i].sv);
102 17 working->roots[i].count = ctx->roots[i].count;
103 17 working->roots[i].readonly = ctx->roots[i].readonly;
104 17 working->roots[i].lexical = ctx->roots[i].lexical;
105 }
106 }
107  
108 17 hv_delete(copy, "lexicals", 8, G_DISCARD);
109 17 return result;
110 }
111  
112 /* Invalidate public catalogue status and clear freezer-policy caches before
113 * analyzing new input.
114 */
115 2591 static void dds_reset_facade(pTHX_ dds_ctx *ctx)
116 {
117 2591 hv_delete(ctx->object, "cache_freeze_class", 18, G_DISCARD);
118 2591 hv_delete(ctx->object, "cache_skip_freeze", 17, G_DISCARD);
119 2591 hv_stores(ctx->object, "cataloged", newSViv(0));
120 2591 }
121  
122 /*
123 * Guarded operations
124 *
125 * Capture and analysis share an operation guard with output. Entry points
126 * adapt that result to Perl calling context.
127 */
128  
129 /* Run capture, analysis or emission inside an exception-safe operation,
130 * returning the dumper, text or chunk array appropriate to the call.
131 */
132 1948 static SV *dds_run(pTHX_ SV *self, I32 argc, SV **args, I32 gimme, bool analyze_only)
133 {
134 1948 dds_ctx *ctx = dds_context(aTHX_ self);
135  
136 void *operation;
137 1948 SV *result = DDS_TEMP(newSV(0));
138  
139 1948 ENTER;
140 1948 operation = dds_operation_begin(aTHX_ ctx, self);
141 1948 ▶ if (analyze_only || argc || !ctx->cataloged)
Branch: 3 branches
BranchTrueFalseTotal
if (analyze_only || argc || !ctx->cataloged) 1513 435 1948
if (analyze_only || argc || !ctx->cataloged) 1504 9 1513
if (analyze_only || argc || !ctx->cataloged) 1072 432 1504
142 1516 dds_reset_facade(aTHX_ ctx);
143 1948 ▶ if (argc)
Branch: 1 branch
BranchTrueFalseTotal
if (argc) 443 1505 1948
144 443 dds_capture(aTHX_ ctx, argc, args);
145  
146 1948 ▶ if (analyze_only) {
Branch: 1 branch
BranchTrueFalseTotal
if (analyze_only) { 435 1513 1948
147 435 dds_analyze(aTHX_ ctx);
148 433 sv_setsv(result, self);
149 } else {
150 static const char *globals[] = {"\\", "\"", ","};
151 UV i;
152  
153 /* Output must not inherit the caller's record or field separators. */
154 6052 ▶ for (i = 0; i < 3; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 3; i++) { 4539 1513 6052
155 4539 GV *gv = gv_fetchpv(globals[i], GV_ADD, SVt_PV);
156 4539 SV *local = save_scalar(gv);
157  
158 4539 sv_setpvs(local, "");
159 4539 ▶ SvSETMAGIC(local);
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(local); 1513 3026 4539
160 }
161  
162 1513 dds_output(aTHX_ ctx, gimme);
163  
164 1509 ▶ if (ctx->printer || gimme == G_VOID)
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->printer || gimme == G_VOID) 1505 4 1509
if (ctx->printer || gimme == G_VOID) 4 1501 1505
165 8 sv_setsv(result, self);
166 1501 ▶ else if (gimme == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
else if (gimme == G_ARRAY) 11 1490 1501
167 11 sv_setsv(result, DDS_TEMP(newRV_inc((SV *)ctx->chunks)));
168 else
169 1490 sv_setsv(result, ctx->out);
170 }
171  
172 1942 dds_operation_commit(operation);
173 1942 LEAVE;
174  
175 1942 return result;
176 }
177  
178 /* Replace captured roots under the operation guard, invalidating cached
179 * analysis without producing output.
180 */
181 1075 static void dds_capture_api(pTHX_ SV *self, I32 count, SV **args)
182 {
183 1075 dds_ctx *ctx = dds_context(aTHX_ self);
184  
185 void *operation;
186  
187 1075 ENTER;
188 1075 operation = dds_operation_begin(aTHX_ ctx, self);
189 1075 dds_reset_facade(aTHX_ ctx);
190 1075 dds_capture(aTHX_ ctx, count, args);
191 1075 dds_operation_commit(operation);
192 1075 LEAVE;
193 1075 }
194  
195 /* Normalize and validate supplied root names, then store an owned name list on
196 * the facade.
197 */
198 831 static void dds_set_names(pTHX_ HV *object, I32 count, SV **args)
199 {
200 831 AV *names = (AV *)DDS_TEMP((SV *)newAV());
201 AV *source;
202 SSize_t i, last;
203  
204 831 ▶ if (count == 1 && SvROK(args[0]) && SvTYPE(SvRV(args[0])) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (count == 1 && SvROK(args[0]) && SvTYPE(SvRV(args[0])) == SVt_PVAV) { 771 60 831
if (count == 1 && SvROK(args[0]) && SvTYPE(SvRV(args[0])) == SVt_PVAV) { 3 768 771
if (count == 1 && SvROK(args[0]) && SvTYPE(SvRV(args[0])) == SVt_PVAV) { 3 0 3
205 3 source = (AV *)DDS_TEMP(SvREFCNT_inc(SvRV(args[0])));
206 } else {
207 /* A magical name can grow the Perl stack or replace another
208 * argument. Retain the input SVs before fetching any values. */
209 828 source = (AV *)DDS_TEMP((SV *)newAV());
210 1729 ▶ for (i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) 901 828 1729
211 901 av_push(source, SvREFCNT_inc(args[i]));
212 }
213  
214 831 last = av_len(source);
215 1746 ▶ for (i = 0; i <= last; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= last; i++) { 916 830 1746
216 916 SV **entry = av_fetch(source, i, 0);
217 SV *value, *name;
218 916 STRLEN len, j = 0;
219 const U8 *p;
220  
221 916 ▶ if (!entry)
Branch: 1 branch
BranchTrueFalseTotal
if (!entry) 4 912 916
222 8 continue;
223  
224 912 value = DDS_TEMP(SvREFCNT_inc(*entry));
225 912 name = DDS_TEMP(newSVsv(value));
226 912 ▶ if (!SvOK(name))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(name)) 4 908 912
227 4 continue;
228  
229 /* Normalize the sigil before checking the identifier itself. */
230 908 p = (const U8 *)SvPV_force(name, len);
231 908 ▶ if (len && strchr("@%&-", p[0]))
Branch: 2 branches
BranchTrueFalseTotal
if (len && strchr("@%&-", p[0])) 908 0 908
if (len && strchr("@%&-", p[0])) 9 899 908
232 9 SvPVX(name)[0] = '*';
233 899 ▶ else if (len && p[0] == '$') {
Branch: 2 branches
BranchTrueFalseTotal
else if (len && p[0] == '$') { 899 0 899
else if (len && p[0] == '$') { 6 893 899
234 6 sv_chop(name, (char *)p + 1);
235 6 p = (U8 *)SvPV(name, len);
236 }
237  
238 908 ▶ if (len && p[0] == '*')
Branch: 2 branches
BranchTrueFalseTotal
if (len && p[0] == '*') 908 0 908
if (len && p[0] == '*') 91 817 908
239 91 j++;
240 908 ▶ if (len && j == len)
Branch: 2 branches
BranchTrueFalseTotal
if (len && j == len) 908 0 908
if (len && j == len) 0 908 908
241 0 croak("Bad name '%s'", DDS_PV(name));
242 5095 ▶ while (j < len) {
Branch: 1 branch
BranchTrueFalseTotal
while (j < len) { 4188 907 5095
243 4188 STRLEN width = 1;
244 4188 UV ch = p[j];
245  
246 4188 ▶ if (SvUTF8(name))
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(name)) 95 4093 4188
247 95 ch = utf8_to_uvchr_buf(p + j, p + len, &width);
248 4188 ▶ if (!isWORDCHAR_uni(ch))
Branch: 4 branches
BranchTrueFalseTotal
if (!isWORDCHAR_uni(ch)) 4184 4 4188
if (!isWORDCHAR_uni(ch)) 4184 0 4184
if (!isWORDCHAR_uni(ch)) 1 4183 4184
if (!isWORDCHAR_uni(ch)) 1 4187 4188
249 1 croak("Bad name '%s'", DDS_PV(name));
250 4187 j += width;
251 }
252  
253 907 av_push(names, newSVsv(name));
254 }
255  
256 830 hv_stores(object, "unames", newRV_inc((SV *)names));
257 830 }
258  
259 /* Match class policies to the byte names used by pre-5.16 stashes without
260 * changing the caller's class-name scalar. Newer stashes retain UTF-8 flags.
261 */
262 322 static SV *dds_policy_class(pTHX_ SV *value)
263 {
264 #if PERL_VERSION < 16
265 SV *name = DDS_TEMP(newSVsv(value));
266  
267 SvUTF8_off(name);
268 return name;
269 #else
270 322 return value;
271 #endif
272 }
273  
274 /* Build a mortal policy key: an address key for a reference, or a Unicode-
275 * preserving class/default key for a string.
276 */
277 288 static SV *dds_policy_key(pTHX_ SV *value)
278 {
279 SV *key;
280  
281 288 ▶ if (SvROK(value))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(value)) 2 286 288
282 2 return DDS_TEMP(newSVpvf("#%" UVuf, PTR2UV(SvRV(value))));
283  
284 286 key = DDS_TEMP(newSVpvs("."));
285 286 ▶ if (SvOK(value))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(value)) 286 0 286
286 286 sv_catsv(key, dds_policy_class(aTHX_ value));
287 286 return key;
288 }
289  
290 /* Read or update key-order policies, resolving built-in modes and class
291 * methods into values the native sorter can use.
292 */
293 279 static SV *dds_key_order(pTHX_ SV *self, I32 count, SV **args)
294 {
295 279 HV *style = dds_hash(aTHX_ dds_context(aTHX_ self)->object, "style", TRUE);
296 279 HV *sorters = dds_hash(aTHX_ style, "sortkeys", TRUE);
297 279 HV *strings = dds_hash(aTHX_ style, "sortkeys_string", TRUE);
298 I32 i;
299  
300 279 ▶ if (count > 2 && count % 2)
Branch: 2 branches
BranchTrueFalseTotal
if (count > 2 && count % 2) 1 278 279
if (count > 2 && count % 2) 0 1 1
301 0 croak("KeyOrder() must have an even number of arguments");
302  
303 557 ▶ for (i = 0; i < count; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i += 2) { 279 278 557
304 279 SV *key = dds_policy_key(aTHX_ args[i]);
305 SV *value;
306  
307 279 ▶ if (i + 1 == count) {
Branch: 1 branch
BranchTrueFalseTotal
if (i + 1 == count) { 1 278 279
308 1 HE *entry = hv_fetch_ent(strings, key, 0, 0);
309  
310 1 ▶ if (entry && SvTRUE(HeVAL(entry)))
Branch: 2 branches
BranchTrueFalseTotal
if (entry && SvTRUE(HeVAL(entry))) 1 0 1
if (entry && SvTRUE(HeVAL(entry))) 1 0 1
311 1 return HeVAL(entry);
312 0 entry = hv_fetch_ent(sorters, key, 0, 0);
313 0 ▶ return entry ? HeVAL(entry) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
return entry ? HeVAL(entry) : &PL_sv_undef; 0 0 0
314 }
315  
316 278 value = args[i + 1];
317 278 hv_delete_ent(strings, key, G_DISCARD, 0);
318 278 ▶ if (!SvOK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(value)) { 0 278 278
319 0 hv_delete_ent(sorters, key, G_DISCARD, 0);
320 0 continue;
321 }
322  
323 278 ▶ if (!SvROK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(value)) { 265 13 278
324 265 const char *builtin = dds_builtin_order(aTHX_ value);
325  
326 265 ▶ if (builtin) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin) { 264 1 265
327 264 hv_store_ent(strings, key, newSVsv(value), 0);
328 264 value = DDS_TEMP(newSVpv(builtin, 0));
329 } else {
330 HV *stash;
331 GV *method;
332  
333 1 ▶ if (SvROK(args[i]) || !SvTRUE(args[i]))
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(args[i]) || !SvTRUE(args[i])) 1 0 1
if (SvROK(args[i]) || !SvTRUE(args[i])) 0 1 1
334 0 croak("Unblessed or per object Sortkeys() must be coderefs:'%s'",
335 DDS_PV(value));
336 1 stash = gv_stashsv(args[i], 0);
337 2 ▶ method = stash ? gv_fetchmethod_autoload(stash, DDS_PV(value), 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
method = stash ? gv_fetchmethod_autoload(stash, DDS_PV(value), 0) : NULL; 1 0 1
338 1 ▶ if (!method || !GvCV(method))
Branch: 2 branches
BranchTrueFalseTotal
if (!method || !GvCV(method)) 1 0 1
if (!method || !GvCV(method)) 0 1 1
339 0 croak("Unknown sortkeys '%s'", DDS_PV(value));
340 1 hv_store_ent(strings, key, newSVsv(value), 0);
341 1 value = DDS_TEMP(newRV_inc((SV *)GvCV(method)));
342 }
343 13 ▶ } else if (SvTYPE(SvRV(value)) != SVt_PVAV && SvTYPE(SvRV(value)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
} else if (SvTYPE(SvRV(value)) != SVt_PVAV && SvTYPE(SvRV(value)) != SVt_PVCV) 10 3 13
} else if (SvTYPE(SvRV(value)) != SVt_PVAV && SvTYPE(SvRV(value)) != SVt_PVCV) 0 10 10
344 0 croak("Can't use value as KeyOrder() value");
345 278 hv_store_ent(sorters, key, newSVsv(value), 0);
346 }
347 278 return self;
348 }
349  
350 /* Implement the public constructor, returning a newly initialized dumper for
351 * the requested class.
352 */
353 18 XS_INTERNAL(dds_xs_new)
354 {
355 18 dXSARGS;
356 18 ▶ if (!items)
Branch: 1 branch
BranchTrueFalseTotal
if (!items) 0 18 18
357 0 croak("Usage: Data::Dump::Streamer->new()");
358 18 ST(0) = dds_new_object(aTHX_ ST(0));
359 18 XSRETURN(1);
360 }
361  
362 /* Normalize the invocant and, for the working-self variant, isolate a
363 * reentrant operation before returning it to Perl.
364 */
365 0 XS_INTERNAL(dds_xs_safe_self)
366 {
367 0 dXSARGS;
368 SV *self;
369  
370 0 ▶ if (!items)
Branch: 1 branch
BranchTrueFalseTotal
if (!items) 0 0 0
371 0 croak("Missing dumper invocant");
372 0 self = dds_safe_self(aTHX_ ST(0));
373 0 ▶ if (CvXSUBANY(cv).any_i32)
Branch: 1 branch
BranchTrueFalseTotal
if (CvXSUBANY(cv).any_i32) 0 0 0
374 0 self = dds_working_self(aTHX_ self);
375 0 ST(0) = DDS_TEMP(newSVsv(self));
376 0 XSRETURN(1);
377 }
378  
379 /* Implement Data and Out, forwarding arguments and Perl context and unpacking
380 * list-context output chunks.
381 */
382 1937 XS_INTERNAL(dds_xs_io)
383 {
384 1937 dXSARGS;
385 SV *self, *result;
386 1937 I32 gimme = GIMME_V;
387 1937 bool data = CvXSUBANY(cv).any_i32;
388  
389 1937 ▶ if (!items)
Branch: 1 branch
BranchTrueFalseTotal
if (!items) 0 1937 1937
390 0 croak("Missing dumper invocant");
391 1937 self = DDS_TEMP(newSVsv(dds_working_self(aTHX_ dds_safe_self(aTHX_ ST(0)))));
392 1937 PUTBACK;
393 1937 result = dds_run(aTHX_ self, items - 1, &ST(1), gimme, data);
394 1931 SPAGAIN;
395 1931 ▶ if (!data && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!data && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 1498 433 1931
if (!data && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 2 1496 1498
if (!data && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 2 0 2
if (!data && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 2 0 2
396 2 AV *chunks = (AV *)SvRV(result);
397 2 SSize_t i, count = av_len(chunks) + 1;
398  
399 2 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 2 0 2
EXTEND(SP, count); 0 2 2
400 8 ▶ for (i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) 6 2 8
401 6 ST(i) = DDS_TEMP(newSVsv(*av_fetch(chunks, i, 0)));
402 2 XSRETURN(count);
403 }
404 1929 ST(0) = result;
405 1929 XSRETURN(1);
406 }
407  
408 /* Implement the capture-only entry points, replacing roots and returning the
409 * working dumper for chaining.
410 */
411 0 XS_INTERNAL(dds_xs_capture)
412 {
413 0 dXSARGS;
414 SV *self;
415  
416 0 ▶ if (!items)
Branch: 1 branch
BranchTrueFalseTotal
if (!items) 0 0 0
417 0 croak("Missing dumper invocant");
418 0 self = DDS_TEMP(newSVsv(dds_working_self(aTHX_ dds_safe_self(aTHX_ ST(0)))));
419 0 dds_capture_api(aTHX_ self, items - 1, &ST(1));
420 0 ST(0) = DDS_TEMP(newSVsv(self));
421 0 XSRETURN(1);
422 }
423  
424 typedef enum {
425 DDS_DUMP,
426 DDS_DUMP_TEXT,
427 DDS_DUMP_VARS,
428 DDS_DUMP_LEX
429 } dds_dump_kind;
430  
431 /* Dispatch Dump, Dumper, DumpVars and DumpLex, handling invocants, naming,
432 * scalar capture and context-sensitive output.
433 */
434 1174 XS_INTERNAL(dds_xs_dump)
435 {
436 1174 dXSARGS;
437 1174 I32 first = 0, gimme = GIMME_V;
438 1174 const dds_dump_kind kind = (dds_dump_kind)CvXSUBANY(cv).any_i32;
439 1174 const bool want_text = kind == DDS_DUMP_TEXT;
440 1174 const bool named_pairs = kind == DDS_DUMP_VARS;
441 bool lexical_names, capture_empty, capture;
442 1174 SV *self = NULL, *result;
443 1174 AV *values = NULL, *names = NULL;
444  
445 /* Accept either the exported function form or an existing dumper. */
446 1174 ▶ if (items && SvROK(ST(0)) && sv_derived_from(ST(0), "Data::Dump::Streamer")) {
Branch: 3 branches
BranchTrueFalseTotal
if (items && SvROK(ST(0)) && sv_derived_from(ST(0), "Data::Dump::Streamer")) { 1085 89 1174
if (items && SvROK(ST(0)) && sv_derived_from(ST(0), "Data::Dump::Streamer")) { 534 551 1085
if (items && SvROK(ST(0)) && sv_derived_from(ST(0), "Data::Dump::Streamer")) { 4 530 534
447 4 self = DDS_TEMP(newSVsv(dds_working_self(aTHX_ ST(0))));
448 4 first++;
449 }
450 1174 ▶ if (!self)
Branch: 1 branch
BranchTrueFalseTotal
if (!self) 1170 4 1174
451 1170 self = dds_new_object(aTHX_ DDS_TEMP(newSVpvs("Data::Dump::Streamer")));
452  
453 1174 ▶ lexical_names = kind == DDS_DUMP_LEX && SvTRUE(get_sv("Data::Dump::Streamer::HasPadWalker", 0));
Branch: 2 branches
BranchTrueFalseTotal
lexical_names = kind == DDS_DUMP_LEX && SvTRUE(get_sv("Data::Dump::Streamer::HasPadWalker", 0)); 7 1167 1174
lexical_names = kind == DDS_DUMP_LEX && SvTRUE(get_sv("Data::Dump::Streamer::HasPadWalker", 0)); 5 2 7
454  
455 /* Scalar-context named entry points capture even an empty argument list.
456 * Output calls without arguments reuse existing roots. Without PadWalker,
457 * DumpLex follows ordinary Dump capture rules. */
458 1174 ▶ capture_empty = named_pairs || lexical_names;
Branch: 2 branches
BranchTrueFalseTotal
capture_empty = named_pairs || lexical_names; 1171 3 1174
capture_empty = named_pairs || lexical_names; 5 1166 1171
459  
460 1174 ▶ if (lexical_names) {
Branch: 1 branch
BranchTrueFalseTotal
if (lexical_names) { 5 1169 1174
461 SV *lexnames;
462  
463 5 PUTBACK;
464 5 lexnames = dds_invoke(aTHX_ dds_context(aTHX_ self),
465 DDS_TEMP(newSVpvs("Data::Dump::Streamer::_xs_lexical_names")), FALSE,
466 5 G_SCALAR, items - first, &ST(first));
467 5 SPAGAIN;
468 5 ▶ if (SvROK(lexnames) && SvTYPE(SvRV(lexnames)) == SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(lexnames) && SvTYPE(SvRV(lexnames)) == SVt_PVAV) { 5 0 5
if (SvROK(lexnames) && SvTYPE(SvRV(lexnames)) == SVt_PVAV) { 5 0 5
469 5 AV *source = (AV *)SvRV(lexnames);
470  
471 5 dds_set_names(aTHX_ dds_context(aTHX_ self)->object, av_len(source) + 1,
472 AvARRAY(source));
473 }
474 }
475  
476 1174 ▶ if (named_pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (named_pairs) { 3 1171 1174
477 I32 i;
478  
479 3 values = (AV *)DDS_TEMP((SV *)newAV());
480 3 names = (AV *)DDS_TEMP((SV *)newAV());
481 3 ▶ if ((items - first) % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ((items - first) % 2) { 0 3 3
482 0 warn("Odd number of arguments in DumpVars");
483 0 items--;
484 }
485  
486 10 ▶ for (i = first; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = first; i < items; i += 2) { 7 3 10
487 7 av_push(names, newSVsv(ST(i)));
488 7 av_push(values, SvREFCNT_inc(ST(i + 1)));
489 }
490  
491 3 dds_set_names(aTHX_ dds_context(aTHX_ self)->object, av_len(names) + 1, AvARRAY(names));
492 }
493  
494 /* Scalar Dump captures for chaining; Dumper always produces text. */
495 1174 ▶ capture = items > first || capture_empty;
Branch: 2 branches
BranchTrueFalseTotal
capture = items > first || capture_empty; 91 1083 1174
capture = items > first || capture_empty; 1 90 91
496 1174 ▶ if (!want_text && ((gimme == G_SCALAR && capture) || (!items && !capture_empty))) {
Branch: 5 branches
BranchTrueFalseTotal
if (!want_text && ((gimme == G_SCALAR && capture) || (!items && !capture_empty))) { 1173 1 1174
if (!want_text && ((gimme == G_SCALAR && capture) || (!items && !capture_empty))) { 1163 10 1173
if (!want_text && ((gimme == G_SCALAR && capture) || (!items && !capture_empty))) { 88 1075 1163
if (!want_text && ((gimme == G_SCALAR && capture) || (!items && !capture_empty))) { 89 9 98
if (!want_text && ((gimme == G_SCALAR && capture) || (!items && !capture_empty))) { 88 1 89
497 1163 ▶ if (capture)
Branch: 1 branch
BranchTrueFalseTotal
if (capture) 1075 88 1163
498 2147 ▶ dds_capture_api(aTHX_ self, values ? av_len(values) + 1 : items - first,
Branch: 2 branches
BranchTrueFalseTotal
dds_capture_api(aTHX_ self, values ? av_len(values) + 1 : items - first, 3 1072 1075
dds_capture_api(aTHX_ self, values ? av_len(values) + 1 : items - first, 3 1072 1075
499 1072 values ? AvARRAY(values) : &ST(first));
500 1163 ST(0) = DDS_TEMP(newSVsv(self));
501 1163 XSRETURN(1);
502 }
503  
504 11 PUTBACK;
505 22 ▶ result = dds_run(aTHX_ self, values ? av_len(values) + 1 : items - first,
Branch: 3 branches
BranchTrueFalseTotal
result = dds_run(aTHX_ self, values ? av_len(values) + 1 : items - first, 1 10 11
result = dds_run(aTHX_ self, values ? av_len(values) + 1 : items - first, 0 11 11
result = dds_run(aTHX_ self, values ? av_len(values) + 1 : items - first, 0 11 11
506 11 values ? AvARRAY(values) : &ST(first), want_text ? G_SCALAR : gimme, FALSE);
507 11 SPAGAIN;
508  
509 11 ▶ if (!want_text && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!want_text && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 10 1 11
if (!want_text && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 9 1 10
if (!want_text && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 9 0 9
if (!want_text && gimme == G_ARRAY && SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) { 9 0 9
510 9 AV *chunks = (AV *)SvRV(result);
511 9 SSize_t i, count = av_len(chunks) + 1;
512  
513 9 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 9 0 9
EXTEND(SP, count); 0 9 9
514 60 ▶ for (i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) 51 9 60
515 51 ST(i) = DDS_TEMP(newSVsv(*av_fetch(chunks, i, 0)));
516 9 XSRETURN(count);
517 }
518  
519 2 ST(0) = result;
520 2 XSRETURN(1);
521 }
522  
523 #define DDS_OPTION_LIST(X) \
524 X(DECLARE, "declare", "Declare") \
525 X(INDENT_COLS, "indentcols", "IndentCols") \
526 X(INDENT_KEYS, "indentkeys", "IndentKeys") \
527 X(VERBOSE, "verbose", "Verbose") \
528 X(DUMP_GLOB, "dumpglob", "DumpGlob") \
529 X(DEPARSE, "deparse", "Deparse") \
530 X(DEPARSE_GLOB, "deparseglob", "DeparseGlob") \
531 X(DEPARSE_FORMAT, "deparseformat", "DeparseFormat") \
532 X(CODE_STUB, "codestub", "CodeStub") \
533 X(FORMAT_STUB, "formatstub", "FormatStub") \
534 X(RLE, "rle", "Rle") \
535 X(PURITY, "purity", "Purity") \
536 X(DUAL_VARS, "dualvars", "DualVars") \
537 X(ECLIPSE_NAME, "eclipsename", "EclipseName") \
538 X(COMPRESS, "compress", "Compress") \
539 X(COMPRESSOR, "compressor", "Compressor") \
540 X(OPT_SPACE, "optspace", "OptSpace") \
541 X(TERSE, "terse", "Terse") \
542 X(INDENT, "indent", "Indent") \
543 X(TO, "fh", "To") \
544 X(DEPARSE_OPTS, "deparseopts", "DeparseOpts") \
545 X(FREEZER, "freezer", "Freezer") \
546 X(RESET_FREEZER, "resetfreezer", "ResetFreezer") \
547 X(IGNORE, "ignore", "Ignore") \
548 X(KEY_ORDER, "keyorder", "KeyOrder") \
549 X(SORT_KEYS, "sortkeys", "SortKeys") \
550 X(NAMES, "unames", "Names")
551  
552 typedef enum {
553 #define OPTION_ENUM(id, key, name) DDS_OPT_##id,
554 DDS_OPTION_LIST(OPTION_ENUM)
555 #undef OPTION_ENUM
556 DDS_OPT_COUNT
557 } dds_option;
558  
559 static const char *dds_option_keys[] = {
560 #define OPTION_KEY(id, key, name) key,
561 DDS_OPTION_LIST(OPTION_KEY)
562 #undef OPTION_KEY
563 };
564  
565 /*
566 * Option dispatch
567 *
568 * The shared selector table connects accessor names to stored option keys.
569 * Complex options retain their specialized validation and context behavior.
570 */
571  
572 /* Implement option getters and setters, including context-sensitive list
573 * results and options with specialized validation or storage.
574 */
575 1551 XS_INTERNAL(dds_xs_option)
576 {
577 1551 dXSARGS;
578 1551 I32 ix = CvXSUBANY(cv).any_i32;
579 1551 SV *self, *result, *setvalue = NULL;
580 HV *object, *style;
581 1551 const char *key = dds_option_keys[ix];
582  
583 1551 ▶ if (!items)
Branch: 1 branch
BranchTrueFalseTotal
if (!items) 0 1551 1551
584 0 croak("Missing dumper invocant");
585 1551 self = DDS_TEMP(newSVsv(dds_safe_self(aTHX_ ST(0))));
586 1551 ▶ if (items > 1 && ix < DDS_OPT_DEPARSE_OPTS)
Branch: 2 branches
BranchTrueFalseTotal
if (items > 1 && ix < DDS_OPT_DEPARSE_OPTS) 1358 193 1551
if (items > 1 && ix < DDS_OPT_DEPARSE_OPTS) 210 1148 1358
587 210 setvalue = DDS_TEMP(newSVsv(ST(1)));
588 1551 object = dds_context(aTHX_ self)->object;
589 1551 style = dds_hash(aTHX_ object, "style", TRUE);
590 1551 result = self;
591 1551 ▶ if (ix == DDS_OPT_NAMES) { /* Names */
Branch: 1 branch
BranchTrueFalseTotal
if (ix == DDS_OPT_NAMES) { /* Names */ 835 716 1551
592 AV *names;
593  
594 835 ▶ if (items > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) 823 12 835
595 823 dds_set_names(aTHX_ object, items - 1, &ST(1));
596 12 ▶ else if (GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
else if (GIMME_V == G_VOID) 4 8 12
597 4 hv_stores(object, "unames", newRV_noinc((SV *)newAV()));
598 8 ▶ else if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
else if (GIMME_V == G_ARRAY) { 3 5 8
599 SSize_t i, count;
600  
601 3 names = dds_array(aTHX_ object, "unames", FALSE);
602 3 ▶ count = names ? av_len(names) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
count = names ? av_len(names) + 1 : 0; 3 0 3
603 3 SPAGAIN;
604 3 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 3 0 3
EXTEND(SP, count); 0 3 3
605 10 ▶ for (i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) 7 3 10
606 7 ST(i) = DDS_TEMP(newSVsv(*av_fetch(names, i, 0)));
607 3 XSRETURN(count);
608 } else
609 5 result = dds_hget(aTHX_ object, "unames");
610 716 ▶ } else if (ix == DDS_OPT_KEY_ORDER || ix == DDS_OPT_SORT_KEYS) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (ix == DDS_OPT_KEY_ORDER || ix == DDS_OPT_SORT_KEYS) { 709 7 716
} else if (ix == DDS_OPT_KEY_ORDER || ix == DDS_OPT_SORT_KEYS) { 272 437 709
611 279 ▶ if (ix == DDS_OPT_SORT_KEYS) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == DDS_OPT_SORT_KEYS) { 272 7 279
612 272 AV *args = (AV *)DDS_TEMP((SV *)newAV());
613 I32 i;
614  
615 272 av_push(args, newSVpvs(""));
616 543 ▶ for (i = 1; i < items; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i++) 271 272 543
617 271 av_push(args, newSVsv(ST(i)));
618 272 result = dds_key_order(aTHX_ self, av_len(args) + 1, AvARRAY(args));
619 } else
620 7 result = dds_key_order(aTHX_ self, items - 1, &ST(1));
621 437 ▶ } else if (ix == DDS_OPT_IGNORE) { /* Ignore */
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == DDS_OPT_IGNORE) { /* Ignore */ 10 427 437
622 10 HV *ignore = dds_hash(aTHX_ style, "ignore", TRUE);
623 I32 i;
624  
625 10 ▶ if (items == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) { 1 9 10
626 HE *he;
627 1 I32 count = 0;
628  
629 1 hv_iterinit(ignore);
630 1 SPAGAIN;
631 1 ▶ EXTEND(SP, (SSize_t)HvTOTALKEYS(ignore));
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, (SSize_t)HvTOTALKEYS(ignore)); 1 0 1
EXTEND(SP, (SSize_t)HvTOTALKEYS(ignore)); 0 1 1
632 2 ▶ while ((he = hv_iternext(ignore))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(ignore))) { 1 1 2
633 1 SV *name = DDS_TEMP(newSVsv(hv_iterkeysv(he)));
634 STRLEN len;
635 1 char *p = SvPV(name, len);
636  
637 1 ▶ if (len)
Branch: 1 branch
BranchTrueFalseTotal
if (len) 1 0 1
638 1 sv_chop(name, p + 1);
639 1 ST(count++) = name;
640 }
641 1 ▶ if (GIMME_V == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) 1 0 1
642 1 XSRETURN(count);
643 0 ST(0) = DDS_TEMP(newSViv(count));
644 0 XSRETURN(1);
645 }
646 9 ▶ if (items > 2 && !(items % 2))
Branch: 2 branches
BranchTrueFalseTotal
if (items > 2 && !(items % 2)) 7 2 9
if (items > 2 && !(items % 2)) 0 7 7
647 0 croak("Must have an even number of arguments in Ignore()");
648 16 ▶ for (i = 1; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) { 9 7 16
649 9 SV *policy = dds_policy_key(aTHX_ ST(i));
650  
651 9 ▶ if (i + 1 == items) {
Branch: 1 branch
BranchTrueFalseTotal
if (i + 1 == items) { 2 7 9
652 2 HE *entry = hv_fetch_ent(ignore, policy, 0, 0);
653  
654 2 ▶ result = entry ? HeVAL(entry) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
result = entry ? HeVAL(entry) : &PL_sv_undef; 1 1 2
655 2 break;
656 }
657 7 ▶ if (SvTRUE(ST(i + 1)))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(ST(i + 1))) 5 2 7
658 5 hv_store_ent(ignore, policy, newSViv(1), 0);
659 else
660 2 hv_delete_ent(ignore, policy, G_DISCARD, 0);
661 }
662 427 ▶ } else if (ix == DDS_OPT_RESET_FREEZER) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == DDS_OPT_RESET_FREEZER) { 7 420 427
663 7 hv_stores(style, "freezer", newSVpvs("DDS_freeze"));
664 7 hv_stores(style, "freeze_class", newRV_noinc((SV *)newHV()));
665 420 ▶ } else if (ix == DDS_OPT_FREEZER && items == 3) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (ix == DDS_OPT_FREEZER && items == 3) { 38 382 420
} else if (ix == DDS_OPT_FREEZER && items == 3) { 36 2 38
666 36 hv_store_ent(dds_hash(aTHX_ style, "freeze_class", TRUE), dds_policy_class(aTHX_ ST(1)),
667 newSVsv(ST(2)), 0);
668 384 ▶ } else if (ix == DDS_OPT_FREEZER && items == 1 && GIMME_V == G_ARRAY) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (ix == DDS_OPT_FREEZER && items == 1 && GIMME_V == G_ARRAY) { 2 382 384
} else if (ix == DDS_OPT_FREEZER && items == 1 && GIMME_V == G_ARRAY) { 0 2 2
} else if (ix == DDS_OPT_FREEZER && items == 1 && GIMME_V == G_ARRAY) { 0 0 0
669 0 HV *classes = dds_hash(aTHX_ style, "freeze_class", TRUE);
670 HE *he;
671 0 I32 count = 1;
672  
673 0 SPAGAIN;
674 0 ▶ EXTEND(SP, 2 * (SSize_t)HvTOTALKEYS(classes) + 1);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, 2 * (SSize_t)HvTOTALKEYS(classes) + 1); 0 0 0
EXTEND(SP, 2 * (SSize_t)HvTOTALKEYS(classes) + 1); 0 0 0
675 0 ST(0) = DDS_TEMP(newSVsv(dds_hget(aTHX_ style, "freezer")));
676 0 hv_iterinit(classes);
677 0 ▶ while ((he = hv_iternext(classes))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(classes))) { 0 0 0
678 0 ST(count++) = DDS_TEMP(newSVsv(hv_iterkeysv(he)));
679 0 ST(count++) = DDS_TEMP(newSVsv(HeVAL(he)));
680 }
681 0 XSRETURN(count);
682 384 ▶ } else if (ix == DDS_OPT_DEPARSE_OPTS) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == DDS_OPT_DEPARSE_OPTS) { 3 381 384
683 3 ▶ if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 1) { 1 2 3
684 SV *opts;
685  
686 1 ▶ if (SvROK(ST(1)))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(ST(1))) 0 1 1
687 0 opts = newSVsv(ST(1));
688 else {
689 1 AV *array = newAV();
690 I32 i;
691  
692 3 ▶ for (i = 1; i < items; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i++) 2 1 3
693 2 av_push(array, newSVsv(ST(i)));
694 1 opts = newRV_noinc((SV *)array);
695 }
696 1 hv_stores(style, "deparseopts", opts);
697 2 ▶ } else if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (GIMME_V == G_ARRAY) { 1 1 2
698 1 AV *opts = dds_array(aTHX_ style, "deparseopts", FALSE);
699 1 ▶ SSize_t i, count = opts ? av_len(opts) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
SSize_t i, count = opts ? av_len(opts) + 1 : 0; 1 0 1
700  
701 1 SPAGAIN;
702 1 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 1 0 1
EXTEND(SP, count); 0 1 1
703 3 ▶ for (i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) 2 1 3
704 2 ST(i) = DDS_TEMP(newSVsv(*av_fetch(opts, i, 0)));
705 1 XSRETURN(count);
706 } else
707 1 result = dds_hget(aTHX_ style, key);
708 381 ▶ } else if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (items > 1) { 212 169 381
709 212 ▶ HV *target = ix == DDS_OPT_TO ? object : style;
Branch: 1 branch
BranchTrueFalseTotal
HV *target = ix == DDS_OPT_TO ? object : style; 8 204 212
710  
711 212 ▶ if (ix == DDS_OPT_INDENT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == DDS_OPT_INDENT) { 18 194 212
712 18 SV *space = dds_hget(aTHX_ style, "optspace");
713  
714 18 ▶ if (SvIV(setvalue) == 0 && sv_len_utf8(space)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIV(setvalue) == 0 && sv_len_utf8(space)) { 11 7 18
if (SvIV(setvalue) == 0 && sv_len_utf8(space)) { 11 0 11
715 11 hv_stores(style, "last_optspace", newSVsv(space));
716 11 hv_stores(style, "optspace", newSVpvs(""));
717 7 ▶ } else if (!SvTRUE(dds_hget(aTHX_ style, "indent")) && !sv_len_utf8(space))
Branch: 2 branches
BranchTrueFalseTotal
} else if (!SvTRUE(dds_hget(aTHX_ style, "indent")) && !sv_len_utf8(space)) 3 4 7
} else if (!SvTRUE(dds_hget(aTHX_ style, "indent")) && !sv_len_utf8(space)) 3 0 3
718 3 hv_stores(style, "optspace", newSVsv(dds_hget(aTHX_ style, "last_optspace")));
719 }
720 212 ▶ hv_store(target, key, strlen(key), newSVsv(setvalue ? setvalue : ST(1)), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(target, key, strlen(key), newSVsv(setvalue ? setvalue : ST(1)), 0); 2 210 212
721 } else
722 169 ▶ result = dds_hget(aTHX_ ix == DDS_OPT_TO ? object : style, key);
Branch: 1 branch
BranchTrueFalseTotal
result = dds_hget(aTHX_ ix == DDS_OPT_TO ? object : style, key); 0 169 169
723 1545 ST(0) = DDS_TEMP(newSVsv(result));
724 1545 XSRETURN(1);
725 }
726  
727 /* Provide the non-pure output placeholder by returning its first argument, or
728 * undef when none was supplied.
729 */
730 0 XS_INTERNAL(dds_xs_alias_to)
731 {
732 0 dXSARGS;
733 0 ▶ ST(0) = items ? ST(0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = items ? ST(0) : &PL_sv_undef; 0 0 0
734 0 XSRETURN(1);
735 }
736  
737 /* Exclude dumper objects from ithread cloning because their native traversal
738 * state belongs to one interpreter.
739 */
740 0 XS_INTERNAL(dds_xs_clone_skip)
741 {
742 0 dXSARGS;
743 PERL_UNUSED_VAR(items);
744 0 XSRETURN_YES;
745 }
746  
747 /* Register public entry points, option accessors and spelling aliases with
748 * their native dispatch selectors.
749 */
750 46 void dds_api_boot(pTHX)
751 {
752 static const struct {
753 const char *name;
754 dds_option selector;
755 } options[] = {
756 #define OPTION_ENTRY(id, key, name) {name, DDS_OPT_##id},
757 DDS_OPTION_LIST(OPTION_ENTRY)
758 #undef OPTION_ENTRY
759 {"RLE", DDS_OPT_RLE},
760 {"Dualvars", DDS_OPT_DUAL_VARS},
761 {"Keyorder", DDS_OPT_KEY_ORDER},
762 {"HashKeys", DDS_OPT_KEY_ORDER},
763 {"Hashkeys", DDS_OPT_KEY_ORDER},
764 {"Sortkeys", DDS_OPT_SORT_KEYS},
765 };
766 UV i;
767 CV *cv;
768 #define INSTALL(name, function, selector) \
769 STMT_START \
770 { \
771 cv = newXS("Data::Dump::Streamer::" name, function, __FILE__); \
772 CvXSUBANY(cv).any_i32 = selector; \
773 } \
774 STMT_END
775 46 INSTALL("new", dds_xs_new, 0);
776 46 INSTALL("_safe_self", dds_xs_safe_self, 0);
777 46 INSTALL("_xs_working_self", dds_xs_safe_self, 1);
778 46 INSTALL("Data", dds_xs_io, 1);
779 46 INSTALL("Out", dds_xs_io, 0);
780 46 INSTALL("_xs_data", dds_xs_io, 1);
781 46 INSTALL("_xs_out", dds_xs_io, 0);
782 46 INSTALL("_xs_capture", dds_xs_capture, 0);
783 46 INSTALL("_make_args", dds_xs_capture, 0);
784 46 INSTALL("Dump", dds_xs_dump, DDS_DUMP);
785 46 INSTALL("Precise", dds_xs_dump, DDS_DUMP);
786 46 INSTALL("Dumper", dds_xs_dump, DDS_DUMP_TEXT);
787 46 INSTALL("DumpVars", dds_xs_dump, DDS_DUMP_VARS);
788 46 INSTALL("DumpLex", dds_xs_dump, DDS_DUMP_LEX);
789 46 INSTALL("alias_to", dds_xs_alias_to, 0);
790 46 INSTALL("CLONE_SKIP", dds_xs_clone_skip, 0);
791 1564 ▶ for (i = 0; i < sizeof(options) / sizeof(*options); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < sizeof(options) / sizeof(*options); i++) { 1518 46 1564
792 1518 SV *name = DDS_TEMP(newSVpvf("Data::Dump::Streamer::%s", options[i].name));
793  
794 1518 cv = newXS(DDS_PV(name), dds_xs_option, __FILE__);
795 1518 CvXSUBANY(cv).any_i32 = options[i].selector;
796 }
797 #undef INSTALL
798 46 }
« Streamer.xs ↑ Summary dds_emit.c »