Scalar::Construct - build custom kinds of scalar
use Scalar::Construct qw(constant variable aliasref aliasobj); $ref = constant($value); $ref = variable($value); $ref = aliasref(\$array); $ref = aliasobj($array);
This module supplies functions to construct Perl scalar objects. While writable (variable) scalars can easily be constructed using the ordinary facilities of the Perl language, immutable (constant) scalars require a library such as this.
Each function has two names. There is a longer descriptive name, and a shorter name to spare screen space and the programmer's fingers.
Creates a fresh immutable scalar, with value VALUE, and returns a reference to it.
If VALUE is actually a compile-time constant that can be expressed as a literal, such as
123, it would appear that a reference to a constant object with that value can be created by a Perl expression such as
\123. However, Perl has some bugs relating to compile-time constants that prevent this working as intended. On Perls built for threading (even if threading is not actually used), such a scalar will be copied at surprising times, losing both its object identity and its immutability. The function supplied by this module avoids these problems.
Creates a fresh writable scalar, initialised to value VALUE, and returns a reference to it.
OBJECT_REF must be a reference to a scalar. Returns another reference to the same scalar. (This is effectively an identity function, included for completeness.)
Returns a reference to OBJECT.
Andrew Main (Zefram) <firstname.lastname@example.org>
Copyright (C) 2012 Andrew Main (Zefram) <email@example.com>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.