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 like v5.16.1
  • $] β†’ a constant like 5.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