Initial Commit
This commit is contained in:
21018
database/perl/lib/Devel/PPPort.pm
Normal file
21018
database/perl/lib/Devel/PPPort.pm
Normal file
File diff suppressed because it is too large
Load Diff
586
database/perl/lib/Devel/Peek.pm
Normal file
586
database/perl/lib/Devel/Peek.pm
Normal file
@@ -0,0 +1,586 @@
|
||||
# Devel::Peek - A data debugging tool for the XS programmer
|
||||
# The documentation is after the __END__
|
||||
|
||||
package Devel::Peek;
|
||||
|
||||
$VERSION = '1.28';
|
||||
$XS_VERSION = $VERSION;
|
||||
$VERSION = eval $VERSION;
|
||||
|
||||
require Exporter;
|
||||
require XSLoader;
|
||||
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw(Dump mstat DeadCode DumpArray DumpWithOP DumpProg
|
||||
fill_mstats mstats_fillhash mstats2hash runops_debug debug_flags);
|
||||
@EXPORT_OK = qw(SvREFCNT CvGV);
|
||||
%EXPORT_TAGS = ('ALL' => [@EXPORT, @EXPORT_OK]);
|
||||
|
||||
XSLoader::load();
|
||||
|
||||
sub import {
|
||||
my $c = shift;
|
||||
my $ops_rx = qr/^:opd(=[stP]*)?\b/;
|
||||
my @db = grep m/$ops_rx/, @_;
|
||||
@_ = grep !m/$ops_rx/, @_;
|
||||
if (@db) {
|
||||
die "Too many :opd options" if @db > 1;
|
||||
runops_debug(1);
|
||||
my $flags = ($db[0] =~ m/$ops_rx/ and $1);
|
||||
$flags = 'st' unless defined $flags;
|
||||
my $f = 0;
|
||||
$f |= 2 if $flags =~ /s/;
|
||||
$f |= 8 if $flags =~ /t/;
|
||||
$f |= 64 if $flags =~ /P/;
|
||||
$^D |= $f if $f;
|
||||
}
|
||||
unshift @_, $c;
|
||||
goto &Exporter::import;
|
||||
}
|
||||
|
||||
sub DumpWithOP ($;$) {
|
||||
local($Devel::Peek::dump_ops)=1;
|
||||
my $depth = @_ > 1 ? $_[1] : 4 ;
|
||||
Dump($_[0],$depth);
|
||||
}
|
||||
|
||||
$D_flags = 'psltocPmfrxuLHXDSTR';
|
||||
|
||||
sub debug_flags (;$) {
|
||||
my $out = "";
|
||||
for my $i (0 .. length($D_flags)-1) {
|
||||
$out .= substr $D_flags, $i, 1 if $^D & (1<<$i);
|
||||
}
|
||||
my $arg = shift;
|
||||
my $num = $arg;
|
||||
if (defined $arg and $arg =~ /\D/) {
|
||||
die "unknown flags in debug_flags()" if $arg =~ /[^-$D_flags]/;
|
||||
my ($on,$off) = split /-/, "$arg-";
|
||||
$num = $^D;
|
||||
$num |= (1<<index($D_flags, $_)) for split //, $on;
|
||||
$num &= ~(1<<index($D_flags, $_)) for split //, $off;
|
||||
}
|
||||
$^D = $num if defined $arg;
|
||||
$out
|
||||
}
|
||||
|
||||
sub B::Deparse::pp_Devel_Peek_Dump {
|
||||
my ($deparse,$op,$cx) = @_;
|
||||
my @kids = $deparse->deparse($op->first, 6);
|
||||
my $sib = $op->first->sibling;
|
||||
if (ref $sib ne 'B::NULL') {
|
||||
push @kids, $deparse->deparse($sib, 6);
|
||||
}
|
||||
return "Devel::Peek::Dump(" . join(", ", @kids) . ")";
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Devel::Peek - A data debugging tool for the XS programmer
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Devel::Peek;
|
||||
Dump( $a );
|
||||
Dump( $a, 5 );
|
||||
Dump( @a );
|
||||
Dump( %h );
|
||||
DumpArray( 5, $a, $b, ... );
|
||||
mstat "Point 5";
|
||||
|
||||
use Devel::Peek ':opd=st';
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Devel::Peek contains functions which allows raw Perl datatypes to be
|
||||
manipulated from a Perl script. This is used by those who do XS programming
|
||||
to check that the data they are sending from C to Perl looks as they think
|
||||
it should look. The trick, then, is to know what the raw datatype is
|
||||
supposed to look like when it gets to Perl. This document offers some tips
|
||||
and hints to describe good and bad raw data.
|
||||
|
||||
It is very possible that this document will fall far short of being useful
|
||||
to the casual reader. The reader is expected to understand the material in
|
||||
the first few sections of L<perlguts>.
|
||||
|
||||
Devel::Peek supplies a C<Dump()> function which can dump a raw Perl
|
||||
datatype, and C<mstat("marker")> function to report on memory usage
|
||||
(if perl is compiled with corresponding option). The function
|
||||
DeadCode() provides statistics on the data "frozen" into inactive
|
||||
C<CV>. Devel::Peek also supplies C<SvREFCNT()> which can query reference
|
||||
counts on SVs. This document will take a passive, and safe, approach
|
||||
to data debugging and for that it will describe only the C<Dump()>
|
||||
function.
|
||||
|
||||
All output is to STDERR.
|
||||
|
||||
The C<Dump()> function takes one or two arguments: something to dump, and
|
||||
an optional limit for recursion and array elements (default is 4). The
|
||||
first argument is evaluted in rvalue scalar context, with exceptions for
|
||||
@array and %hash, which dump the array or hash itself. So C<Dump @array>
|
||||
works, as does C<Dump $foo>. And C<Dump pos> will call C<pos> in rvalue
|
||||
context, whereas C<Dump ${\pos}> will call it in lvalue context.
|
||||
|
||||
Function C<DumpArray()> allows dumping of multiple values (useful when you
|
||||
need to analyze returns of functions).
|
||||
|
||||
The global variable $Devel::Peek::pv_limit can be set to limit the
|
||||
number of character printed in various string values. Setting it to 0
|
||||
means no limit.
|
||||
|
||||
If C<use Devel::Peek> directive has a C<:opd=FLAGS> argument,
|
||||
this switches on debugging of opcode dispatch. C<FLAGS> should be a
|
||||
combination of C<s>, C<t>, and C<P> (see
|
||||
L<< B<-D> flags in perlrun|perlrun/B<-D>I<letters> >>).
|
||||
|
||||
C<:opd> is a shortcut for C<:opd=st>.
|
||||
|
||||
=head2 Runtime debugging
|
||||
|
||||
C<CvGV($cv)> return one of the globs associated to a subroutine reference $cv.
|
||||
|
||||
debug_flags() returns a string representation of C<$^D> (similar to
|
||||
what is allowed for B<-D> flag). When called with a numeric argument,
|
||||
sets $^D to the corresponding value. When called with an argument of
|
||||
the form C<"flags-flags">, set on/off bits of C<$^D> corresponding to
|
||||
letters before/after C<->. (The returned value is for C<$^D> before
|
||||
the modification.)
|
||||
|
||||
runops_debug() returns true if the current I<opcode dispatcher> is the
|
||||
debugging one. When called with an argument, switches to debugging or
|
||||
non-debugging dispatcher depending on the argument (active for
|
||||
newly-entered subs/etc only). (The returned value is for the dispatcher before the modification.)
|
||||
|
||||
=head2 Memory footprint debugging
|
||||
|
||||
When perl is compiled with support for memory footprint debugging
|
||||
(default with Perl's malloc()), Devel::Peek provides an access to this API.
|
||||
|
||||
Use mstat() function to emit a memory state statistic to the terminal.
|
||||
For more information on the format of output of mstat() see
|
||||
L<perldebguts/Using $ENV{PERL_DEBUG_MSTATS}>.
|
||||
|
||||
Three additional functions allow access to this statistic from Perl.
|
||||
First, use C<mstats_fillhash(%hash)> to get the information contained
|
||||
in the output of mstat() into %hash. The field of this hash are
|
||||
|
||||
minbucket nbuckets sbrk_good sbrk_slack sbrked_remains sbrks
|
||||
start_slack topbucket topbucket_ev topbucket_odd total total_chain
|
||||
total_sbrk totfree
|
||||
|
||||
Two additional fields C<free>, C<used> contain array references which
|
||||
provide per-bucket count of free and used chunks. Two other fields
|
||||
C<mem_size>, C<available_size> contain array references which provide
|
||||
the information about the allocated size and usable size of chunks in
|
||||
each bucket. Again, see L<perldebguts/Using $ENV{PERL_DEBUG_MSTATS}>
|
||||
for details.
|
||||
|
||||
|
||||
Keep in mind that only the first several "odd-numbered" buckets are
|
||||
used, so the information on size of the "odd-numbered" buckets which are
|
||||
not used is probably meaningless.
|
||||
|
||||
The information in
|
||||
|
||||
mem_size available_size minbucket nbuckets
|
||||
|
||||
is the property of a particular build of perl, and does not depend on
|
||||
the current process. If you do not provide the optional argument to
|
||||
the functions mstats_fillhash(), fill_mstats(), mstats2hash(), then
|
||||
the information in fields C<mem_size>, C<available_size> is not
|
||||
updated.
|
||||
|
||||
C<fill_mstats($buf)> is a much cheaper call (both speedwise and
|
||||
memory-wise) which collects the statistic into $buf in
|
||||
machine-readable form. At a later moment you may need to call
|
||||
C<mstats2hash($buf, %hash)> to use this information to fill %hash.
|
||||
|
||||
All three APIs C<fill_mstats($buf)>, C<mstats_fillhash(%hash)>, and
|
||||
C<mstats2hash($buf, %hash)> are designed to allocate no memory if used
|
||||
I<the second time> on the same $buf and/or %hash.
|
||||
|
||||
So, if you want to collect memory info in a cycle, you may call
|
||||
|
||||
$#buf = 999;
|
||||
fill_mstats($_) for @buf;
|
||||
mstats_fillhash(%report, 1); # Static info too
|
||||
|
||||
foreach (@buf) {
|
||||
# Do something...
|
||||
fill_mstats $_; # Collect statistic
|
||||
}
|
||||
foreach (@buf) {
|
||||
mstats2hash($_, %report); # Preserve static info
|
||||
# Do something with %report
|
||||
}
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
The following examples don't attempt to show everything as that would be a
|
||||
monumental task, and, frankly, we don't want this manpage to be an internals
|
||||
document for Perl. The examples do demonstrate some basics of the raw Perl
|
||||
datatypes, and should suffice to get most determined people on their way.
|
||||
There are no guidewires or safety nets, nor blazed trails, so be prepared to
|
||||
travel alone from this point and on and, if at all possible, don't fall into
|
||||
the quicksand (it's bad for business).
|
||||
|
||||
Oh, one final bit of advice: take L<perlguts> with you. When you return we
|
||||
expect to see it well-thumbed.
|
||||
|
||||
=head2 A simple scalar string
|
||||
|
||||
Let's begin by looking a simple scalar which is holding a string.
|
||||
|
||||
use Devel::Peek;
|
||||
$a = 42; $a = "hello";
|
||||
Dump $a;
|
||||
|
||||
The output:
|
||||
|
||||
SV = PVIV(0xbc288) at 0xbe9a8
|
||||
REFCNT = 1
|
||||
FLAGS = (POK,pPOK)
|
||||
IV = 42
|
||||
PV = 0xb2048 "hello"\0
|
||||
CUR = 5
|
||||
LEN = 8
|
||||
|
||||
This says C<$a> is an SV, a scalar. The scalar type is a PVIV, which is
|
||||
capable of holding an integer (IV) and/or a string (PV) value. The scalar's
|
||||
head is allocated at address 0xbe9a8, while the body is at 0xbc288.
|
||||
Its reference count is 1. It has the C<POK> flag set, meaning its
|
||||
current PV field is valid. Because POK is set we look at the PV item
|
||||
to see what is in the scalar. The \0 at the end indicate that this
|
||||
PV is properly NUL-terminated.
|
||||
Note that the IV field still contains its old numeric value, but because
|
||||
FLAGS doesn't have IOK set, we must ignore the IV item.
|
||||
CUR indicates the number of characters in the PV. LEN indicates the
|
||||
number of bytes allocated for the PV (at least one more than CUR, because
|
||||
LEN includes an extra byte for the end-of-string marker, then usually
|
||||
rounded up to some efficient allocation unit).
|
||||
|
||||
=head2 A simple scalar number
|
||||
|
||||
If the scalar contains a number the raw SV will be leaner.
|
||||
|
||||
use Devel::Peek;
|
||||
$a = 42;
|
||||
Dump $a;
|
||||
|
||||
The output:
|
||||
|
||||
SV = IV(0xbc818) at 0xbe9a8
|
||||
REFCNT = 1
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 42
|
||||
|
||||
This says C<$a> is an SV, a scalar. The scalar is an IV, a number. Its
|
||||
reference count is 1. It has the C<IOK> flag set, meaning it is currently
|
||||
being evaluated as a number. Because IOK is set we look at the IV item to
|
||||
see what is in the scalar.
|
||||
|
||||
=head2 A simple scalar with an extra reference
|
||||
|
||||
If the scalar from the previous example had an extra reference:
|
||||
|
||||
use Devel::Peek;
|
||||
$a = 42;
|
||||
$b = \$a;
|
||||
Dump $a;
|
||||
|
||||
The output:
|
||||
|
||||
SV = IV(0xbe860) at 0xbe9a8
|
||||
REFCNT = 2
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 42
|
||||
|
||||
Notice that this example differs from the previous example only in its
|
||||
reference count. Compare this to the next example, where we dump C<$b>
|
||||
instead of C<$a>.
|
||||
|
||||
=head2 A reference to a simple scalar
|
||||
|
||||
This shows what a reference looks like when it references a simple scalar.
|
||||
|
||||
use Devel::Peek;
|
||||
$a = 42;
|
||||
$b = \$a;
|
||||
Dump $b;
|
||||
|
||||
The output:
|
||||
|
||||
SV = IV(0xf041c) at 0xbe9a0
|
||||
REFCNT = 1
|
||||
FLAGS = (ROK)
|
||||
RV = 0xbab08
|
||||
SV = IV(0xbe860) at 0xbe9a8
|
||||
REFCNT = 2
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 42
|
||||
|
||||
Starting from the top, this says C<$b> is an SV. The scalar is an IV,
|
||||
which is capable of holding an integer or reference value.
|
||||
It has the C<ROK> flag set, meaning it is a reference (rather than an
|
||||
integer or string). Notice that Dump
|
||||
follows the reference and shows us what C<$b> was referencing. We see the
|
||||
same C<$a> that we found in the previous example.
|
||||
|
||||
Note that the value of C<RV> coincides with the numbers we see when we
|
||||
stringify $b. The addresses inside IV() are addresses of
|
||||
C<X***> structures which hold the current state of an C<SV>. This
|
||||
address may change during lifetime of an SV.
|
||||
|
||||
=head2 A reference to an array
|
||||
|
||||
This shows what a reference to an array looks like.
|
||||
|
||||
use Devel::Peek;
|
||||
$a = [42];
|
||||
Dump $a;
|
||||
|
||||
The output:
|
||||
|
||||
SV = IV(0xc85998) at 0xc859a8
|
||||
REFCNT = 1
|
||||
FLAGS = (ROK)
|
||||
RV = 0xc70de8
|
||||
SV = PVAV(0xc71e10) at 0xc70de8
|
||||
REFCNT = 1
|
||||
FLAGS = ()
|
||||
ARRAY = 0xc7e820
|
||||
FILL = 0
|
||||
MAX = 0
|
||||
FLAGS = (REAL)
|
||||
Elt No. 0
|
||||
SV = IV(0xc70f88) at 0xc70f98
|
||||
REFCNT = 1
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 42
|
||||
|
||||
This says C<$a> is a reference (ROK), which points to
|
||||
another SV which is a PVAV, an array. The array has one element,
|
||||
element zero, which is another SV. The field C<FILL> above indicates
|
||||
the last element in the array, similar to C<$#$a>.
|
||||
|
||||
If C<$a> pointed to an array of two elements then we would see the
|
||||
following.
|
||||
|
||||
use Devel::Peek 'Dump';
|
||||
$a = [42,24];
|
||||
Dump $a;
|
||||
|
||||
The output:
|
||||
|
||||
SV = IV(0x158c998) at 0x158c9a8
|
||||
REFCNT = 1
|
||||
FLAGS = (ROK)
|
||||
RV = 0x1577de8
|
||||
SV = PVAV(0x1578e10) at 0x1577de8
|
||||
REFCNT = 1
|
||||
FLAGS = ()
|
||||
ARRAY = 0x1585820
|
||||
FILL = 1
|
||||
MAX = 1
|
||||
FLAGS = (REAL)
|
||||
Elt No. 0
|
||||
SV = IV(0x1577f88) at 0x1577f98
|
||||
REFCNT = 1
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 42
|
||||
Elt No. 1
|
||||
SV = IV(0x158be88) at 0x158be98
|
||||
REFCNT = 1
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 24
|
||||
|
||||
Note that C<Dump> will not report I<all> the elements in the array,
|
||||
only several first (depending on how deep it already went into the
|
||||
report tree).
|
||||
|
||||
=head2 A reference to a hash
|
||||
|
||||
The following shows the raw form of a reference to a hash.
|
||||
|
||||
use Devel::Peek;
|
||||
$a = {hello=>42};
|
||||
Dump $a;
|
||||
|
||||
The output:
|
||||
|
||||
SV = IV(0x55cb50b50fb0) at 0x55cb50b50fc0
|
||||
REFCNT = 1
|
||||
FLAGS = (ROK)
|
||||
RV = 0x55cb50b2b758
|
||||
SV = PVHV(0x55cb50b319c0) at 0x55cb50b2b758
|
||||
REFCNT = 1
|
||||
FLAGS = (SHAREKEYS)
|
||||
ARRAY = 0x55cb50b941a0 (0:7, 1:1)
|
||||
hash quality = 100.0%
|
||||
KEYS = 1
|
||||
FILL = 1
|
||||
MAX = 7
|
||||
Elt "hello" HASH = 0x3128ece4
|
||||
SV = IV(0x55cb50b464f8) at 0x55cb50b46508
|
||||
REFCNT = 1
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 42
|
||||
|
||||
This shows C<$a> is a reference pointing to an SV. That SV is a PVHV, a hash.
|
||||
|
||||
The "quality" of a hash is defined as the total number of comparisons needed
|
||||
to access every element once, relative to the expected number needed for a
|
||||
random hash. The value can go over 100%.
|
||||
|
||||
The total number of comparisons is equal to the sum of the squares of the
|
||||
number of entries in each bucket. For a random hash of C<<n>> keys into
|
||||
C<<k>> buckets, the expected value is:
|
||||
|
||||
n + n(n-1)/2k
|
||||
|
||||
=head2 Dumping a large array or hash
|
||||
|
||||
The C<Dump()> function, by default, dumps up to 4 elements from a
|
||||
toplevel array or hash. This number can be increased by supplying a
|
||||
second argument to the function.
|
||||
|
||||
use Devel::Peek;
|
||||
$a = [10,11,12,13,14];
|
||||
Dump $a;
|
||||
|
||||
Notice that C<Dump()> prints only elements 10 through 13 in the above code.
|
||||
The following code will print all of the elements.
|
||||
|
||||
use Devel::Peek 'Dump';
|
||||
$a = [10,11,12,13,14];
|
||||
Dump $a, 5;
|
||||
|
||||
=head2 A reference to an SV which holds a C pointer
|
||||
|
||||
This is what you really need to know as an XS programmer, of course. When
|
||||
an XSUB returns a pointer to a C structure that pointer is stored in an SV
|
||||
and a reference to that SV is placed on the XSUB stack. So the output from
|
||||
an XSUB which uses something like the T_PTROBJ map might look something like
|
||||
this:
|
||||
|
||||
SV = IV(0xf381c) at 0xc859a8
|
||||
REFCNT = 1
|
||||
FLAGS = (ROK)
|
||||
RV = 0xb8ad8
|
||||
SV = PVMG(0xbb3c8) at 0xc859a0
|
||||
REFCNT = 1
|
||||
FLAGS = (OBJECT,IOK,pIOK)
|
||||
IV = 729160
|
||||
NV = 0
|
||||
PV = 0
|
||||
STASH = 0xc1d10 "CookBookB::Opaque"
|
||||
|
||||
This shows that we have an SV which is a reference, which points at another
|
||||
SV. In this case that second SV is a PVMG, a blessed scalar. Because it is
|
||||
blessed it has the C<OBJECT> flag set. Note that an SV which holds a C
|
||||
pointer also has the C<IOK> flag set. The C<STASH> is set to the package
|
||||
name which this SV was blessed into.
|
||||
|
||||
The output from an XSUB which uses something like the T_PTRREF map, which
|
||||
doesn't bless the object, might look something like this:
|
||||
|
||||
SV = IV(0xf381c) at 0xc859a8
|
||||
REFCNT = 1
|
||||
FLAGS = (ROK)
|
||||
RV = 0xb8ad8
|
||||
SV = PVMG(0xbb3c8) at 0xc859a0
|
||||
REFCNT = 1
|
||||
FLAGS = (IOK,pIOK)
|
||||
IV = 729160
|
||||
NV = 0
|
||||
PV = 0
|
||||
|
||||
=head2 A reference to a subroutine
|
||||
|
||||
Looks like this:
|
||||
|
||||
SV = IV(0x24d2dd8) at 0x24d2de8
|
||||
REFCNT = 1
|
||||
FLAGS = (TEMP,ROK)
|
||||
RV = 0x24e79d8
|
||||
SV = PVCV(0x24e5798) at 0x24e79d8
|
||||
REFCNT = 2
|
||||
FLAGS = ()
|
||||
COMP_STASH = 0x22c9c50 "main"
|
||||
START = 0x22eed60 ===> 0
|
||||
ROOT = 0x22ee490
|
||||
GVGV::GV = 0x22de9d8 "MY" :: "top_targets"
|
||||
FILE = "(eval 5)"
|
||||
DEPTH = 0
|
||||
FLAGS = 0x0
|
||||
OUTSIDE_SEQ = 93
|
||||
PADLIST = 0x22e9ed8
|
||||
PADNAME = 0x22e9ec0(0x22eed00) PAD = 0x22e9ea8(0x22eecd0)
|
||||
OUTSIDE = 0x22c9fb0 (MAIN)
|
||||
|
||||
|
||||
This shows that
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
the subroutine is not an XSUB (since C<START> and C<ROOT> are
|
||||
non-zero, and C<XSUB> is not listed, and is thus null);
|
||||
|
||||
=item *
|
||||
|
||||
that it was compiled in the package C<main>;
|
||||
|
||||
=item *
|
||||
|
||||
under the name C<MY::top_targets>;
|
||||
|
||||
=item *
|
||||
|
||||
inside a 5th eval in the program;
|
||||
|
||||
=item *
|
||||
|
||||
it is not currently executed (because C<DEPTH> is 0);
|
||||
|
||||
=item *
|
||||
|
||||
it has no prototype (C<PROTOTYPE> field is missing).
|
||||
|
||||
=back
|
||||
|
||||
=head1 EXPORTS
|
||||
|
||||
C<Dump>, C<mstat>, C<DeadCode>, C<DumpArray>, C<DumpWithOP> and
|
||||
C<DumpProg>, C<fill_mstats>, C<mstats_fillhash>, C<mstats2hash> by
|
||||
default. Additionally available C<SvREFCNT>, C<SvREFCNT_inc> and
|
||||
C<SvREFCNT_dec>.
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
Readers have been known to skip important parts of L<perlguts>, causing much
|
||||
frustration for all.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Ilya Zakharevich ilya@math.ohio-state.edu
|
||||
|
||||
Copyright (c) 1995-98 Ilya Zakharevich. All rights reserved.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the same terms as Perl itself.
|
||||
|
||||
Author of this software makes no claim whatsoever about suitability,
|
||||
reliability, edability, editability or usability of this product, and
|
||||
should not be kept liable for any damage resulting from the use of
|
||||
it. If you can use it, you are in luck, if not, I should not be kept
|
||||
responsible. Keep a handy copy of your backup tape at hand.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<perlguts>, and L<perlguts>, again.
|
||||
|
||||
=cut
|
||||
152
database/perl/lib/Devel/SelfStubber.pm
Normal file
152
database/perl/lib/Devel/SelfStubber.pm
Normal file
@@ -0,0 +1,152 @@
|
||||
package Devel::SelfStubber;
|
||||
use File::Spec;
|
||||
require SelfLoader;
|
||||
@ISA = qw(SelfLoader);
|
||||
@EXPORT = 'AUTOLOAD';
|
||||
$JUST_STUBS = 1;
|
||||
$VERSION = 1.06;
|
||||
sub Version {$VERSION}
|
||||
|
||||
# Use as
|
||||
# perl -e 'use Devel::SelfStubber;Devel::SelfStubber->stub(MODULE_NAME,LIB)'
|
||||
# (LIB defaults to '.') e.g.
|
||||
# perl -e 'use Devel::SelfStubber;Devel::SelfStubber->stub('Math::BigInt')'
|
||||
# would print out stubs needed if you added a __DATA__ before the subs.
|
||||
# Setting $Devel::SelfStubber::JUST_STUBS to 0 will print out the whole
|
||||
# module with the stubs entered just before the __DATA__
|
||||
|
||||
sub _add_to_cache {
|
||||
my($self,$fullname,$pack,$lines, $prototype) = @_;
|
||||
push(@DATA,@{$lines});
|
||||
if($fullname){push(@STUBS,"sub $fullname $prototype;\n")}; # stubs
|
||||
'1;';
|
||||
}
|
||||
|
||||
sub _package_defined {
|
||||
my($self,$line) = @_;
|
||||
push(@DATA,$line);
|
||||
}
|
||||
|
||||
sub stub {
|
||||
my($self,$module,$lib) = @_;
|
||||
my($line,$end_data,$fh,$mod_file,$found_selfloader);
|
||||
$lib ||= File::Spec->curdir();
|
||||
($mod_file = $module) =~ s,::,/,g;
|
||||
$mod_file =~ tr|/|:| if $^O eq 'MacOS';
|
||||
|
||||
$mod_file = File::Spec->catfile($lib, "$mod_file.pm");
|
||||
$fh = "${module}::DATA";
|
||||
my (@BEFORE_DATA, @AFTER_DATA, @AFTER_END);
|
||||
@DATA = @STUBS = ();
|
||||
|
||||
open($fh,'<',$mod_file) || die "Unable to open $mod_file";
|
||||
local $/ = "\n";
|
||||
while(defined ($line = <$fh>) and $line !~ m/^__DATA__/) {
|
||||
push(@BEFORE_DATA,$line);
|
||||
$line =~ /use\s+SelfLoader/ && $found_selfloader++;
|
||||
}
|
||||
(defined ($line) && $line =~ m/^__DATA__/)
|
||||
|| die "$mod_file doesn't contain a __DATA__ token";
|
||||
$found_selfloader ||
|
||||
print 'die "\'use SelfLoader;\' statement NOT FOUND!!\n"',"\n";
|
||||
if ($JUST_STUBS) {
|
||||
$self->_load_stubs($module);
|
||||
} else {
|
||||
$self->_load_stubs($module, \@AFTER_END);
|
||||
}
|
||||
if ( fileno($fh) ) {
|
||||
$end_data = 1;
|
||||
while(defined($line = <$fh>)) {
|
||||
push(@AFTER_DATA,$line);
|
||||
}
|
||||
}
|
||||
close($fh);
|
||||
unless ($JUST_STUBS) {
|
||||
print @BEFORE_DATA;
|
||||
}
|
||||
print @STUBS;
|
||||
unless ($JUST_STUBS) {
|
||||
print "1;\n__DATA__\n",@DATA;
|
||||
if($end_data) { print "__END__ DATA\n",@AFTER_DATA; }
|
||||
if(@AFTER_END) { print "__END__\n",@AFTER_END; }
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Devel::SelfStubber - generate stubs for a SelfLoading module
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
To generate just the stubs:
|
||||
|
||||
use Devel::SelfStubber;
|
||||
Devel::SelfStubber->stub('MODULENAME','MY_LIB_DIR');
|
||||
|
||||
or to generate the whole module with stubs inserted correctly
|
||||
|
||||
use Devel::SelfStubber;
|
||||
$Devel::SelfStubber::JUST_STUBS=0;
|
||||
Devel::SelfStubber->stub('MODULENAME','MY_LIB_DIR');
|
||||
|
||||
MODULENAME is the Perl module name, e.g. Devel::SelfStubber,
|
||||
NOT 'Devel/SelfStubber' or 'Devel/SelfStubber.pm'.
|
||||
|
||||
MY_LIB_DIR defaults to '.' if not present.
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Devel::SelfStubber prints the stubs you need to put in the module
|
||||
before the __DATA__ token (or you can get it to print the entire
|
||||
module with stubs correctly placed). The stubs ensure that if
|
||||
a method is called, it will get loaded. They are needed specifically
|
||||
for inherited autoloaded methods.
|
||||
|
||||
This is best explained using the following example:
|
||||
|
||||
Assume four classes, A,B,C & D.
|
||||
|
||||
A is the root class, B is a subclass of A, C is a subclass of B,
|
||||
and D is another subclass of A.
|
||||
|
||||
A
|
||||
/ \
|
||||
B D
|
||||
/
|
||||
C
|
||||
|
||||
If D calls an autoloaded method 'foo' which is defined in class A,
|
||||
then the method is loaded into class A, then executed. If C then
|
||||
calls method 'foo', and that method was reimplemented in class
|
||||
B, but set to be autoloaded, then the lookup mechanism never gets to
|
||||
the AUTOLOAD mechanism in B because it first finds the method
|
||||
already loaded in A, and so erroneously uses that. If the method
|
||||
foo had been stubbed in B, then the lookup mechanism would have
|
||||
found the stub, and correctly loaded and used the sub from B.
|
||||
|
||||
So, for classes and subclasses to have inheritance correctly
|
||||
work with autoloading, you need to ensure stubs are loaded.
|
||||
|
||||
The SelfLoader can load stubs automatically at module initialization
|
||||
with the statement 'SelfLoader-E<gt>load_stubs()';, but you may wish to
|
||||
avoid having the stub loading overhead associated with your
|
||||
initialization (though note that the SelfLoader::load_stubs method
|
||||
will be called sooner or later - at latest when the first sub
|
||||
is being autoloaded). In this case, you can put the sub stubs
|
||||
before the __DATA__ token. This can be done manually, but this
|
||||
module allows automatic generation of the stubs.
|
||||
|
||||
By default it just prints the stubs, but you can set the
|
||||
global $Devel::SelfStubber::JUST_STUBS to 0 and it will
|
||||
print out the entire module with the stubs positioned correctly.
|
||||
|
||||
At the very least, this is useful to see what the SelfLoader
|
||||
thinks are stubs - in order to ensure future versions of the
|
||||
SelfStubber remain in step with the SelfLoader, the
|
||||
SelfStubber actually uses the SelfLoader to determine which
|
||||
stubs are needed.
|
||||
|
||||
=cut
|
||||
500
database/perl/lib/Devel/Symdump.pm
Normal file
500
database/perl/lib/Devel/Symdump.pm
Normal file
@@ -0,0 +1,500 @@
|
||||
package Devel::Symdump;
|
||||
|
||||
use 5.003;
|
||||
use Carp ();
|
||||
use strict;
|
||||
use vars qw($Defaults $VERSION *ENTRY $MAX_RECURSION);
|
||||
|
||||
$VERSION = '2.18';
|
||||
$MAX_RECURSION = 97;
|
||||
|
||||
$Defaults = {
|
||||
'RECURS' => 0,
|
||||
'AUTOLOAD' => {
|
||||
'packages' => 1,
|
||||
'scalars' => 1,
|
||||
'arrays' => 1,
|
||||
'hashes' => 1,
|
||||
'functions' => 1,
|
||||
'ios' => 1,
|
||||
'unknowns' => 1,
|
||||
},
|
||||
'SEEN' => {},
|
||||
};
|
||||
|
||||
sub rnew {
|
||||
my($class,@packages) = @_;
|
||||
no strict "refs";
|
||||
my $self = bless {%${"$class\::Defaults"}}, $class;
|
||||
$self->{RECURS}++;
|
||||
$self->_doit(@packages);
|
||||
}
|
||||
|
||||
sub new {
|
||||
my($class,@packages) = @_;
|
||||
no strict "refs";
|
||||
my $self = bless {%${"$class\::Defaults"}}, $class;
|
||||
$self->_doit(@packages);
|
||||
}
|
||||
|
||||
sub _doit {
|
||||
my($self,@packages) = @_;
|
||||
@packages = ("main") unless @packages;
|
||||
$self->{RESULT} = $self->_symdump(@packages);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub _symdump {
|
||||
my($self,@packages) = @_ ;
|
||||
my($key,$val,$num,$pack,@todo,$tmp);
|
||||
my $result = {};
|
||||
foreach $pack (@packages){
|
||||
no strict;
|
||||
while (($key,$val) = each(%{*{"$pack\::"}})) {
|
||||
my $gotone = 0;
|
||||
local(*ENTRY) = $val;
|
||||
#### SCALAR ####
|
||||
if (defined $val && defined *ENTRY{SCALAR}) {
|
||||
$result->{$pack}{SCALARS}{$key}++;
|
||||
$gotone++;
|
||||
}
|
||||
#### ARRAY ####
|
||||
if (defined $val && defined *ENTRY{ARRAY}) {
|
||||
$result->{$pack}{ARRAYS}{$key}++;
|
||||
$gotone++;
|
||||
}
|
||||
#### HASH ####
|
||||
if (defined $val && defined *ENTRY{HASH} && $key !~ /::/) {
|
||||
$result->{$pack}{HASHES}{$key}++;
|
||||
$gotone++;
|
||||
}
|
||||
#### PACKAGE ####
|
||||
if (defined $val && defined *ENTRY{HASH} && $key =~ /::$/ &&
|
||||
$key ne "main::" && $key ne "<none>::") {
|
||||
my($p) = $pack ne "main" ? "$pack\::" : "";
|
||||
($p .= $key) =~ s/::$//;
|
||||
$result->{$pack}{PACKAGES}{$p}++;
|
||||
$gotone++;
|
||||
if (++$self->{SEEN}{*$val} > $Devel::Symdump::MAX_RECURSION){
|
||||
next;
|
||||
}
|
||||
push @todo, $p;
|
||||
}
|
||||
#### FUNCTION ####
|
||||
if (defined $val && defined *ENTRY{CODE}) {
|
||||
$result->{$pack}{FUNCTIONS}{$key}++;
|
||||
$gotone++;
|
||||
}
|
||||
|
||||
#### IO #### had to change after 5.003_10
|
||||
if ($] > 5.003_10){
|
||||
if (defined $val && defined *ENTRY{IO}){ # fileno and telldir...
|
||||
$result->{$pack}{IOS}{$key}++;
|
||||
$gotone++;
|
||||
}
|
||||
} else {
|
||||
#### FILEHANDLE ####
|
||||
if (defined fileno(ENTRY)){
|
||||
$result->{$pack}{IOS}{$key}++;
|
||||
$gotone++;
|
||||
} elsif (defined telldir(ENTRY)){
|
||||
#### DIRHANDLE ####
|
||||
$result->{$pack}{IOS}{$key}++;
|
||||
$gotone++;
|
||||
}
|
||||
}
|
||||
|
||||
#### SOMETHING ELSE ####
|
||||
unless ($gotone) {
|
||||
$result->{$pack}{UNKNOWNS}{$key}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (@todo && $self->{RECURS})
|
||||
? { %$result, %{$self->_symdump(@todo)} }
|
||||
: $result;
|
||||
}
|
||||
|
||||
sub _partdump {
|
||||
my($self,$part)=@_;
|
||||
my ($pack, @result);
|
||||
my $prepend = "";
|
||||
foreach $pack (keys %{$self->{RESULT}}){
|
||||
$prepend = "$pack\::" unless $part eq 'PACKAGES';
|
||||
push @result, map {"$prepend$_"} keys %{$self->{RESULT}{$pack}{$part} || {}};
|
||||
}
|
||||
return @result;
|
||||
}
|
||||
|
||||
# this is needed so we don't try to AUTOLOAD the DESTROY method
|
||||
sub DESTROY {}
|
||||
|
||||
sub as_string {
|
||||
my $self = shift;
|
||||
my($type,@m);
|
||||
for $type (sort keys %{$self->{'AUTOLOAD'}}) {
|
||||
push @m, $type;
|
||||
push @m, "\t" . join "\n\t", map {
|
||||
s/([\000-\037\177])/ '^' . pack('c', ord($1) ^ 64) /eg;
|
||||
$_;
|
||||
} sort $self->_partdump(uc $type);
|
||||
}
|
||||
return join "\n", @m;
|
||||
}
|
||||
|
||||
sub as_HTML {
|
||||
my $self = shift;
|
||||
my($type,@m);
|
||||
push @m, "<TABLE>";
|
||||
for $type (sort keys %{$self->{'AUTOLOAD'}}) {
|
||||
push @m, "<TR><TD valign=top><B>$type</B></TD>";
|
||||
push @m, "<TD>" . join ", ", map {
|
||||
s/([\000-\037\177])/ '^' .
|
||||
pack('c', ord($1) ^ 64)
|
||||
/eg; $_;
|
||||
} sort $self->_partdump(uc $type);
|
||||
push @m, "</TD></TR>";
|
||||
}
|
||||
push @m, "</TABLE>";
|
||||
return join "\n", @m;
|
||||
}
|
||||
|
||||
sub diff {
|
||||
my($self,$second) = @_;
|
||||
my($type,@m);
|
||||
for $type (sort keys %{$self->{'AUTOLOAD'}}) {
|
||||
my(%first,%second,%all,$symbol);
|
||||
foreach $symbol ($self->_partdump(uc $type)){
|
||||
$first{$symbol}++;
|
||||
$all{$symbol}++;
|
||||
}
|
||||
foreach $symbol ($second->_partdump(uc $type)){
|
||||
$second{$symbol}++;
|
||||
$all{$symbol}++;
|
||||
}
|
||||
my(@typediff);
|
||||
foreach $symbol (sort keys %all){
|
||||
next if $first{$symbol} && $second{$symbol};
|
||||
push @typediff, "- $symbol" unless $second{$symbol};
|
||||
push @typediff, "+ $symbol" unless $first{$symbol};
|
||||
}
|
||||
foreach (@typediff) {
|
||||
s/([\000-\037\177])/ '^' . pack('c', ord($1) ^ 64) /eg;
|
||||
}
|
||||
push @m, $type, @typediff if @typediff;
|
||||
}
|
||||
return join "\n", @m;
|
||||
}
|
||||
|
||||
sub inh_tree {
|
||||
my($self) = @_;
|
||||
return $self->{INHTREE} if ref $self && defined $self->{INHTREE};
|
||||
my($inherited_by) = {};
|
||||
my($m)="";
|
||||
my(@isa) = grep /\bISA$/, Devel::Symdump->rnew->arrays;
|
||||
my $isa;
|
||||
foreach $isa (sort @isa) {
|
||||
$isa =~ s/::ISA$//;
|
||||
my($isaisa);
|
||||
no strict 'refs';
|
||||
foreach $isaisa (@{"$isa\::ISA"}){
|
||||
$inherited_by->{$isaisa}{$isa}++;
|
||||
}
|
||||
}
|
||||
my $item;
|
||||
foreach $item (sort keys %$inherited_by) {
|
||||
$m .= "$item\n";
|
||||
$m .= _inh_tree($item,$inherited_by);
|
||||
}
|
||||
$self->{INHTREE} = $m if ref $self;
|
||||
$m;
|
||||
}
|
||||
|
||||
sub _inh_tree {
|
||||
my($package,$href,$depth) = @_;
|
||||
return unless defined $href;
|
||||
$depth ||= 0;
|
||||
$depth++;
|
||||
if ($depth > 100){
|
||||
warn "Deep recursion in ISA\n";
|
||||
return;
|
||||
}
|
||||
my($m) = "";
|
||||
# print "DEBUG: package[$package]depth[$depth]\n";
|
||||
my $i;
|
||||
foreach $i (sort keys %{$href->{$package}}) {
|
||||
$m .= qq{\t} x $depth;
|
||||
$m .= qq{$i\n};
|
||||
$m .= _inh_tree($i,$href,$depth);
|
||||
}
|
||||
$m;
|
||||
}
|
||||
|
||||
sub isa_tree{
|
||||
my($self) = @_;
|
||||
return $self->{ISATREE} if ref $self && defined $self->{ISATREE};
|
||||
my(@isa) = grep /\bISA$/, Devel::Symdump->rnew->arrays;
|
||||
my($m) = "";
|
||||
my($isa);
|
||||
foreach $isa (sort @isa) {
|
||||
$isa =~ s/::ISA$//;
|
||||
$m .= qq{$isa\n};
|
||||
$m .= _isa_tree($isa)
|
||||
}
|
||||
$self->{ISATREE} = $m if ref $self;
|
||||
$m;
|
||||
}
|
||||
|
||||
sub _isa_tree{
|
||||
my($package,$depth) = @_;
|
||||
$depth ||= 0;
|
||||
$depth++;
|
||||
if ($depth > 100){
|
||||
warn "Deep recursion in ISA\n";
|
||||
return;
|
||||
}
|
||||
my($m) = "";
|
||||
# print "DEBUG: package[$package]depth[$depth]\n";
|
||||
my $isaisa;
|
||||
no strict 'refs';
|
||||
foreach $isaisa (@{"$package\::ISA"}) {
|
||||
$m .= qq{\t} x $depth;
|
||||
$m .= qq{$isaisa\n};
|
||||
$m .= _isa_tree($isaisa,$depth);
|
||||
}
|
||||
$m;
|
||||
}
|
||||
|
||||
AUTOLOAD {
|
||||
my($self,@packages) = @_;
|
||||
unless (ref $self) {
|
||||
$self = $self->new(@packages);
|
||||
}
|
||||
no strict "vars";
|
||||
(my $auto = $AUTOLOAD) =~ s/.*:://;
|
||||
|
||||
$auto =~ s/(file|dir)handles/ios/;
|
||||
my $compat = $1;
|
||||
|
||||
unless ($self->{'AUTOLOAD'}{$auto}) {
|
||||
Carp::croak("invalid Devel::Symdump method: $auto()");
|
||||
}
|
||||
|
||||
my @syms = $self->_partdump(uc $auto);
|
||||
if (defined $compat) {
|
||||
no strict 'refs';
|
||||
local $^W; # bleadperl@26631 introduced an io warning here
|
||||
if ($compat eq "file") {
|
||||
@syms = grep { defined(fileno($_)) } @syms;
|
||||
} else {
|
||||
@syms = grep { _is_dirhandle($_) } @syms;
|
||||
}
|
||||
}
|
||||
return @syms; # make sure now it gets context right
|
||||
}
|
||||
|
||||
use Config ();
|
||||
use constant HAVE_TELLDIR => $Config::Config{d_telldir};
|
||||
sub _is_dirhandle {
|
||||
my ($glob) = @_;
|
||||
if ( HAVE_TELLDIR ) {
|
||||
return defined(telldir($glob));
|
||||
}
|
||||
else {
|
||||
if ( !ref $glob ) {
|
||||
no strict 'refs';
|
||||
$glob = \*{$glob};
|
||||
}
|
||||
require B;
|
||||
my $obj = B::svref_2object($glob);
|
||||
return if !$obj || !eval{ $obj->IO; $obj->IO->IoTYPE; 1 };
|
||||
my $mode = $obj->IO->IoTYPE;
|
||||
return $mode eq "\0" ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Devel::Symdump - dump symbol names or the symbol table
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
# Constructor
|
||||
require Devel::Symdump;
|
||||
@packs = qw(some_package another_package);
|
||||
$obj = Devel::Symdump->new(@packs); # no recursion
|
||||
$obj = Devel::Symdump->rnew(@packs); # with recursion
|
||||
|
||||
# Methods
|
||||
@array = $obj->packages;
|
||||
@array = $obj->scalars;
|
||||
@array = $obj->arrays;
|
||||
@array = $obj->hashes;
|
||||
@array = $obj->functions;
|
||||
@array = $obj->filehandles; # deprecated, use ios instead
|
||||
@array = $obj->dirhandles; # deprecated, use ios instead
|
||||
@array = $obj->ios;
|
||||
@array = $obj->unknowns; # only perl version < 5.003 had some
|
||||
|
||||
$string = $obj->as_string;
|
||||
$string = $obj->as_HTML;
|
||||
$string = $obj1->diff($obj2);
|
||||
|
||||
$string = Devel::Symdump->isa_tree; # or $obj->isa_tree
|
||||
$string = Devel::Symdump->inh_tree; # or $obj->inh_tree
|
||||
|
||||
# Methods with autogenerated objects
|
||||
# all of those call new(@packs) internally
|
||||
@array = Devel::Symdump->packages(@packs);
|
||||
@array = Devel::Symdump->scalars(@packs);
|
||||
@array = Devel::Symdump->arrays(@packs);
|
||||
@array = Devel::Symdump->hashes(@packs);
|
||||
@array = Devel::Symdump->functions(@packs);
|
||||
@array = Devel::Symdump->ios(@packs);
|
||||
@array = Devel::Symdump->unknowns(@packs);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This little package serves to access the symbol table of perl.
|
||||
|
||||
=over 4
|
||||
|
||||
=item C<Devel::Symdump-E<gt>rnew(@packages)>
|
||||
|
||||
returns a symbol table object for all subtrees below @packages.
|
||||
Nested Modules are analyzed recursively. If no package is given as
|
||||
argument, it defaults to C<main>. That means to get the whole symbol
|
||||
table, just do a C<rnew> without arguments.
|
||||
|
||||
The global variable $Devel::Symdump::MAX_RECURSION limits the
|
||||
recursion to prevent contention. The default value is set to 97, just
|
||||
low enough to survive the test suite without a warning about deep
|
||||
recursion.
|
||||
|
||||
=item C<Devel::Symdump-E<gt>new(@packages)>
|
||||
|
||||
does not go into recursion and only analyzes the packages that are
|
||||
given as arguments.
|
||||
|
||||
=item packages, scalars, arrays, hashes, functions, ios
|
||||
|
||||
The methods packages(), scalars(), arrays(), hashes(), functions(),
|
||||
ios(), and (for older perls) unknowns() each return an array of fully
|
||||
qualified symbols of the specified type in all packages that are held
|
||||
within a Devel::Symdump object, but without the leading C<$>, C<@> or
|
||||
C<%>. In a scalar context, they will return the number of such
|
||||
symbols. Unknown symbols are usually either formats or variables that
|
||||
haven't yet got a defined value.
|
||||
|
||||
Note that scalar symbol table entries are a special case. If a symbol
|
||||
table entry exists at all, presence of a scalar is currently
|
||||
unknowable, due to a feature of Perl described in L<perlref/Making
|
||||
References> point 7. For example, this package will mark a scalar
|
||||
value C<$foo> as present if any of C<@foo>, C<%foo>, C<&foo> etc. have
|
||||
been declared or used.
|
||||
|
||||
=item as_string
|
||||
|
||||
=item as_HTML
|
||||
|
||||
As_string() and as_HTML() return a simple string/HTML representations
|
||||
of the object.
|
||||
|
||||
=item diff
|
||||
|
||||
Diff() prints the difference between two Devel::Symdump objects in
|
||||
human readable form. The format is similar to the one used by the
|
||||
as_string method.
|
||||
|
||||
=item isa_tree
|
||||
|
||||
=item inh_tree
|
||||
|
||||
Isa_tree() and inh_tree() both return a simple string representation
|
||||
of the current inheritance tree. The difference between the two
|
||||
methods is the direction from which the tree is viewed: top-down or
|
||||
bottom-up. As I'm sure, many users will have different expectation
|
||||
about what is top and what is bottom, I'll provide an example what
|
||||
happens when the Socket module is loaded:
|
||||
|
||||
=item % print Devel::Symdump-E<gt>inh_tree
|
||||
|
||||
AutoLoader
|
||||
DynaLoader
|
||||
Socket
|
||||
DynaLoader
|
||||
Socket
|
||||
Exporter
|
||||
Carp
|
||||
Config
|
||||
Socket
|
||||
|
||||
The inh_tree method shows on the left hand side a package name and
|
||||
indented to the right the packages that use the former.
|
||||
|
||||
=item % print Devel::Symdump-E<gt>isa_tree
|
||||
|
||||
Carp
|
||||
Exporter
|
||||
Config
|
||||
Exporter
|
||||
DynaLoader
|
||||
AutoLoader
|
||||
Socket
|
||||
Exporter
|
||||
DynaLoader
|
||||
AutoLoader
|
||||
|
||||
The isa_tree method displays from left to right ISA relationships, so
|
||||
Socket IS A DynaLoader and DynaLoader IS A AutoLoader. (Actually, they
|
||||
were at the time this manpage was written)
|
||||
|
||||
=back
|
||||
|
||||
You may call both methods, isa_tree() and inh_tree(), with an
|
||||
object. If you do that, the object will store the output and retrieve
|
||||
it when you call the same method again later. The typical usage would
|
||||
be to use them as class methods directly though.
|
||||
|
||||
=head1 SUBCLASSING
|
||||
|
||||
The design of this package is intentionally primitive and allows it to
|
||||
be subclassed easily. An example of a (maybe) useful subclass is
|
||||
Devel::Symdump::Export, a package which exports all methods of the
|
||||
Devel::Symdump package and turns them into functions.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
Routines for manipulating stashes: C<Package::Stash>; to work with
|
||||
lexicals: C<PadWalker>.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
Andreas Koenig F<< <andk@cpan.org> >> and Tom Christiansen
|
||||
F<< <tchrist@perl.com> >>. Based on the old F<dumpvar.pl> by Larry
|
||||
Wall.
|
||||
|
||||
=head1 COPYRIGHT, LICENSE
|
||||
|
||||
This module is
|
||||
|
||||
Copyright (c) 1995, 1997, 2000, 2002, 2005, 2006 Andreas Koenig C<< <andk@cpan.org> >>.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
This library is free software;
|
||||
you may use, redistribute and/or modify it under the same
|
||||
terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
# Local Variables:
|
||||
# mode: cperl
|
||||
# cperl-indent-level: 4
|
||||
# End:
|
||||
39
database/perl/lib/Devel/Symdump/Export.pm
Normal file
39
database/perl/lib/Devel/Symdump/Export.pm
Normal file
@@ -0,0 +1,39 @@
|
||||
package Devel::Symdump::Export;
|
||||
require Devel::Symdump;
|
||||
require Exporter;
|
||||
use Carp;
|
||||
use strict;
|
||||
use vars qw(@ISA @EXPORT_OK $AUTOLOAD);
|
||||
@ISA=('Exporter');
|
||||
|
||||
@EXPORT_OK=(
|
||||
'packages' ,
|
||||
'scalars' ,
|
||||
'arrays' ,
|
||||
'hashes' ,
|
||||
'functions' ,
|
||||
'filehandles' ,
|
||||
'dirhandles' ,
|
||||
'ios' ,
|
||||
'unknowns' ,
|
||||
);
|
||||
my %OK;
|
||||
@OK{@EXPORT_OK}=(1) x @EXPORT_OK;
|
||||
|
||||
push @EXPORT_OK, "symdump";
|
||||
|
||||
# undocumented feature symdump() -- does it save enough typing?
|
||||
sub symdump {
|
||||
my @packages = @_;
|
||||
Devel::Symdump->new(@packages)->as_string;
|
||||
}
|
||||
|
||||
AUTOLOAD {
|
||||
my @packages = @_;
|
||||
(my $auto = $AUTOLOAD) =~ s/.*:://;
|
||||
confess("Unknown function call $auto") unless $OK{$auto};
|
||||
my @ret = Devel::Symdump->new->$auto(@packages);
|
||||
return @ret;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user