B-DeparseTree
view release on metacpan or search on metacpan
[](https://travis-ci.org/rocky/p5-B-DeparseTree)
Synopsis
--------
Perl's B::Deparse but we save abstract tree information and associate
that with Perl text fragments. These are fragments accessible by OP
address. With this, you can determine get exactly where you inside Perl in
a program with granularity finer that at a line number boundary.
Uses for this could be in stack trace routines like _Carp_. It is used
in the [deparse](https://metacpan.org/pod/Devel::Trepan::Deparse)
command extension to
[Devel::Trepan](https://metacpan.org/pod/Devel::Trepan).
Example
-------
use B::DeparseTree;
my $deparse = B::DeparseTree->new();
# create a subroutine to deparse...
sub my_abs($) {
return $a < 0 ? -$a : $a;
};
my $deparse_tree = B::DeparseTree->new();
my $tree_node = $deparse_tree->coderef2info(\&my_abs);
print $tree_node->{text};
The above produces:
($)
{
return $a < 0 ? -$a : $a
}
but the result are reconstructed purely from the OPnode tree. To show
parent-child information in the tree:
use B::DeparseTree::Fragment;
B::DeparseTree::Fragment::dump_relations($deparse_tree);
which produces:
0: ==================================================
Child info:
addr: 0xe87280, parent: 0x16684c0
op: pushmark
text: return $a < 0 ? -$a : $a
($)...
return $a < 0 ? -$a : $a
~~~~~~
0: ==================================================
1: ==================================================
Child info:
addr: 0xe8b550, parent: 0xe9cba0
op: gvsv
text: $a
( run in 0.641 second using v1.01-cache-2.11-cpan-788537b7465 )