Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
HACK #78 Introspect Your Subroutines As each node returned should be a gvsv op (blessed into B::XPath::SVOP ), the NAME( ) method retrieves the name of the glob. The find_nextstate( ) method finds the nearest parent control op (or COP) which contains the name of the file and the line number on which the variable appeared. * The results are: $ perl friendly_animals.pl Global frog found at friendly_animals.pl:8 Global frog found at friendly_animals.pl:9 Hacking the Hack If you want to find only globals named $toad , change the XPath expression and parameterize it by a node attribute: $node->match( '//gvsv[@NAME="toad"]' )) There's no limit to the types of opcodes you can search for in a program beyond what B::XPath supports and the XPath expressions you can write. As long as you can dump a snippet of code into an optree list, you can eventu- ally turn that into an XPath expression. From there, just grab the node infor- mation you need and you're on your way.