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)
104 STRLEN grow = 0, j = 1, l;
107 /* this will need EBCDICification */
108 for (s = src, send = src + slen; s < send; s += UTF8SKIP(s)) {
109 UV k = utf8_to_uvchr((U8*)s, &l);
112 (*s == '"' || *s == '\\') ? 2 :
113 (k < 0x80 ? 1 : UNISKIP(k) + 1 + 4); /* 4: \x{} */
115 sv_grow(sv, SvCUR(sv)+3+grow); /* 3: ""\0 */
116 r = SvPVX(sv) + SvCUR(sv);
118 for (s = src; s < send; s += UTF8SKIP(s)) {
119 UV k = utf8_to_uvchr((U8*)s, &l);
121 if (*s == '"' || *s == '\\') {
131 j += sprintf(r + j, "%"UVxf, k);
139 r[0] = r[j++] = '\'';
141 SvCUR_set(sv, SvCUR(sv) + j);
146 /* append a repeated string to an SV */
148 sv_x(pTHX_ SV *sv, register char *str, STRLEN len, I32 n)
151 sv = newSVpvn("", 0);
153 assert(SvTYPE(sv) >= SVt_PV);
156 SvGROW(sv, len*n + SvCUR(sv) + 1);
158 char *start = SvPVX(sv) + SvCUR(sv);
166 sv_catpvn(sv, str, len);
174 * This ought to be split into smaller functions. (it is one long function since
175 * it exactly parallels the perl version, which was one long thing for
176 * efficiency raisins.) Ugggh!
179 DD_dump(pTHX_ SV *val, char *name, STRLEN namelen, SV *retval, HV *seenhv,
180 AV *postav, I32 *levelp, I32 indent, SV *pad, SV *xpad,
181 SV *apad, SV *sep, SV *freezer, SV *toaster, I32 purity,
182 I32 deepcopy, I32 quotekeys, SV *bless, I32 maxdepth, SV *sortkeys)
186 char *c, *r, *realpack, id[128];
188 SV *sv, *ipad, *ival;
189 SV *blesspad = Nullsv;
190 AV *seenentry = Nullav;
192 STRLEN inamelen, idlen = 0;
198 realtype = SvTYPE(val);
204 if (SvOBJECT(SvRV(val)) && freezer &&
205 SvPOK(freezer) && SvCUR(freezer))
207 dSP; ENTER; SAVETMPS; PUSHMARK(sp);
208 XPUSHs(val); PUTBACK;
209 i = perl_call_method(SvPVX(freezer), G_EVAL|G_SCALAR);
212 warn("WARNING(Freezer method call failed): %s",
216 PUTBACK; FREETMPS; LEAVE;
218 (void)sv_2mortal(val);
222 realtype = SvTYPE(ival);
223 (void) sprintf(id, "0x%lx", (unsigned long)ival);
226 realpack = HvNAME(SvSTASH(ival));
230 /* if it has a name, we need to either look it up, or keep a tab
231 * on it so we know when we hit it later
234 if ((svp = hv_fetch(seenhv, id, idlen, FALSE))
235 && (sv = *svp) && SvROK(sv) && (seenentry = (AV*)SvRV(sv)))
238 if ((svp = av_fetch(seenentry, 0, FALSE))
239 && (othername = *svp))
241 if (purity && *levelp > 0) {
244 if (realtype == SVt_PVHV)
245 sv_catpvn(retval, "{}", 2);
246 else if (realtype == SVt_PVAV)
247 sv_catpvn(retval, "[]", 2);
249 sv_catpvn(retval, "do{my $o}", 9);
250 postentry = newSVpvn(name, namelen);
251 sv_catpvn(postentry, " = ", 3);
252 sv_catsv(postentry, othername);
253 av_push(postav, postentry);
256 if (name[0] == '@' || name[0] == '%') {
257 if ((SvPVX(othername))[0] == '\\' &&
258 (SvPVX(othername))[1] == name[0]) {
259 sv_catpvn(retval, SvPVX(othername)+1,
263 sv_catpvn(retval, name, 1);
264 sv_catpvn(retval, "{", 1);
265 sv_catsv(retval, othername);
266 sv_catpvn(retval, "}", 1);
270 sv_catsv(retval, othername);
275 warn("ref name not found for %s", id);
279 else { /* store our name and continue */
281 if (name[0] == '@' || name[0] == '%') {
282 namesv = newSVpvn("\\", 1);
283 sv_catpvn(namesv, name, namelen);
285 else if (realtype == SVt_PVCV && name[0] == '*') {
286 namesv = newSVpvn("\\", 2);
287 sv_catpvn(namesv, name, namelen);
288 (SvPVX(namesv))[1] = '&';
291 namesv = newSVpvn(name, namelen);
293 av_push(seenentry, namesv);
294 (void)SvREFCNT_inc(val);
295 av_push(seenentry, val);
296 (void)hv_store(seenhv, id, strlen(id),
297 newRV((SV*)seenentry), 0);
298 SvREFCNT_dec(seenentry);
302 if (realpack && *realpack == 'R' && strEQ(realpack, "Regexp")) {
304 char *rval = SvPV(val, rlen);
305 char *slash = strchr(rval, '/');
306 sv_catpvn(retval, "qr/", 3);
308 sv_catpvn(retval, rval, slash-rval);
309 sv_catpvn(retval, "\\/", 2);
310 rlen -= slash-rval+1;
312 slash = strchr(rval, '/');
314 sv_catpvn(retval, rval, rlen);
315 sv_catpvn(retval, "/", 1);
319 /* If purity is not set and maxdepth is set, then check depth:
320 * if we have reached maximum depth, return the string
321 * representation of the thing we are currently examining
322 * at this depth (i.e., 'Foo=ARRAY(0xdeadbeef)').
324 if (!purity && maxdepth > 0 && *levelp >= maxdepth) {
326 char *valstr = SvPV(val,vallen);
327 sv_catpvn(retval, "'", 1);
328 sv_catpvn(retval, valstr, vallen);
329 sv_catpvn(retval, "'", 1);
333 if (realpack) { /* we have a blessed ref */
335 char *blessstr = SvPV(bless, blesslen);
336 sv_catpvn(retval, blessstr, blesslen);
337 sv_catpvn(retval, "( ", 2);
340 apad = newSVsv(apad);
341 sv_x(aTHX_ apad, " ", 1, blesslen+2);
346 ipad = sv_x(aTHX_ Nullsv, SvPVX(xpad), SvCUR(xpad), *levelp);
348 if (realtype <= SVt_PVBM) { /* scalar ref */
349 SV *namesv = newSVpvn("${", 2);
350 sv_catpvn(namesv, name, namelen);
351 sv_catpvn(namesv, "}", 1);
352 if (realpack) { /* blessed */
353 sv_catpvn(retval, "do{\\(my $o = ", 13);
354 DD_dump(aTHX_ ival, SvPVX(namesv), SvCUR(namesv), retval, seenhv,
355 postav, levelp, indent, pad, xpad, apad, sep,
356 freezer, toaster, purity, deepcopy, quotekeys, bless,
358 sv_catpvn(retval, ")}", 2);
361 sv_catpvn(retval, "\\", 1);
362 DD_dump(aTHX_ ival, SvPVX(namesv), SvCUR(namesv), retval, seenhv,
363 postav, levelp, indent, pad, xpad, apad, sep,
364 freezer, toaster, purity, deepcopy, quotekeys, bless,
367 SvREFCNT_dec(namesv);
369 else if (realtype == SVt_PVGV) { /* glob ref */
370 SV *namesv = newSVpvn("*{", 2);
371 sv_catpvn(namesv, name, namelen);
372 sv_catpvn(namesv, "}", 1);
373 sv_catpvn(retval, "\\", 1);
374 DD_dump(aTHX_ ival, SvPVX(namesv), SvCUR(namesv), retval, seenhv,
375 postav, levelp, indent, pad, xpad, apad, sep,
376 freezer, toaster, purity, deepcopy, quotekeys, bless,
378 SvREFCNT_dec(namesv);
380 else if (realtype == SVt_PVAV) {
383 I32 ixmax = av_len((AV *)ival);
385 SV *ixsv = newSViv(0);
386 /* allowing for a 24 char wide array index */
387 New(0, iname, namelen+28, char);
388 (void)strcpy(iname, name);
390 if (name[0] == '@') {
391 sv_catpvn(retval, "(", 1);
395 sv_catpvn(retval, "[", 1);
396 /* omit "->" in $foo{bar}->[0], but not in ${$foo}->[0] */
398 && name[namelen-1] != ']' && name[namelen-1] != '}'
399 && (namelen < 4 || (name[1] != '{' && name[2] != '{')))*/
401 && name[namelen-1] != ']' && name[namelen-1] != '}')
404 || (name[0] == '\\' && name[2] == '{'))))
406 iname[inamelen++] = '-'; iname[inamelen++] = '>';
407 iname[inamelen] = '\0';
410 if (iname[0] == '*' && iname[inamelen-1] == '}' && inamelen >= 8 &&
411 (instr(iname+inamelen-8, "{SCALAR}") ||
412 instr(iname+inamelen-7, "{ARRAY}") ||
413 instr(iname+inamelen-6, "{HASH}"))) {
414 iname[inamelen++] = '-'; iname[inamelen++] = '>';
416 iname[inamelen++] = '['; iname[inamelen] = '\0';
417 totpad = newSVsv(sep);
418 sv_catsv(totpad, pad);
419 sv_catsv(totpad, apad);
421 for (ix = 0; ix <= ixmax; ++ix) {
424 svp = av_fetch((AV*)ival, ix, FALSE);
432 (void) sprintf(iname+ilen, "%"IVdf, (IV)ix);
433 ilen = strlen(iname);
434 iname[ilen++] = ']'; iname[ilen] = '\0';
436 sv_catsv(retval, totpad);
437 sv_catsv(retval, ipad);
438 sv_catpvn(retval, "#", 1);
439 sv_catsv(retval, ixsv);
441 sv_catsv(retval, totpad);
442 sv_catsv(retval, ipad);
443 DD_dump(aTHX_ elem, iname, ilen, retval, seenhv, postav,
444 levelp, indent, pad, xpad, apad, sep,
445 freezer, toaster, purity, deepcopy, quotekeys, bless,
448 sv_catpvn(retval, ",", 1);
451 SV *opad = sv_x(aTHX_ Nullsv, SvPVX(xpad), SvCUR(xpad), (*levelp)-1);
452 sv_catsv(retval, totpad);
453 sv_catsv(retval, opad);
457 sv_catpvn(retval, ")", 1);
459 sv_catpvn(retval, "]", 1);
461 SvREFCNT_dec(totpad);
464 else if (realtype == SVt_PVHV) {
465 SV *totpad, *newapad;
473 iname = newSVpvn(name, namelen);
474 if (name[0] == '%') {
475 sv_catpvn(retval, "(", 1);
476 (SvPVX(iname))[0] = '$';
479 sv_catpvn(retval, "{", 1);
480 /* omit "->" in $foo[0]->{bar}, but not in ${$foo}->{bar} */
482 && name[namelen-1] != ']' && name[namelen-1] != '}')
485 || (name[0] == '\\' && name[2] == '{'))))
487 sv_catpvn(iname, "->", 2);
490 if (name[0] == '*' && name[namelen-1] == '}' && namelen >= 8 &&
491 (instr(name+namelen-8, "{SCALAR}") ||
492 instr(name+namelen-7, "{ARRAY}") ||
493 instr(name+namelen-6, "{HASH}"))) {
494 sv_catpvn(iname, "->", 2);
496 sv_catpvn(iname, "{", 1);
497 totpad = newSVsv(sep);
498 sv_catsv(totpad, pad);
499 sv_catsv(totpad, apad);
501 /* If requested, get a sorted/filtered array of hash keys */
503 if (sortkeys == &PL_sv_yes) {
505 (void)hv_iterinit((HV*)ival);
506 while (entry = hv_iternext((HV*)ival)) {
507 sv = hv_iterkeysv(entry);
511 #ifdef USE_LOCALE_NUMERIC
512 sortsv(AvARRAY(keys),
514 IN_LOCALE ? Perl_sv_cmp_locale : Perl_sv_cmp);
516 sortsv(AvARRAY(keys),
522 dSP; ENTER; SAVETMPS; PUSHMARK(sp);
523 XPUSHs(sv_2mortal(newRV_inc(ival))); PUTBACK;
524 i = perl_call_sv(sortkeys, G_SCALAR | G_EVAL);
528 if (SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVAV))
529 keys = (AV*)SvREFCNT_inc(SvRV(sv));
532 warn("Sortkeys subroutine did not return ARRAYREF\n");
533 PUTBACK; FREETMPS; LEAVE;
536 sv_2mortal((SV*)keys);
539 (void)hv_iterinit((HV*)ival);
541 /* foreach (keys %hash) */
542 for (i = 0; 1; i++) {
547 bool do_utf8 = FALSE;
549 if ((sortkeys && !(keys && i <= av_len(keys))) ||
550 !(entry = hv_iternext((HV *)ival)))
554 sv_catpvn(retval, ",", 1);
558 svp = av_fetch(keys, i, FALSE);
559 keysv = svp ? *svp : sv_mortalcopy(&PL_sv_undef);
560 key = SvPV(keysv, keylen);
561 svp = hv_fetch((HV*)ival, key, keylen, 0);
562 hval = svp ? *svp : sv_mortalcopy(&PL_sv_undef);
565 keysv = hv_iterkeysv(entry);
566 hval = hv_iterval((HV*)ival, entry);
569 do_utf8 = DO_UTF8(keysv);
570 key = SvPV(keysv, keylen);
574 char *okey = SvPVX(retval) + SvCUR(retval);
577 sv_catsv(retval, totpad);
578 sv_catsv(retval, ipad);
579 nlen = esc_q_utf8(aTHX_ retval, key, klen);
581 sname = newSVsv(iname);
582 sv_catpvn(sname, okey, nlen);
583 sv_catpvn(sname, "}", 1);
586 if (quotekeys || needs_quote(key)) {
587 nticks = num_q(key, klen);
588 New(0, nkey, klen+nticks+3, char);
591 klen += esc_q(nkey+1, key, klen);
593 (void)Copy(key, nkey+1, klen, char);
598 New(0, nkey, klen, char);
599 (void)Copy(key, nkey, klen, char);
602 sname = newSVsv(iname);
603 sv_catpvn(sname, nkey, klen);
604 sv_catpvn(sname, "}", 1);
606 sv_catsv(retval, totpad);
607 sv_catsv(retval, ipad);
608 sv_catpvn(retval, nkey, klen);
610 sv_catpvn(retval, " => ", 4);
614 newapad = newSVsv(apad);
615 New(0, extra, klen+4+1, char);
616 while (elen < (klen+4))
619 sv_catpvn(newapad, extra, elen);
625 DD_dump(aTHX_ hval, SvPVX(sname), SvCUR(sname), retval, seenhv,
626 postav, levelp, indent, pad, xpad, newapad, sep,
627 freezer, toaster, purity, deepcopy, quotekeys, bless,
632 SvREFCNT_dec(newapad);
635 SV *opad = sv_x(aTHX_ Nullsv, SvPVX(xpad), SvCUR(xpad), *levelp-1);
636 sv_catsv(retval, totpad);
637 sv_catsv(retval, opad);
641 sv_catpvn(retval, ")", 1);
643 sv_catpvn(retval, "}", 1);
645 SvREFCNT_dec(totpad);
647 else if (realtype == SVt_PVCV) {
648 sv_catpvn(retval, "sub { \"DUMMY\" }", 15);
650 warn("Encountered CODE ref, using dummy placeholder");
653 warn("cannot handle ref type %ld", realtype);
656 if (realpack) { /* free blessed allocs */
661 sv_catpvn(retval, ", '", 3);
662 sv_catpvn(retval, realpack, strlen(realpack));
663 sv_catpvn(retval, "' )", 3);
664 if (toaster && SvPOK(toaster) && SvCUR(toaster)) {
665 sv_catpvn(retval, "->", 2);
666 sv_catsv(retval, toaster);
667 sv_catpvn(retval, "()", 2);
677 (void) sprintf(id, "0x%lx", (unsigned long)val);
678 if ((svp = hv_fetch(seenhv, id, (idlen = strlen(id)), FALSE)) &&
679 (sv = *svp) && SvROK(sv) &&
680 (seenentry = (AV*)SvRV(sv)))
683 if ((svp = av_fetch(seenentry, 0, FALSE)) && (othername = *svp)
684 && (svp = av_fetch(seenentry, 2, FALSE)) && *svp && SvIV(*svp) > 0)
686 sv_catpvn(retval, "${", 2);
687 sv_catsv(retval, othername);
688 sv_catpvn(retval, "}", 1);
694 namesv = newSVpvn("\\", 1);
695 sv_catpvn(namesv, name, namelen);
697 av_push(seenentry, namesv);
698 av_push(seenentry, newRV(val));
699 (void)hv_store(seenhv, id, strlen(id), newRV((SV*)seenentry), 0);
700 SvREFCNT_dec(seenentry);
707 (void) sprintf(tmpbuf, "%"UVuf, SvUV(val));
709 (void) sprintf(tmpbuf, "%"IVdf, SvIV(val));
710 len = strlen(tmpbuf);
711 sv_catpvn(retval, tmpbuf, len);
713 else if (realtype == SVt_PVGV) {/* GLOBs can end up with scribbly names */
715 ++c; --i; /* just get the name */
716 if (i >= 6 && strncmp(c, "main::", 6) == 0) {
720 if (needs_quote(c)) {
721 sv_grow(retval, SvCUR(retval)+6+2*i);
722 r = SvPVX(retval)+SvCUR(retval);
723 r[0] = '*'; r[1] = '{'; r[2] = '\'';
724 i += esc_q(r+3, c, i);
726 r[i++] = '\''; r[i++] = '}';
730 sv_grow(retval, SvCUR(retval)+i+2);
731 r = SvPVX(retval)+SvCUR(retval);
732 r[0] = '*'; strcpy(r+1, c);
735 SvCUR_set(retval, SvCUR(retval)+i);
738 static char *entries[] = { "{SCALAR}", "{ARRAY}", "{HASH}" };
739 static STRLEN sizes[] = { 8, 7, 6 };
741 SV *nname = newSVpvn("", 0);
742 SV *newapad = newSVpvn("", 0);
746 for (j=0; j<3; j++) {
747 e = ((j == 0) ? GvSV(gv) : (j == 1) ? (SV*)GvAV(gv) : (SV*)GvHV(gv));
750 if (j == 0 && !SvOK(e))
755 SV *postentry = newSVpvn(r,i);
757 sv_setsv(nname, postentry);
758 sv_catpvn(nname, entries[j], sizes[j]);
759 sv_catpvn(postentry, " = ", 3);
760 av_push(postav, postentry);
765 (void)sv_x(aTHX_ newapad, " ", 1, SvCUR(postentry));
767 DD_dump(aTHX_ e, SvPVX(nname), SvCUR(nname), postentry,
768 seenhv, postav, &nlevel, indent, pad, xpad,
769 newapad, sep, freezer, toaster, purity,
770 deepcopy, quotekeys, bless, maxdepth,
776 SvREFCNT_dec(newapad);
780 else if (val == &PL_sv_undef || !SvOK(val)) {
781 sv_catpvn(retval, "undef", 5);
786 i += esc_q_utf8(aTHX_ retval, c, i);
788 sv_grow(retval, SvCUR(retval)+3+2*i); /* 3: ""\0 */
789 r = SvPVX(retval) + SvCUR(retval);
791 i += esc_q(r+1, c, i);
795 SvCUR_set(retval, SvCUR(retval)+i);
802 (void)hv_delete(seenhv, id, idlen, G_DISCARD);
803 else if (namelen && seenentry) {
804 SV *mark = *av_fetch(seenentry, 2, TRUE);
812 MODULE = Data::Dumper PACKAGE = Data::Dumper PREFIX = Data_Dumper_
815 # This is the exact equivalent of Dump. Well, almost. The things that are
816 # different as of now (due to Laziness):
817 # * doesnt do double-quotes yet.
821 Data_Dumper_Dumpxs(href, ...)
829 AV *postav, *todumpav, *namesav;
831 I32 indent, terse, i, imax, postlen;
833 SV *val, *name, *pad, *xpad, *apad, *sep, *varname;
834 SV *freezer, *toaster, *bless, *sortkeys;
835 I32 purity, deepcopy, quotekeys, maxdepth = 0;
839 if (!SvROK(href)) { /* call new to get an object first */
841 croak("Usage: Data::Dumper::Dumpxs(PACKAGE, VAL_ARY_REF, [NAME_ARY_REF])");
848 XPUSHs(sv_2mortal(newSVsv(ST(1))));
850 XPUSHs(sv_2mortal(newSVsv(ST(2))));
852 i = perl_call_method("new", G_SCALAR);
855 href = newSVsv(POPs);
861 (void)sv_2mortal(href);
864 todumpav = namesav = Nullav;
866 val = pad = xpad = apad = sep = varname
867 = freezer = toaster = bless = &PL_sv_undef;
868 name = sv_newmortal();
870 terse = purity = deepcopy = 0;
873 retval = newSVpvn("", 0);
875 && (hv = (HV*)SvRV((SV*)href))
876 && SvTYPE(hv) == SVt_PVHV) {
878 if ((svp = hv_fetch(hv, "seen", 4, FALSE)) && SvROK(*svp))
879 seenhv = (HV*)SvRV(*svp);
880 if ((svp = hv_fetch(hv, "todump", 6, FALSE)) && SvROK(*svp))
881 todumpav = (AV*)SvRV(*svp);
882 if ((svp = hv_fetch(hv, "names", 5, FALSE)) && SvROK(*svp))
883 namesav = (AV*)SvRV(*svp);
884 if ((svp = hv_fetch(hv, "indent", 6, FALSE)))
886 if ((svp = hv_fetch(hv, "purity", 6, FALSE)))
888 if ((svp = hv_fetch(hv, "terse", 5, FALSE)))
889 terse = SvTRUE(*svp);
890 #if 0 /* useqq currently unused */
891 if ((svp = hv_fetch(hv, "useqq", 5, FALSE)))
892 useqq = SvTRUE(*svp);
894 if ((svp = hv_fetch(hv, "pad", 3, FALSE)))
896 if ((svp = hv_fetch(hv, "xpad", 4, FALSE)))
898 if ((svp = hv_fetch(hv, "apad", 4, FALSE)))
900 if ((svp = hv_fetch(hv, "sep", 3, FALSE)))
902 if ((svp = hv_fetch(hv, "varname", 7, FALSE)))
904 if ((svp = hv_fetch(hv, "freezer", 7, FALSE)))
906 if ((svp = hv_fetch(hv, "toaster", 7, FALSE)))
908 if ((svp = hv_fetch(hv, "deepcopy", 8, FALSE)))
909 deepcopy = SvTRUE(*svp);
910 if ((svp = hv_fetch(hv, "quotekeys", 9, FALSE)))
911 quotekeys = SvTRUE(*svp);
912 if ((svp = hv_fetch(hv, "bless", 5, FALSE)))
914 if ((svp = hv_fetch(hv, "maxdepth", 8, FALSE)))
915 maxdepth = SvIV(*svp);
916 if ((svp = hv_fetch(hv, "sortkeys", 8, FALSE))) {
918 if (! SvTRUE(sortkeys))
920 else if (! (SvROK(sortkeys) &&
921 SvTYPE(SvRV(sortkeys)) == SVt_PVCV) )
923 /* flag to use qsortsv() for sorting hash keys */
924 sortkeys = &PL_sv_yes;
930 imax = av_len(todumpav);
933 valstr = newSVpvn("",0);
934 for (i = 0; i <= imax; ++i) {
938 if ((svp = av_fetch(todumpav, i, FALSE)))
942 if ((svp = av_fetch(namesav, i, TRUE)))
943 sv_setsv(name, *svp);
945 (void)SvOK_off(name);
948 if ((SvPVX(name))[0] == '*') {
950 switch (SvTYPE(SvRV(val))) {
952 (SvPVX(name))[0] = '@';
955 (SvPVX(name))[0] = '%';
958 (SvPVX(name))[0] = '*';
961 (SvPVX(name))[0] = '$';
966 (SvPVX(name))[0] = '$';
968 else if ((SvPVX(name))[0] != '$')
969 sv_insert(name, 0, 0, "$", 1);
973 sv_setpvn(name, "$", 1);
974 sv_catsv(name, varname);
975 (void) sprintf(tmpbuf, "%"IVdf, (IV)(i+1));
976 nchars = strlen(tmpbuf);
977 sv_catpvn(name, tmpbuf, nchars);
981 SV *tmpsv = sv_x(aTHX_ Nullsv, " ", 1, SvCUR(name)+3);
982 newapad = newSVsv(apad);
983 sv_catsv(newapad, tmpsv);
989 DD_dump(aTHX_ val, SvPVX(name), SvCUR(name), valstr, seenhv,
990 postav, &level, indent, pad, xpad, newapad, sep,
991 freezer, toaster, purity, deepcopy, quotekeys,
992 bless, maxdepth, sortkeys);
995 SvREFCNT_dec(newapad);
997 postlen = av_len(postav);
998 if (postlen >= 0 || !terse) {
999 sv_insert(valstr, 0, 0, " = ", 3);
1000 sv_insert(valstr, 0, 0, SvPVX(name), SvCUR(name));
1001 sv_catpvn(valstr, ";", 1);
1003 sv_catsv(retval, pad);
1004 sv_catsv(retval, valstr);
1005 sv_catsv(retval, sep);
1008 sv_catsv(retval, pad);
1009 for (i = 0; i <= postlen; ++i) {
1011 svp = av_fetch(postav, i, FALSE);
1012 if (svp && (elem = *svp)) {
1013 sv_catsv(retval, elem);
1015 sv_catpvn(retval, ";", 1);
1016 sv_catsv(retval, sep);
1017 sv_catsv(retval, pad);
1021 sv_catpvn(retval, ";", 1);
1022 sv_catsv(retval, sep);
1024 sv_setpvn(valstr, "", 0);
1025 if (gimme == G_ARRAY) {
1026 XPUSHs(sv_2mortal(retval));
1027 if (i < imax) /* not the last time thro ? */
1028 retval = newSVpvn("",0);
1031 SvREFCNT_dec(postav);
1032 SvREFCNT_dec(valstr);
1035 croak("Call to new() method failed to return HASH ref");
1036 if (gimme == G_SCALAR)
1037 XPUSHs(sv_2mortal(retval));