1 /* Copyright (c) 2008-2014 H.Merijn Brand. All rights reserved.
2 * This program is free software; you can redistribute it and/or
3 * modify it under the same terms as Perl itself.
12 #define NEED_pv_pretty
13 #define NEED_pv_escape
14 #define NEED_my_snprintf
20 SV *_DDump (pTHX_ SV *sv)
26 if (pipe (err)) return (NULL);
31 if (dup (err[1]) == 2)
35 err[1] = dup (err[2]);
38 sv_setpvn (dd, "", 0);
39 while ((n = read (err[0], buf, 128)) > 0)
41 /* perl 5.8.0 did not export Perl_sv_catpvn */
42 sv_catpvn_flags (dd, buf, n, SV_GMAGIC);
44 sv_catpvn (dd, buf, n);
49 SV *_DPeek (pTHX_ int items, SV *sv)
52 return newSVpv ("Your perl did not export Perl_sv_peek ()", 0);
54 return newSVpv (sv_peek (items ? sv : DEFSV), 0);
58 void _Dump_Dual (pTHX_ SV *sv, SV *pv, SV *iv, SV *nv, SV *rv)
61 warn ("%s\n PV: %s\n IV: %s\n NV: %s\n RV: %s\n",
62 sv_peek (sv), sv_peek (pv), sv_peek (iv), sv_peek (nv), sv_peek (rv));
66 MODULE = Data::Peek PACKAGE = Data::Peek
73 ST (0) = _DPeek (aTHX_ items, ST (0));
74 if (gimme == G_VOID) warn ("%s\n", SvPVX (ST (0)));
82 SV *sv = items ? ST (0) : DEFSV;
83 SV *dsp = newSVpv ("", 0);
84 if (SvPOK (sv) || SvPOKp (sv))
85 pv_pretty (dsp, SvPVX (sv), SvCUR (sv), 0,
87 (PERL_PV_PRETTY_DUMP | PERL_PV_ESCAPE_UNI_DETECT));
93 triplevar (pv, iv, nv)
100 SV *tv = newSVpvs ("");
101 SvUPGRADE (tv, SVt_PVNV);
103 if (SvPOK (pv) || SvPOKp (pv)) {
104 sv_setpvn (tv, SvPVX (pv), SvCUR (pv));
105 if (SvUTF8 (pv)) SvUTF8_on (tv);
108 sv_setpvn (tv, NULL, 0);
110 if (SvNOK (nv) || SvNOKp (nv)) {
111 SvNV_set (tv, SvNV (nv));
115 if (SvIOK (iv) || SvIOKp (iv)) {
116 SvIV_set (tv, SvIV (iv));
132 if (items > 1 && SvGMAGICAL (sv) && SvTRUE (ST (1)))
135 if (SvPOK (sv) || SvPOKp (sv)) {
136 SV *xv = newSVpv (SvPVX (sv), 0);
137 if (SvUTF8 (sv)) SvUTF8_on (xv);
141 PUSHs (&PL_sv_undef);
143 if (SvIOK (sv) || SvIOKp (sv))
146 PUSHs (&PL_sv_undef);
148 if (SvNOK (sv) || SvNOKp (sv))
151 PUSHs (&PL_sv_undef);
154 SV *xv = newSVsv (SvRV (sv));
158 PUSHs (&PL_sv_undef);
160 mPUSHi (SvMAGICAL (sv) >> 21);
162 if (gimme == G_VOID) _Dump_Dual (aTHX_ sv, ST (0), ST (1), ST (2), ST (3));
175 sv_setpvn (sv, "", 0);
186 SV *dd = _DDump (aTHX_ sv);
196 #if PERL_VERSION >= 8
199 DDump_IO (io, sv, level)
205 do_sv_dump (0, io, sv, 1, level, 1, 0);