dds_api.c

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