Scalar...nstruct(3pm)

πŸ“¦
version 0.000 Β· 2 versions
, in fedora 43

πŸ’– NAME πŸ’–

Scalar::Construct β€” bestie, it builds custom kinds of scalar for you ✨ (and yes this is the Scalar...nstruct(3pm) page, the man page just truncates it like that, she's dramatic πŸ’…)


🌸 SYNOPSIS 🌸

use Scalar::Construct qw(constant variable aliasref aliasobj);

$ref = constant($value);
$ref = variable($value);
$ref = aliasref(\$array[0]);
$ref = aliasobj($array[0]);

✨ DESCRIPTION ✨

Okay so this module hands you functions that construct Perl scalar objects. 🫢

Here's the tea: writable (aka variable) scalars? You can literally just make those with the ordinary facilities of the Perl language, no big deal, main character energy. But immutable (constant) scalars? Those need a library. This one. That's the whole reason she exists, periodt. πŸ‘‘


πŸŽ€ FUNCTIONS πŸŽ€

Not me giving every function two names πŸ™ˆ β€” there's a longer descriptive name for the vibes, and a shorter name to spare screen space and the programmer's fingers. Both slay equally.

  • constant(VALUE)
  • ro(VALUE)

Creates a fresh immutable scalar, with value VALUE, and returns a reference to it. 🧊

Now listen, because this part matters. If VALUE is actually a compile-time constant that can be expressed as a literal, like 123, you'd think you could get a reference to a constant object with that value from a Perl expression like "\123". You would be wrong, bestie. 😭 Perl has some bugs relating to compile-time constants that stop this working as intended. On Perls built for threading (even if threading isn't actually used), such a scalar gets copied at surprising times, losing both its object identity and its immutability. πŸ’€ The function this module supplies avoids these problems. Slay.

  • variable(VALUE)
  • rw(VALUE)

Creates a fresh writable scalar, initialised to value VALUE, and returns a reference to it. 🌱

  • aliasref(OBJECT_REF)
  • ar(OBJECT_REF)

OBJECT_REF must be a reference to a scalar. Returns another reference to the same scalar. (This is effectively an identity function β€” she's included for completeness, a true team player 🫑.)

⚠️ Due to the Perl bugs discussed above for "constant", it is unwise to attempt to alias a compile-time constant. Instead use "constant" to create a well-behaved constant scalar. Don't fight the bugs, babe. πŸ™…β€β™€οΈ
  • aliasobj(OBJECT)
  • ao(OBJECT)

Returns a reference to OBJECT. πŸͺž

⚠️ Same warning, same energy: due to the Perl bugs discussed above for "constant", it is unwise to attempt to alias a compile-time constant. Use "constant" to create a well-behaved constant scalar instead. πŸ’–

πŸ¦‹ SEE ALSO πŸ¦‹

  • Lexical::Var β€” go read her too, iykyk πŸ‘€

πŸ‘‘ AUTHOR πŸ‘‘

Andrew Main (Zefram) <zefram@fysh.org> β€” icon, legend, the moment. 🌟


Copyright (C) 2012 Andrew Main (Zefram) <zefram@fysh.org>


🌈 LICENSE 🌈

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. So generous, so giving. 🎁


okay that's the whole page bestie, no cap 🫢 this was perl v5.42.0, dated 2025-07-25, from Scalar...nstruct(3pm) β€” go forth and construct your scalars, you absolute genius πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from