NAME
Python::Bytecode - Disassemble and investigate Python bytecode
SYNOPSIS
use Python::Bytecode
my $bytecode = Python::Bytecode->new($bytecode);
my $bytecode = Python::Bytecode->new(FH);
for ($bytecode->disassemble) {
print $_->[0],"\n"; # Textual representation of disassembly
}
DESCRIPTION
Python::Bytecode
accepts a string or filehandle contain Python bytecode and puts it into a format you can manipulate.
METHODS
disassemble
-
This is the basic method for getting at the actual code. It returns an array representing the individual operations in the bytecode stream. Each element is a reference to a three-element array containing a textual representation of the disassembly, the opcode number, (the
opname()
function can be used to turn this into an op name) and the argument to the op, if any. constants
-
This returns an array reflecting the constants table of the bytecode. Some operations such as
LOAD_CONST
refer to constants by index in this array. labels
-
Similar to
constants
, some operations branch to labels by index in this table. varnames
-
Again, when variables are referred to by name, the names are stored as an index into this table.
filename
-
The filename from which this compiled bytecode is derived.
There are other methods, but you can read the code to find them. It's not hard, and besides, it's probably easiest to work off the textual representation of the disassembly anyway.
PERPETRATOR
Simon Cozens, simon@cpan.org
LICENSE
This code is licensed under the same terms as Perl itself.