B-DeparseTree

 view release on metacpan or  search on metacpan

lib/B/DeparseTree.pod  view on Meta::CPAN

=pod

=for comment
This file located in the distribution. But it is also found in a Github wiki:
https://github.com/rocky/p5-B-DeparseTree/wiki/DeparseTree.pod
where we can immediately see the results and others can contribute.

=begin html

<a href="https://travis-ci.org/rocky/p5-B-DeparseTree"><img src="https://travis-ci.org/rocky/p5-B-DeparseTree.png"></a>

=end html

=head1 Name

B::DeparseTree

=head2 Synopsis

    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: 0x23065a0, parent: 0x23d9720
         op: negate
         text: -$a

    return $a < 0 ? -$a : $a
                    ---
    0: ==================================================
    1: ==================================================
    Child info:
         addr: 0x23065f0, parent: 0x23065a0
         op: gvsv
         text: $a

    return $a < 0 ? -$a : $a
                     --
    1: ==================================================
    2: ==================================================
    Child info:
         addr: 0x2306630, parent: 0x23065a0
         op: gvsv
         text: $a



( run in 0.859 second using v1.01-cache-2.11-cpan-788537b7465 )