package Dumpvalue;
use strict;
our $VERSION = '1.11';
# documentation nits, handle complex data structures better by chromatic
# translate control chars to ^X - Randal Schwartz
# Modifications to print types by Peter Gordon v1.0
# Ilya Zakharevich -- patches after 5.001 (and some before ;-)
# Won't dump symbol tables and contents of debugged files by default
# (IZ) changes for objectification:
# c) quote() renamed to method set_quote();
# d) unctrlSet() renamed to method set_unctrl();
# f) Compiles with `use strict', but in two places no strict refs is needed:
# maybe more problems are waiting...
my %defaults = (
globPrint => 0,
printUndef => 1,
tick => "auto",
unctrl => 'quote',
subdump => 1,
dumpReused => 0,
bareStringify => 1,
hashDepth => '',
arrayDepth => '',
dumpDBFiles => '',
dumpPackages => '',
quoteHighBit => '',
usageOnly => '',
compactDump => '',
veryCompact => '',
stopDbSignal => '',
);
sub new {
my $class = shift;
}
sub set {
my $self = shift;
my %opt = @_;
}
sub get {
my $self = shift;
}
sub dumpValue {
my $self = shift;
die "usage: \$dumper->dumpValue(value)" unless @_ == 1;
local %address;
local $^W=0;
(print "undef\n"), return unless defined $_[0];
}
sub dumpValues {
my $self = shift;
local %address;
local $^W=0;
(print "undef\n"), return unless defined $_[0];
}
# This one is good for variable names:
sub unctrl {
local($_) = @_;
return \$_ if ref \$_ eq "GLOB";
$_;
}
sub stringify {
my $self = shift;
local $_ = shift;
my $noticks = shift;
return $_ . "" if ref \$_ eq 'GLOB';
{ no strict 'refs';
$_ = &{'overload::StrVal'}($_)
if $self->{bareStringify} and ref $_
and %overload:: and defined &{'overload::StrVal'};
}
if ($tick eq 'auto') {
if (/[\000-\011\013-\037\177]/) {
$tick = '"';
} else {
$tick = "'";
}
}
if ($tick eq "'") {
s/([\'\\])/\\$1/g;
s/([\"\\])/\\$1/g ;
if $self->{quoteHighBit};
s/([\"\\\$\@])/\\$1/g if $tick eq '"';
s/\033/\\e/g;
}
($noticks || /^\d+(\.\d*)?\Z/)
? $_
}
sub DumpElem {
my ($self, $v) = (shift, shift);
my $shortmore = '';
if ($self->{veryCompact} && ref $v
&& (ref $v eq 'ARRAY' and !grep(ref $_, @$v) )) {
my $depth = $#$v;
print "0..$#{$v} @a$shortmore\n";
} elsif ($self->{veryCompact} && ref $v
&& (ref $v eq 'HASH') and !grep(ref $_, values %$v)) {
my @a = sort keys %$v;
my $depth = $#a;
@a[0..$depth];
local $" = ', ';
print "@b$shortmore\n";
} else {
print "$short\n";
}
}
sub unwrap {
my $self = shift;
my ($v) = shift ;
my ($s) = shift ; # extra no of spaces
my $sp;
$sp = " " x $s ;
$s += 3 ;
# Check for reused addresses
if (ref $v) {
my $val = $v;
{ no strict 'refs';
$val = &{'overload::StrVal'}($v)
if %overload:: and defined &{'overload::StrVal'};
}
print "${sp}-> REUSED_ADDRESS\n" ;
return ;
}
}
} elsif (ref \$v eq 'GLOB') {
print "${sp}*DUMPED_GLOB*\n" ;
return ;
}
}
if (ref $v eq 'Regexp') {
my $re = "$v";
$re =~ s,/,\\/,g;
print "$sp-> qr/$re/\n";
return;
}
my @sortKeys = sort keys(%$v) ;
my $more;
my $tHashDepth = $#sortKeys ;
$tHashDepth = $#sortKeys < $self->{hashDepth}-1 ? $#sortKeys : $self->{hashDepth}-1
my $shortmore = "";
$#sortKeys = $tHashDepth ;
if ($self->{compactDump} && !grep(ref $_, values %{$v})) {
my @keys;
for (@sortKeys) {
}
}
}
print "$sp empty hash\n" unless @sortKeys;
print "$sp$more" if defined $more ;
my $tArrayDepth = $#{$v} ;
my $more ;
$tArrayDepth = $#$v < $self->{arrayDepth}-1 ? $#$v : $self->{arrayDepth}-1
my $shortmore = "";
if ($self->{compactDump} && !grep(ref $_, @{$v})) {
if ($#$v >= 0) {
join(" ",
) . "$shortmore";
} else {
}
}
for my $num ($[ .. $tArrayDepth) {
print "$sp$num ";
if (exists $v->[$num]) {
} else {
print "empty slot\n";
}
}
print "$sp empty array\n" unless @$v;
print "$sp$more" if defined $more ;
print "$sp-> ";
print "$sp-> ";
$s += 3;
} elsif (defined ($fileno = fileno($v))) {
print( (' ' x ($s+3)) . "FileHandle({$$v}) => fileno($fileno)\n" );
}
} elsif (ref \$v eq 'GLOB') {
} elsif (defined ($fileno = fileno(\$v))) {
print( (' ' x $s) . "FileHandle({$v}) => fileno($fileno)\n" );
}
}
}
sub matchvar {
$_[0] eq $_[1] or
($1 eq '!') ^ (eval {($_[2] . "::" . $_[0]) =~ /$2$3/});
}
sub compactDump {
my $self = shift;
$self->{compactDump} = shift if @_;
$self->{compactDump};
}
sub veryCompact {
my $self = shift;
$self->{veryCompact} = shift if @_;
$self->{veryCompact};
}
sub set_unctrl {
my $self = shift;
if (@_) {
my $in = shift;
} else {
print "Unknown value for `unctrl'.\n";
}
}
}
sub set_quote {
my $self = shift;
if (@_ and $_[0] eq '"') {
} elsif (@_ and $_[0] eq 'auto') {
} elsif (@_) { # Need to set
}
}
sub dumpglob {
my $self = shift;
my $fileno;
}
}
}
}
if ($all) {
if (defined &stab) {
}
}
}
sub CvGV_name {
my $self = shift;
my $in = shift;
}
sub dumpsub {
my $self = shift;
my $s;
&& $DB::sub{$s});
$s = $sub unless defined $s;
}
sub findsubs {
my $self = shift;
return undef unless %DB::sub;
}
$subs{ shift() };
}
sub dumpvars {
my $self = shift;
local(%address,$^W);
while ($package =~ /(\w+?::)/g) {
}
and ref(\$val) eq 'GLOB';
} else {
}
}
print <<EOP;
print <<EOP;
}
}
sub scalarUsage {
my $self = shift;
my $size;
} elsif (!ref($_[0])) {
$size = length($_[0]);
}
$size;
}
my $self = shift;
my $size = 0;
my $len = @{$_[0]};
if defined $_[1];
$size;
}
my $self = shift;
my @keys = keys %{$_[0]};
my @values = values %{$_[0]};
" (keys: $keys; values: $values; total: $total bytes)\n"
if defined $_[1];
$total;
}
my $self = shift;
local *stab = *{$_[0]};
my $total = 0;
#and !($package eq "Dumpvalue" and $key eq "stab"));
$total;
}
1;
=head1 NAME
Dumpvalue - provides screen dump of Perl data.
=head1 SYNOPSIS
use Dumpvalue;
my $dumper = new Dumpvalue;
$dumper->set(globPrint => 1);
$dumper->dumpValue(\*::);
$dumper->dumpvars('main');
my $dump = $dumper->stringify($some_value);
=head1 DESCRIPTION
=head2 Creation
A new dumper is created by a call
$d = new Dumpvalue(option1 => value1, option2 => value2)
Recognized options:
=over 4
=item C<arrayDepth>, C<hashDepth>
Print only first N elements of arrays and hashes. If false, prints all the
elements.
=item C<compactDump>, C<veryCompact>
Change style of array and hash dump. If true, short array
may be printed on one line.
=item C<globPrint>
Whether to print contents of globs.
=item C<dumpDBFiles>
Dump arrays holding contents of debugged files.
=item C<dumpPackages>
Dump symbol tables of packages.
=item C<dumpReused>
Dump contents of "reused" addresses.
=item C<tick>, C<quoteHighBit>, C<printUndef>
Change style of string dump. Default value of C<tick> is C<auto>, one
can enable either double-quotish dump, or single-quotish by setting it
to C<"> or C<'>. By default, characters with high bit set are printed
I<as is>. If C<quoteHighBit> is set, they will be quoted.
=item C<usageOnly>
rudimentally per-package memory usage dump. If set,
C<dumpvars> calculates total size of strings in variables in the package.
=item unctrl
Changes the style of printout of strings. Possible values are
C<unctrl> and C<quote>.
=item subdump
Whether to try to find the subroutine name given the reference.
=item bareStringify
Whether to write the non-overloaded form of the stringify-overloaded objects.
=item quoteHighBit
Whether to print chars with high bit set in binary or "as is".
=item stopDbSignal
Whether to abort printing if debugger signal flag is raised.
=back
Later in the life of the object the methods may be queries with get()
method and set() method (which accept multiple arguments).
=head2 Methods
=over 4
=item dumpValue
$dumper->dumpValue($value);
$dumper->dumpValue([$value1, $value2]);
Prints a dump to the currently selected filehandle.
=item dumpValues
$dumper->dumpValues($value1, $value2);
Same as C< $dumper->dumpValue([$value1, $value2]); >.
=item stringify
my $dump = $dumper->stringify($value [,$noticks] );
Returns the dump of a single scalar without printing. If the second
argument is true, the return value does not contain enclosing ticks.
Does not handle data structures.
=item dumpvars
$dumper->dumpvars('my_package');
$dumper->dumpvars('my_package', 'foo', '~bar$', '!......');
The optional arguments are considered as literal strings unless they
start with C<~> or C<!>, in which case they are interpreted as regular
expressions (possibly negated).
The second example prints entries with names C<foo>, and also entries
with names which ends on C<bar>, or are shorter than 5 chars.
=item set_quote
$d->set_quote('"');
Sets C<tick> and C<unctrl> options to suitable values for printout with the
given quote char. Possible values are C<auto>, C<'> and C<">.
=item set_unctrl
$d->set_unctrl('"');
Sets C<unctrl> option with checking for an invalid argument.
Possible values are C<unctrl> and C<quote>.
=item compactDump
$d->compactDump(1);
Sets C<compactDump> option. If the value is 1, sets to a reasonable
big number.
=item veryCompact
$d->veryCompact(1);
Sets C<compactDump> and C<veryCompact> options simultaneously.
=item set
$d->set(option1 => value1, option2 => value2);
=item get
@values = $d->get('option1', 'option2');
=back
=cut