X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDumpvalue.pm;h=94b6aa6e78c9bbf6517913bac3650ec04a2b3478;hb=0bcd2fea6bc6ecdf03a0c2410ba83be70e2072dc;hp=9c596ffc0518351e331dbb93aa9da9f2a752cedd;hpb=f6b3007c38a92f48d086a19ea8682dd935b6d4ee;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Dumpvalue.pm b/lib/Dumpvalue.pm index 9c596ff..94b6aa6 100644 --- a/lib/Dumpvalue.pm +++ b/lib/Dumpvalue.pm @@ -1,7 +1,7 @@ -require 5.005; # For (defined ref) and $#$v +use 5.005_64; # for (defined ref) and $#$v and our package Dumpvalue; use strict; -use vars qw(%address *stab %subs); +our(%address, $stab, @stab, %stab, %subs); # translate control chars to ^X - Randal Schwartz # Modifications to print types by Peter Gordon v1.0 @@ -91,7 +91,7 @@ sub stringify { { no strict 'refs'; $_ = &{'overload::StrVal'}($_) if $self->{bareStringify} and ref $_ - and defined %overload:: and defined &{'overload::StrVal'}; + and %overload:: and defined &{'overload::StrVal'}; } if ($tick eq 'auto') { @@ -162,7 +162,7 @@ sub unwrap { my $val = $v; { no strict 'refs'; $val = &{'overload::StrVal'}($v) - if defined %overload:: and defined &{'overload::StrVal'}; + if %overload:: and defined &{'overload::StrVal'}; } ($address) = $val =~ /(0x[0-9a-f]+)\)$/ ; if (!$self->{dumpReused} && defined $address) { @@ -324,12 +324,12 @@ sub dumpglob { print( (' ' x $off) . "\$", &unctrl($key), " = " ); $self->DumpElem($stab, 3+$off); } - if (($key !~ /^_{dumpDBFiles}) and defined @stab) { + if (($key !~ /^_{dumpDBFiles}) and @stab) { print( (' ' x $off) . "\@$key = (\n" ); $self->unwrap(\@stab,3+$off) ; print( (' ' x $off) . ")\n" ); } - if ($key ne "main::" && $key ne "DB::" && defined %stab + if ($key ne "main::" && $key ne "DB::" && %stab && ($self->{dumpPackages} or $key !~ /::$/) && ($key !~ /^_{dumpDBFiles}) && !($package eq "Dumpvalue" and $key eq "stab")) { @@ -347,21 +347,35 @@ sub dumpglob { } } +sub CvGV_name { + my $self = shift; + my $in = shift; + return if $self->{skipCvGV}; # Backdoor to avoid problems if XS broken... + $in = \&$in; # Hard reference... + eval {require Devel::Peek; 1} or return; + my $gv = Devel::Peek::CvGV($in) or return; + *$gv{PACKAGE} . '::' . *$gv{NAME}; +} + sub dumpsub { my $self = shift; my ($off,$sub) = @_; + my $ini = $sub; + my $s; $sub = $1 if $sub =~ /^\{\*(.*)\}$/; - my $subref = \&$sub; - my $place = $DB::sub{$sub} || (($sub = $subs{"$subref"}) && $DB::sub{$sub}) - || ($self->{subdump} && ($sub = $self->findsubs("$subref")) - && $DB::sub{$sub}); + my $subref = defined $1 ? \&$sub : \&$ini; + my $place = $DB::sub{$sub} || (($s = $subs{"$subref"}) && $DB::sub{$s}) + || (($s = $self->CvGV_name($subref)) && $DB::sub{$s}) + || ($self->{subdump} && ($s = $self->findsubs("$subref")) + && $DB::sub{$s}); + $s = $sub unless defined $s; $place = '???' unless defined $place; - print( (' ' x $off) . "&$sub in $place\n" ); + print( (' ' x $off) . "&$s in $place\n" ); } sub findsubs { my $self = shift; - return undef unless defined %DB::sub; + return undef unless %DB::sub; my ($addr, $name, $loc); while (($name, $loc) = each %DB::sub) { $addr = \&$name; @@ -444,9 +458,9 @@ sub globUsage { # glob ref, name local *stab = *{$_[0]}; my $total = 0; $total += $self->scalarUsage($stab) if defined $stab; - $total += $self->arrayUsage(\@stab, $_[1]) if defined @stab; + $total += $self->arrayUsage(\@stab, $_[1]) if @stab; $total += $self->hashUsage(\%stab, $_[1]) - if defined %stab and $_[1] ne "main::" and $_[1] ne "DB::"; + if %stab and $_[1] ne "main::" and $_[1] ne "DB::"; #and !($package eq "Dumpvalue" and $key eq "stab")); $total; } @@ -457,7 +471,7 @@ sub globUsage { # glob ref, name Dumpvalue - provides screen dump of Perl data. -=head1 SYNOPSYS +=head1 SYNOPSIS use Dumpvalue; my $dumper = new Dumpvalue;