1 #define PERL_NO_GET_CONTEXT
7 #include "patchlevel.h"
8 #define PERL_VERSION PATCHLEVEL
13 # define PL_sv_undef sv_undef
16 # define ERRSV GvSV(errgv)
19 # define newSVpvn newSVpv
23 static I32 num_q (char *s, STRLEN slen);
24 static I32 esc_q (char *dest, char *src, STRLEN slen);
25 static I32 esc_q_utf8 (pTHX_ SV *sv, char *src, STRLEN slen);
26 static SV *sv_x (pTHX_ SV *sv, char *str, STRLEN len, I32 n);
27 static I32 DD_dump (pTHX_ SV *val, char *name, STRLEN namelen, SV *retval,
28 HV *seenhv, AV *postav, I32 *levelp, I32 indent,
29 SV *pad, SV *xpad, SV *apad, SV *sep,
30 SV *freezer, SV *toaster,
31 I32 purity, I32 deepcopy, I32 quotekeys, SV *bless,
32 I32 maxdepth, SV *sortkeys);
34 /* does a string need to be protected? */
36 needs_quote(register char *s)
61 /* count the number of "'"s and "\"s in string */
63 num_q(register char *s, register STRLEN slen)
68 if (*s == '\'' || *s == '\\')
77 /* returns number of chars added to escape "'"s and "\"s in s */
78 /* slen number of characters in s will be escaped */
79 /* destination must be long enough for additional chars */
81 esc_q(register char *d, register char *s, register STRLEN slen)
101 esc_q_utf8(pTHX_ SV* sv, register char *src, register STRLEN slen)
103 char *s, *send, *r, *rstart;
104 STRLEN j, cur = SvCUR(sv);
105 /* Could count 128-255 and 256+ in two variables, if we want to
106 be like &qquote and make a distinction. */
107 STRLEN grow = 0; /* bytes needed to represent chars 128+ */
108 /* STRLEN topbit_grow = 0; bytes needed to represent chars 128-255 */
109 STRLEN backslashes = 0;
110 STRLEN single_quotes = 0;
111 STRLEN qq_escapables = 0; /* " $ @ will need a \ in "" strings. */
114 /* this will need EBCDICification */
115 for (s = src, send = src + slen; s < send; s += UTF8SKIP(s)) {
116 UV k = utf8_to_uvchr((U8*)s, NULL);
119 /* 4: \x{} then count the number of hex digits. */
120 grow += 4 + (k <= 0xFF ? 2 : k <= 0xFFF ? 3 : k <= 0xFFFF ? 4 :
122 8 /* We may allocate a bit more than the minimum here. */
124 k <= 0xFFFFFFFF ? 8 : UVSIZE * 4
127 } else if (k == '\\') {
129 } else if (k == '\'') {
131 } else if (k == '"' || k == '$' || k == '@') {
138 /* We have something needing hex. 3 is ""\0 */
139 sv_grow(sv, cur+3+grow+2*qq_escapables+2*backslashes+normal);
140 rstart = r = SvPVX(sv) + cur;
144 for (s = src; s < send; s += UTF8SKIP(s)) {
145 UV k = utf8_to_uvchr((U8*)s, NULL);
147 if (k == '"' || k == '\\' || k == '$' || k == '@') {
154 r += sprintf(r, "\\x{%"UVxf"}", k);
160 sv_grow(sv, cur+3+grow+2*single_quotes+2*backslashes+normal);
161 rstart = r = SvPVX(sv) + cur;
163 for (s = src; s < send; s ++) {
165 if (k == '\'' || k == '\\')
173 SvCUR_set(sv, cur + j);
178 /* append a repeated string to an SV */
180 sv_x(pTHX_ SV *sv, register char *str, STRLEN len, I32 n)
183 sv = newSVpvn("", 0);
185 assert(SvTYPE(sv) >= SVt_PV);
188 SvGROW(sv, len*n + SvCUR(sv) + 1);
190 char *start = SvPVX(sv) + SvCUR(sv);
198 sv_catpvn(sv, str, len);
206 * This ought to be split into smaller functions. (it is one long function since
207 * it exactly parallels the perl version, which was one long thing for
208 * efficiency raisins.) Ugggh!
211 DD_dump(pTHX_ SV *val, char *name, STRLEN namelen, SV *retval, HV *seenhv,
212 AV *postav, I32 *levelp, I32 indent, SV *pad, SV *xpad,
213 SV *apad, SV *sep, SV *freezer, SV *toaster, I32 purity,
214 I32 deepcopy, I32 quotekeys, SV *bless, I32 maxdepth, SV *sortkeys)
218 char *c, *r, *realpack, id[128];
220 SV *sv, *ipad, *ival;
221 SV *blesspad = Nullsv;
222 AV *seenentry = Nullav;
224 STRLEN inamelen, idlen = 0;
230 realtype = SvTYPE(val);
236 if (SvOBJECT(SvRV(val)) && freezer &&
237 SvPOK(freezer) && SvCUR(freezer))
239 dSP; ENTER; SAVETMPS; PUSHMARK(sp);
240 XPUSHs(val); PUTBACK;
241 i = perl_call_method(SvPVX(freezer), G_EVAL|G_SCALAR);
244 warn("WARNING(Freezer method call failed): %s",
248 PUTBACK; FREETMPS; LEAVE;
250 (void)sv_2mortal(val);
254 realtype = SvTYPE(ival);
255 (void) sprintf(id, "0x%lx", (unsigned long)ival);
258 realpack = HvNAME(SvSTASH(ival));
262 /* if it has a name, we need to either look it up, or keep a tab
263 * on it so we know when we hit it later
266 if ((svp = hv_fetch(seenhv, id, idlen, FALSE))
267 && (sv = *svp) && SvROK(sv) && (seenentry = (AV*)SvRV(sv)))
270 if ((svp = av_fetch(seenentry, 0, FALSE))
271 && (othername = *svp))
273 if (purity && *levelp > 0) {
276 if (realtype == SVt_PVHV)
277 sv_catpvn(retval, "{}", 2);
278 else if (realtype == SVt_PVAV)
279 sv_catpvn(retval, "[]", 2);
281 sv_catpvn(retval, "do{my $o}", 9);
282 postentry = newSVpvn(name, namelen);
283 sv_catpvn(postentry, " = ", 3);
284 sv_catsv(postentry, othername);
285 av_push(postav, postentry);
288 if (name[0] == '@' || name[0] == '%') {
289 if ((SvPVX(othername))[0] == '\\' &&
290 (SvPVX(othername))[1] == name[0]) {
291 sv_catpvn(retval, SvPVX(othername)+1,
295 sv_catpvn(retval, name, 1);
296 sv_catpvn(retval, "{", 1);
297 sv_catsv(retval, othername);
298 sv_catpvn(retval, "}", 1);
302 sv_catsv(retval, othername);
307 warn("ref name not found for %s", id);
311 else { /* store our name and continue */
313 if (name[0] == '@' || name[0] == '%') {
314 namesv = newSVpvn("\\", 1);
315 sv_catpvn(namesv, name, namelen);
317 else if (realtype == SVt_PVCV && name[0] == '*') {
318 namesv = newSVpvn("\\", 2);
319 sv_catpvn(namesv, name, namelen);
320 (SvPVX(namesv))[1] = '&';
323 namesv = newSVpvn(name, namelen);
325 av_push(seenentry, namesv);
326 (void)SvREFCNT_inc(val);
327 av_push(seenentry, val);
328 (void)hv_store(seenhv, id, strlen(id),
329 newRV((SV*)seenentry), 0);
330 SvREFCNT_dec(seenentry);
334 if (realpack && *realpack == 'R' && strEQ(realpack, "Regexp")) {
336 char *rval = SvPV(val, rlen);
337 char *slash = strchr(rval, '/');
338 sv_catpvn(retval, "qr/", 3);
340 sv_catpvn(retval, rval, slash-rval);
341 sv_catpvn(retval, "\\/", 2);
342 rlen -= slash-rval+1;
344 slash = strchr(rval, '/');
346 sv_catpvn(retval, rval, rlen);
347 sv_catpvn(retval, "/", 1);
351 /* If purity is not set and maxdepth is set, then check depth:
352 * if we have reached maximum depth, return the string
353 * representation of the thing we are currently examining
354 * at this depth (i.e., 'Foo=ARRAY(0xdeadbeef)').
356 if (!purity && maxdepth > 0 && *levelp >= maxdepth) {
358 char *valstr = SvPV(val,vallen);
359 sv_catpvn(retval, "'", 1);
360 sv_catpvn(retval, valstr, vallen);
361 sv_catpvn(retval, "'", 1);
365 if (realpack) { /* we have a blessed ref */
367 char *blessstr = SvPV(bless, blesslen);
368 sv_catpvn(retval, blessstr, blesslen);
369 sv_catpvn(retval, "( ", 2);
372 apad = newSVsv(apad);
373 sv_x(aTHX_ apad, " ", 1, blesslen+2);
378 ipad = sv_x(aTHX_ Nullsv, SvPVX(xpad), SvCUR(xpad), *levelp);
380 if (realtype <= SVt_PVBM) { /* scalar ref */
381 SV *namesv = newSVpvn("${", 2);
382 sv_catpvn(namesv, name, namelen);
383 sv_catpvn(namesv, "}", 1);
384 if (realpack) { /* blessed */
385 sv_catpvn(retval, "do{\\(my $o = ", 13);
386 DD_dump(aTHX_ ival, SvPVX(namesv), SvCUR(namesv), retval, seenhv,
387 postav, levelp, indent, pad, xpad, apad, sep,
388 freezer, toaster, purity, deepcopy, quotekeys, bless,
390 sv_catpvn(retval, ")}", 2);
393 sv_catpvn(retval, "\\", 1);
394 DD_dump(aTHX_ ival, SvPVX(namesv), SvCUR(namesv), retval, seenhv,
395 postav, levelp, indent, pad, xpad, apad, sep,
396 freezer, toaster, purity, deepcopy, quotekeys, bless,
399 SvREFCNT_dec(namesv);
401 else if (realtype == SVt_PVGV) { /* glob ref */
402 SV *namesv = newSVpvn("*{", 2);
403 sv_catpvn(namesv, name, namelen);
404 sv_catpvn(namesv, "}", 1);
405 sv_catpvn(retval, "\\", 1);
406 DD_dump(aTHX_ ival, SvPVX(namesv), SvCUR(namesv), retval, seenhv,
407 postav, levelp, indent, pad, xpad, apad, sep,
408 freezer, toaster, purity, deepcopy, quotekeys, bless,
410 SvREFCNT_dec(namesv);
412 else if (realtype == SVt_PVAV) {
415 I32 ixmax = av_len((AV *)ival);
417 SV *ixsv = newSViv(0);
418 /* allowing for a 24 char wide array index */
419 New(0, iname, namelen+28, char);
420 (void)strcpy(iname, name);
422 if (name[0] == '@') {
423 sv_catpvn(retval, "(", 1);
427 sv_catpvn(retval, "[", 1);
428 /* omit "->" in $foo{bar}->[0], but not in ${$foo}->[0] */
430 && name[namelen-1] != ']' && name[namelen-1] != '}'
431 && (namelen < 4 || (name[1] != '{' && name[2] != '{')))*/
433 && name[namelen-1] != ']' && name[namelen-1] != '}')
436 || (name[0] == '\\' && name[2] == '{'))))
438 iname[inamelen++] = '-'; iname[inamelen++] = '>';
439 iname[inamelen] = '\0';
442 if (iname[0] == '*' && iname[inamelen-1] == '}' && inamelen >= 8 &&
443 (instr(iname+inamelen-8, "{SCALAR}") ||
444 instr(iname+inamelen-7, "{ARRAY}") ||
445 instr(iname+inamelen-6, "{HASH}"))) {
446 iname[inamelen++] = '-'; iname[inamelen++] = '>';
448 iname[inamelen++] = '['; iname[inamelen] = '\0';
449 totpad = newSVsv(sep);
450 sv_catsv(totpad, pad);
451 sv_catsv(totpad, apad);
453 for (ix = 0; ix <= ixmax; ++ix) {
456 svp = av_fetch((AV*)ival, ix, FALSE);
464 (void) sprintf(iname+ilen, "%"IVdf, (IV)ix);
465 ilen = strlen(iname);
466 iname[ilen++] = ']'; iname[ilen] = '\0';
468 sv_catsv(retval, totpad);
469 sv_catsv(retval, ipad);
470 sv_catpvn(retval, "#", 1);
471 sv_catsv(retval, ixsv);
473 sv_catsv(retval, totpad);
474 sv_catsv(retval, ipad);
475 DD_dump(aTHX_ elem, iname, ilen, retval, seenhv, postav,
476 levelp, indent, pad, xpad, apad, sep,
477 freezer, toaster, purity, deepcopy, quotekeys, bless,
480 sv_catpvn(retval, ",", 1);
483 SV *opad = sv_x(aTHX_ Nullsv, SvPVX(xpad), SvCUR(xpad), (*levelp)-1);
484 sv_catsv(retval, totpad);
485 sv_catsv(retval, opad);
489 sv_catpvn(retval, ")", 1);
491 sv_catpvn(retval, "]", 1);
493 SvREFCNT_dec(totpad);
496 else if (realtype == SVt_PVHV) {
497 SV *totpad, *newapad;
505 iname = newSVpvn(name, namelen);
506 if (name[0] == '%') {
507 sv_catpvn(retval, "(", 1);
508 (SvPVX(iname))[0] = '$';
511 sv_catpvn(retval, "{", 1);
512 /* omit "->" in $foo[0]->{bar}, but not in ${$foo}->{bar} */
514 && name[namelen-1] != ']' && name[namelen-1] != '}')
517 || (name[0] == '\\' && name[2] == '{'))))
519 sv_catpvn(iname, "->", 2);
522 if (name[0] == '*' && name[namelen-1] == '}' && namelen >= 8 &&
523 (instr(name+namelen-8, "{SCALAR}") ||
524 instr(name+namelen-7, "{ARRAY}") ||
525 instr(name+namelen-6, "{HASH}"))) {
526 sv_catpvn(iname, "->", 2);
528 sv_catpvn(iname, "{", 1);
529 totpad = newSVsv(sep);
530 sv_catsv(totpad, pad);
531 sv_catsv(totpad, apad);
533 /* If requested, get a sorted/filtered array of hash keys */
535 if (sortkeys == &PL_sv_yes) {
537 (void)hv_iterinit((HV*)ival);
538 while ((entry = hv_iternext((HV*)ival))) {
539 sv = hv_iterkeysv(entry);
543 #ifdef USE_LOCALE_NUMERIC
544 sortsv(AvARRAY(keys),
546 IN_LOCALE ? Perl_sv_cmp_locale : Perl_sv_cmp);
548 sortsv(AvARRAY(keys),
554 dSP; ENTER; SAVETMPS; PUSHMARK(sp);
555 XPUSHs(sv_2mortal(newRV_inc(ival))); PUTBACK;
556 i = perl_call_sv(sortkeys, G_SCALAR | G_EVAL);
560 if (SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVAV))
561 keys = (AV*)SvREFCNT_inc(SvRV(sv));
564 warn("Sortkeys subroutine did not return ARRAYREF\n");
565 PUTBACK; FREETMPS; LEAVE;
568 sv_2mortal((SV*)keys);
571 (void)hv_iterinit((HV*)ival);
573 /* foreach (keys %hash) */
574 for (i = 0; 1; i++) {
579 bool do_utf8 = FALSE;
581 if ((sortkeys && !(keys && i <= av_len(keys))) ||
582 !(entry = hv_iternext((HV *)ival)))
586 sv_catpvn(retval, ",", 1);
590 svp = av_fetch(keys, i, FALSE);
591 keysv = svp ? *svp : sv_mortalcopy(&PL_sv_undef);
592 key = SvPV(keysv, keylen);
593 svp = hv_fetch((HV*)ival, key, keylen, 0);
594 hval = svp ? *svp : sv_mortalcopy(&PL_sv_undef);
597 keysv = hv_iterkeysv(entry);
598 hval = hv_iterval((HV*)ival, entry);
601 do_utf8 = DO_UTF8(keysv);
602 key = SvPV(keysv, keylen);
606 char *okey = SvPVX(retval) + SvCUR(retval);
609 sv_catsv(retval, totpad);
610 sv_catsv(retval, ipad);
611 nlen = esc_q_utf8(aTHX_ retval, key, klen);
613 sname = newSVsv(iname);
614 sv_catpvn(sname, okey, nlen);
615 sv_catpvn(sname, "}", 1);
618 if (quotekeys || needs_quote(key)) {
619 nticks = num_q(key, klen);
620 New(0, nkey, klen+nticks+3, char);
623 klen += esc_q(nkey+1, key, klen);
625 (void)Copy(key, nkey+1, klen, char);
630 New(0, nkey, klen, char);
631 (void)Copy(key, nkey, klen, char);
634 sname = newSVsv(iname);
635 sv_catpvn(sname, nkey, klen);
636 sv_catpvn(sname, "}", 1);
638 sv_catsv(retval, totpad);
639 sv_catsv(retval, ipad);
640 sv_catpvn(retval, nkey, klen);
642 sv_catpvn(retval, " => ", 4);
646 newapad = newSVsv(apad);
647 New(0, extra, klen+4+1, char);
648 while (elen < (klen+4))
651 sv_catpvn(newapad, extra, elen);
657 DD_dump(aTHX_ hval, SvPVX(sname), SvCUR(sname), retval, seenhv,
658 postav, levelp, indent, pad, xpad, newapad, sep,
659 freezer, toaster, purity, deepcopy, quotekeys, bless,
664 SvREFCNT_dec(newapad);
667 SV *opad = sv_x(aTHX_ Nullsv, SvPVX(xpad), SvCUR(xpad), *levelp-1);
668 sv_catsv(retval, totpad);
669 sv_catsv(retval, opad);
673 sv_catpvn(retval, ")", 1);
675 sv_catpvn(retval, "}", 1);
677 SvREFCNT_dec(totpad);
679 else if (realtype == SVt_PVCV) {
680 sv_catpvn(retval, "sub { \"DUMMY\" }", 15);
682 warn("Encountered CODE ref, using dummy placeholder");
685 warn("cannot handle ref type %ld", realtype);
688 if (realpack) { /* free blessed allocs */
693 sv_catpvn(retval, ", '", 3);
694 sv_catpvn(retval, realpack, strlen(realpack));
695 sv_catpvn(retval, "' )", 3);
696 if (toaster && SvPOK(toaster) && SvCUR(toaster)) {
697 sv_catpvn(retval, "->", 2);
698 sv_catsv(retval, toaster);
699 sv_catpvn(retval, "()", 2);
709 (void) sprintf(id, "0x%lx", (unsigned long)val);
710 if ((svp = hv_fetch(seenhv, id, (idlen = strlen(id)), FALSE)) &&
711 (sv = *svp) && SvROK(sv) &&
712 (seenentry = (AV*)SvRV(sv)))
715 if ((svp = av_fetch(seenentry, 0, FALSE)) && (othername = *svp)
716 && (svp = av_fetch(seenentry, 2, FALSE)) && *svp && SvIV(*svp) > 0)
718 sv_catpvn(retval, "${", 2);
719 sv_catsv(retval, othername);
720 sv_catpvn(retval, "}", 1);
726 namesv = newSVpvn("\\", 1);
727 sv_catpvn(namesv, name, namelen);
729 av_push(seenentry, namesv);
730 av_push(seenentry, newRV(val));
731 (void)hv_store(seenhv, id, strlen(id), newRV((SV*)seenentry), 0);
732 SvREFCNT_dec(seenentry);
739 (void) sprintf(tmpbuf, "%"UVuf, SvUV(val));
741 (void) sprintf(tmpbuf, "%"IVdf, SvIV(val));
742 len = strlen(tmpbuf);
743 /* For 5.6.x and earlier will need to change this test to check
744 NV if NOK, as there NOK trumps IOK, and NV=3.5,IV=3 is valid.
745 Current code will Dump that as $VAR1 = 3;
746 Changes in 5.7 series mean that now IOK is only set if scalar
747 is precisely integer. */
749 /* Need to check to see if this is a string such as " 0".
750 I'm assuming from sprintf isn't going to clash with utf8.
751 Is this valid on EBCDIC? */
753 const char *pv = SvPV(val, pvlen);
754 if (pvlen != len || memNE(pv, tmpbuf, len))
755 goto integer_came_from_string;
758 /* Looks like we're on a 64 bit system. Make it a string so that
759 if a 32 bit system reads the number it will cope better. */
760 sv_catpvf(retval, "'%s'", tmpbuf);
762 sv_catpvn(retval, tmpbuf, len);
764 else if (realtype == SVt_PVGV) {/* GLOBs can end up with scribbly names */
766 ++c; --i; /* just get the name */
767 if (i >= 6 && strncmp(c, "main::", 6) == 0) {
771 if (needs_quote(c)) {
772 sv_grow(retval, SvCUR(retval)+6+2*i);
773 r = SvPVX(retval)+SvCUR(retval);
774 r[0] = '*'; r[1] = '{'; r[2] = '\'';
775 i += esc_q(r+3, c, i);
777 r[i++] = '\''; r[i++] = '}';
781 sv_grow(retval, SvCUR(retval)+i+2);
782 r = SvPVX(retval)+SvCUR(retval);
783 r[0] = '*'; strcpy(r+1, c);
786 SvCUR_set(retval, SvCUR(retval)+i);
789 static char *entries[] = { "{SCALAR}", "{ARRAY}", "{HASH}" };
790 static STRLEN sizes[] = { 8, 7, 6 };
792 SV *nname = newSVpvn("", 0);
793 SV *newapad = newSVpvn("", 0);
797 for (j=0; j<3; j++) {
798 e = ((j == 0) ? GvSV(gv) : (j == 1) ? (SV*)GvAV(gv) : (SV*)GvHV(gv));
801 if (j == 0 && !SvOK(e))
806 SV *postentry = newSVpvn(r,i);
808 sv_setsv(nname, postentry);
809 sv_catpvn(nname, entries[j], sizes[j]);
810 sv_catpvn(postentry, " = ", 3);
811 av_push(postav, postentry);
816 (void)sv_x(aTHX_ newapad, " ", 1, SvCUR(postentry));
818 DD_dump(aTHX_ e, SvPVX(nname), SvCUR(nname), postentry,
819 seenhv, postav, &nlevel, indent, pad, xpad,
820 newapad, sep, freezer, toaster, purity,
821 deepcopy, quotekeys, bless, maxdepth,
827 SvREFCNT_dec(newapad);
831 else if (val == &PL_sv_undef || !SvOK(val)) {
832 sv_catpvn(retval, "undef", 5);
835 integer_came_from_string:
838 i += esc_q_utf8(aTHX_ retval, c, i);
840 sv_grow(retval, SvCUR(retval)+3+2*i); /* 3: ""\0 */
841 r = SvPVX(retval) + SvCUR(retval);
843 i += esc_q(r+1, c, i);
847 SvCUR_set(retval, SvCUR(retval)+i);
854 (void)hv_delete(seenhv, id, idlen, G_DISCARD);
855 else if (namelen && seenentry) {
856 SV *mark = *av_fetch(seenentry, 2, TRUE);
864 MODULE = Data::Dumper PACKAGE = Data::Dumper PREFIX = Data_Dumper_
867 # This is the exact equivalent of Dump. Well, almost. The things that are
868 # different as of now (due to Laziness):
869 # * doesnt do double-quotes yet.
873 Data_Dumper_Dumpxs(href, ...)
881 AV *postav, *todumpav, *namesav;
883 I32 indent, terse, i, imax, postlen;
885 SV *val, *name, *pad, *xpad, *apad, *sep, *varname;
886 SV *freezer, *toaster, *bless, *sortkeys;
887 I32 purity, deepcopy, quotekeys, maxdepth = 0;
891 if (!SvROK(href)) { /* call new to get an object first */
893 croak("Usage: Data::Dumper::Dumpxs(PACKAGE, VAL_ARY_REF, [NAME_ARY_REF])");
900 XPUSHs(sv_2mortal(newSVsv(ST(1))));
902 XPUSHs(sv_2mortal(newSVsv(ST(2))));
904 i = perl_call_method("new", G_SCALAR);
907 href = newSVsv(POPs);
913 (void)sv_2mortal(href);
916 todumpav = namesav = Nullav;
918 val = pad = xpad = apad = sep = varname
919 = freezer = toaster = bless = &PL_sv_undef;
920 name = sv_newmortal();
922 terse = purity = deepcopy = 0;
925 retval = newSVpvn("", 0);
927 && (hv = (HV*)SvRV((SV*)href))
928 && SvTYPE(hv) == SVt_PVHV) {
930 if ((svp = hv_fetch(hv, "seen", 4, FALSE)) && SvROK(*svp))
931 seenhv = (HV*)SvRV(*svp);
932 if ((svp = hv_fetch(hv, "todump", 6, FALSE)) && SvROK(*svp))
933 todumpav = (AV*)SvRV(*svp);
934 if ((svp = hv_fetch(hv, "names", 5, FALSE)) && SvROK(*svp))
935 namesav = (AV*)SvRV(*svp);
936 if ((svp = hv_fetch(hv, "indent", 6, FALSE)))
938 if ((svp = hv_fetch(hv, "purity", 6, FALSE)))
940 if ((svp = hv_fetch(hv, "terse", 5, FALSE)))
941 terse = SvTRUE(*svp);
942 #if 0 /* useqq currently unused */
943 if ((svp = hv_fetch(hv, "useqq", 5, FALSE)))
944 useqq = SvTRUE(*svp);
946 if ((svp = hv_fetch(hv, "pad", 3, FALSE)))
948 if ((svp = hv_fetch(hv, "xpad", 4, FALSE)))
950 if ((svp = hv_fetch(hv, "apad", 4, FALSE)))
952 if ((svp = hv_fetch(hv, "sep", 3, FALSE)))
954 if ((svp = hv_fetch(hv, "varname", 7, FALSE)))
956 if ((svp = hv_fetch(hv, "freezer", 7, FALSE)))
958 if ((svp = hv_fetch(hv, "toaster", 7, FALSE)))
960 if ((svp = hv_fetch(hv, "deepcopy", 8, FALSE)))
961 deepcopy = SvTRUE(*svp);
962 if ((svp = hv_fetch(hv, "quotekeys", 9, FALSE)))
963 quotekeys = SvTRUE(*svp);
964 if ((svp = hv_fetch(hv, "bless", 5, FALSE)))
966 if ((svp = hv_fetch(hv, "maxdepth", 8, FALSE)))
967 maxdepth = SvIV(*svp);
968 if ((svp = hv_fetch(hv, "sortkeys", 8, FALSE))) {
970 if (! SvTRUE(sortkeys))
972 else if (! (SvROK(sortkeys) &&
973 SvTYPE(SvRV(sortkeys)) == SVt_PVCV) )
975 /* flag to use qsortsv() for sorting hash keys */
976 sortkeys = &PL_sv_yes;
982 imax = av_len(todumpav);
985 valstr = newSVpvn("",0);
986 for (i = 0; i <= imax; ++i) {
990 if ((svp = av_fetch(todumpav, i, FALSE)))
994 if ((svp = av_fetch(namesav, i, TRUE)))
995 sv_setsv(name, *svp);
997 (void)SvOK_off(name);
1000 if ((SvPVX(name))[0] == '*') {
1002 switch (SvTYPE(SvRV(val))) {
1004 (SvPVX(name))[0] = '@';
1007 (SvPVX(name))[0] = '%';
1010 (SvPVX(name))[0] = '*';
1013 (SvPVX(name))[0] = '$';
1018 (SvPVX(name))[0] = '$';
1020 else if ((SvPVX(name))[0] != '$')
1021 sv_insert(name, 0, 0, "$", 1);
1025 sv_setpvn(name, "$", 1);
1026 sv_catsv(name, varname);
1027 (void) sprintf(tmpbuf, "%"IVdf, (IV)(i+1));
1028 nchars = strlen(tmpbuf);
1029 sv_catpvn(name, tmpbuf, nchars);
1033 SV *tmpsv = sv_x(aTHX_ Nullsv, " ", 1, SvCUR(name)+3);
1034 newapad = newSVsv(apad);
1035 sv_catsv(newapad, tmpsv);
1036 SvREFCNT_dec(tmpsv);
1041 DD_dump(aTHX_ val, SvPVX(name), SvCUR(name), valstr, seenhv,
1042 postav, &level, indent, pad, xpad, newapad, sep,
1043 freezer, toaster, purity, deepcopy, quotekeys,
1044 bless, maxdepth, sortkeys);
1047 SvREFCNT_dec(newapad);
1049 postlen = av_len(postav);
1050 if (postlen >= 0 || !terse) {
1051 sv_insert(valstr, 0, 0, " = ", 3);
1052 sv_insert(valstr, 0, 0, SvPVX(name), SvCUR(name));
1053 sv_catpvn(valstr, ";", 1);
1055 sv_catsv(retval, pad);
1056 sv_catsv(retval, valstr);
1057 sv_catsv(retval, sep);
1060 sv_catsv(retval, pad);
1061 for (i = 0; i <= postlen; ++i) {
1063 svp = av_fetch(postav, i, FALSE);
1064 if (svp && (elem = *svp)) {
1065 sv_catsv(retval, elem);
1067 sv_catpvn(retval, ";", 1);
1068 sv_catsv(retval, sep);
1069 sv_catsv(retval, pad);
1073 sv_catpvn(retval, ";", 1);
1074 sv_catsv(retval, sep);
1076 sv_setpvn(valstr, "", 0);
1077 if (gimme == G_ARRAY) {
1078 XPUSHs(sv_2mortal(retval));
1079 if (i < imax) /* not the last time thro ? */
1080 retval = newSVpvn("",0);
1083 SvREFCNT_dec(postav);
1084 SvREFCNT_dec(valstr);
1087 croak("Call to new() method failed to return HASH ref");
1088 if (gimme == G_SCALAR)
1089 XPUSHs(sv_2mortal(retval));