Now Loading...

Dapatkan info terbaru via Facebook. Silahkan klik LIKE / SUKA.

?

Tuesday, May 29, 2012

B::LexInfo 0.02


B::LexInfo B::LexInfo is a Perl module that shows information about subroutine lexical variables.

B::LexInfo is a Perl module that shows information about subroutine lexical variables.

SYNOPSIS

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.

METHODSM

new

Create a new B::LexInfo object:

my $lexi = B::LexInfo->new;

cvlexinfo

Create a padlist snapshot from a single subroutine:

my $info = $lexi->cvlexinfo('Foo::bar');

stash_cvlexinfo

Create a list of padlist snapshots for each subroutine in the given package:

my $info = $lexi->stash_cvlexinfo('Foo');

dumper

Return a reference to a stringified padlist snapshot:

print ${ $lexi->dumper($info) }

diff

Compare two padlist snapshots and return the difference:

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.

cvrundiff

Take a padlist snapshot of a subroutine, run the subroutine with the given arguments, take another snapshot and return a diff of the snapshots.

my $diff = $lexi->cvrundiff('Foo::bar', "arg1", $arg2);
print $$diff;

Complete example:

package Foo;
use B::LexInfo ();

sub bar {
my($string) = a_;
}

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
aa -2,8 +2,10 aa
{
'Foo::bar' => {
'$string' => {
- 'TYPE' => 'NULL',
- 'NULL' => '0x80efd58'
+ 'TYPE' => 'PV',
+ 'LEN' => 9,
+ 'PV' => 'a string',
+ 'CUR' => 8
},
'__SPECIAL__1' => {
'TYPE' => 'NULL',

Requirements:

· Perl



Product's homepage

Requirements:



· Perl


Download B::LexInfo 0.02 Free
Tags: lexical variables   , variables information   , Perl module   , B::LexInfo   , subroutine   , lexical   ,
padlist, subroutine, snapshots, print, snapshot, = , $lexi =, padlist snapshot, 'type' =, information, 'type', blexinfo, $diff, lexical, variable, $lexi, given, jun 28 194841, number, $info, string, assigned, package, value, $lexi-cvrundiff'foobar'

No comments:

Post a Comment