|
B::LexInfo - Show information about subroutine lexical variables |
B::LexInfo - Show information about subroutine lexical variables
use B::ShowLex (); my $lexi = B::ShowLex->new;
Perl stores lexical variable names and values inside a padlist within the subroutine. Certain lexicals will maintain certain attributes after the the variable ``goes out of scope''. For example, when a scalar is assigned a string value, this value remains after the variable has gone out of scope, but is overridden the next time it is assigned to. Lexical Arrays and Hashes will retain their storage space for the maximum number of entries stored at any given point in time.
This module provides methods to record this information, which can be dumped out as-is or to compare two ``snapshots''. The information learned from these snapshots can be valuable in a number of ways.
my $lexi = B::LexInfo->new;
my $info = $lexi->cvlexinfo('Foo::bar');
my $info = $lexi->stash_cvlexinfo('Foo');
print ${ $lexi->dumper($info) }
my $before = $lexi->stash_cvlexinfo(__PACKAGE__); ... let some code run my $after = $lexi->stash_cvlexinfo(__PACKAGE__);
my $diff = B::LexInfo->diff($before, $after); print $$diff;
NOTE: This function relies on the diff -u command. You might need to configure $B::LexInfo::TmpDir and/or $B::LexInfo::DiffCmd to values other than the defaults in LexInfo.pm.
my $diff = $lexi->cvrundiff('Foo::bar', "arg1", $arg2);
print $$diff;
Complete example:
package Foo; use B::LexInfo ();
sub bar {
my($string) = @_;
}
my $lexi = B::LexInfo->new;
my $diff = $lexi->cvrundiff('Foo::bar', "a string");
print $$diff;
Produces:
--- /tmp/B_LexInfo_1848.before Mon Jun 28 19:48:41 1999
+++ /tmp/B_LexInfo_1848.after Mon Jun 28 19:48:41 1999
@@ -2,8 +2,10 @@
{
'Foo::bar' => {
'$string' => {
- 'TYPE' => 'NULL',
- 'NULL' => '0x80efd58'
+ 'TYPE' => 'PV',
+ 'LEN' => 9,
+ 'PV' => 'a string',
+ 'CUR' => 8
},
'__SPECIAL__1' => {
'TYPE' => 'NULL',
Snapshots are built using Perl structures and stringified using Data::Dumper. Hash key order is sorted and preserved if you you the Tie::IxHash module installed. Entry names are that of the variable itself or __SPECIAL__$n for entries that are used by Perl internally. The key/value pairs for each entry depends on the variable type and state. Docs on that to come, in the meantime, study: http://gisle.aas.no/perl/illguts/
B(3), Apache::RegistryLexInfo(3), Devel::Peek(3)
Doug MacEachern
|
B::LexInfo - Show information about subroutine lexical variables |