ConstOptree(3pm)
πΈ ConstOptree β the manual page, but make it cute πΈ
Ok so bestie, this is the docs for B::ConstOptree (it's in the ConstOptree(3pm) manual, if you're keeping score π
). Sit down, hydrate, we're learning about optree constant folding for $^O, $^V, and $].
β¨ NAME β¨
B::ConstOptree β optree constant folding for $^O, $^V, and $] π¦
π SYNOPSIS π
Like, here's the whole vibe in one shot:
$ perl -MO=ConstOptree -MO=Deparse} -e \
'require ($^O eq "MSWin32" ? "Win32.pm" : "POSIX.pm")'
require 'POSIX.pm';
-e syntax OK
See how it just knew? The $^O comparison got folded, so the deparse shows the survivor: require 'POSIX.pm'; β¨ And then -e syntax OK because obviously, it ate. π
π DESCRIPTION π
So here's the tea, bestie: this module propagates constant folding for the variables $^O, $^V, and $]. π
How? It installs custom PL_check handlers for the numeric and string comparison opcodes. Like, it's getting all up in the compiler's business (respectfully π«Ά).
Inside those handlers, any reference to a $^O, $^V, or $] argument gets swapped out for a constant term. Specifically:
$^Oβ a constant like"linux"$^Vβ a constant likev5.16.1$]β a constant like5.016001
That's it. That's the whole thing. No cap. π
β οΈ CAVEATS β οΈ
Ok now the part where we keep it real. π
Regexp matching is not subject to constant folding. So expressions like $^O =~ /win32/i will not be reduced. Sorry babe, it's giving "not my department." π
π AUTHOR π
Written by Alexey Tourbin <at@altlinux.org>. π
π COPYING π
Copyright (c) 2012 Alexey Tourbin
This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
And that's the whole page, bestie π Manifesting a folder that folds your constants before you even blink. π
This was perl v5.42.3, dated 2026-08-19, brought to you by the ConstOptree(3pm) manual. Byeee π¦π
β¨
π¦ where this page comes from
- ubuntu stonking: libb-perlreq-perl 0.82-8build5 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms