The Bytecode Generator
The B::Bytecode module writes the parse tree’s opcodes out in a
platform-independent encoding. You can take a Perl script compiled down
to bytecodes and copy that to any other machine with Perl installed on
it.
The currently experimental perlcc(1) command
from the CPAN B::C distribution knows
how to convert Perl source code into a byte-compiled Perl program. All
you have to do is:
% perlcc –B –o pbyscript srcscriptAnd now you should be able to directly “execute” the resulting pbyscript. The start of that file looks somewhat like this:
#!/usr/bin/perl use ByteLoader 0.03; ^C^@^E^A^C^@^@^@^A^F^@^C^@^@^@^B^F^@^C^@^@^@^C^F^@^C^@^@^@ B^@^@^@^H9^A8M–^?M–^?M–^?M–^?7M–^?M–^?M–^?M–^?6^@^@^@^A6^@ ^G^D^D^@^@^@^KR^@^@^@^HS^@^@^@^HV^@M–2<W^FU^@^@^@^@X^Y@Z^@ ...
There you find a small script header followed by purely binary
data. This may seem like deep magic, but its dweomer, er, dwimmer is at
most a minor one. The ByteLoader module uses a technique called a source filter to alter the source
code before Perl gets a chance to see it. A source filter is a kind of
preprocessor that applies to everything below it in the current file.
Instead of being limited to simplistic transformations the way macro
processors like cpp(1) and
m4(1) are, here there are no constraints. Source
filters have been used to augment Perl’s syntax, to compress or encrypt
source code, even to write Perl programs in Latin. E perlibus unicode;
cogito, ergo substr; carp dbm, et al. Er, caveat scriptor.
The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access