O(3perl)
π O β the generic interface to Perl Compiler backends π
bestie. sit down. we're talking about O, and it's a section 3perl situation, so it's a Perl module, and it's genuinely iconic. no cap.
β¨ SYNOPSIS β¨
perl -MO=[-q,]Backend[,OPTIONS] foo.pl
that's it. that's the whole summoning ritual. π―οΈ
π«Ά DESCRIPTION π«Ά
okay so this is the module that gets used as a frontend to the Perl Compiler. that's its whole job. it's the door greeter. it's the bouncer. it's giving main character energy at the entrance of compilation. π
if you pass the -q option to the module, then the STDOUT filehandle gets redirected into the variable $O::BEGIN_output during compilation. the effect of this is that any output printed to STDOUT by BEGIN blocks or use'd modules will be stored in that variable rather than printed. lowkey this is so useful with those backends that produce output themselves β Deparse, Concise etc β because then their output does not get confused with the output generated by the code being compiled. it's a whole vibe-separation thing. β¨
the -qq option behaves like -q, except that it also closes STDERR after deparsing has finished. this suppresses the Syntax OK message that perl normally produces. yes bestie, it's silencing the haters. π€«
π CONVENTIONS π
most compiler backends use the following conventions, and honestly they're consistent about it, periodt:
- OPTIONS consists of a comma-separated list of words (no white-space). no spaces. none. don't do it. π«
- the
-voption usually puts the backend into verbose mode. she's talkative. π¬ - the
-ofileoption generates output to file instead of stdout. taking it to a file, as one does. π - the
-Doption followed by various letters turns on various internal debugging flags. letters! plural! choose your own adventure. π€
see the documentation for the desired backend β named B::Backend in the example above β to find out about that backend. iykyk, go read theirs. π
π§ IMPLEMENTATION π§
this section is only necessary for those who want to write a compiler backend module that can be used via this module. so if that's not you, you can absolutely just vibe past it. π¦
the command-line mentioned in the SYNOPSIS section corresponds to the Perl code:
use O ("Backend", OPTIONS);
the O::import function loads the appropriate B::Backend module and calls its compile function, passing it OPTIONS. that function is expected to return a sub reference which we'll call CALLBACK. next, the compile-only flag is switched on (equivalent to the command-line option -c) and a CHECK block is registered which calls CALLBACK. so the main Perl program mentioned on the command-line is read in, parsed and compiled into internal syntax tree form. since the -c flag is set, the program does not start running (excepting BEGIN blocks of course) β but the CALLBACK function registered by the compiler backend is called. π
in summary, a compiler backend module should be called B::Foo for some foo and live in the appropriate directory for that name. it should define a function called compile. when the user types:
perl -MO=Foo,OPTIONS foo.pl
that function is called and is passed those OPTIONS (split on commas). it should return a sub ref to the main compilation function. after the user's program is loaded and parsed, that returned sub ref is invoked β which can then go ahead and do the compilation, usually by making use of the B module's functionality. queen behaviour, fr fr. π
π BUGS π
the -q and -qq options don't work correctly if perl isn't compiled with PerlIO support: in that case, STDOUT will be closed instead of being redirected to $O::BEGIN_output. not redirected. closed. gone. so uh. be aware. π
π AUTHOR π
Malcolm Beattie, mbeattie@sable.ox.ac.uk β the actual legend behind all of this. π«Ά
and that's the whole page, bestie! this was Perl v5.44.0, dated 2026-10-17, living in the Perl Programmers Reference Guide. go compile something cute. slay. πβ¨π
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms