NAME

TieConstant - package allowing creation of true scalar constants

AUTHOR

Wayne M. Syvinski, MS <wsyvinski@techcelsior.com>

COPYRIGHT NOTICE

Copyright 2003 Wayne M. Syvinski

WARRANTY

Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, neither Wayne M. Syvinski, nor anyone else, owes you anything whatseover. You have been warned.

LICENSE

You may use this software under one of the following licenses:

(1) GNU General Public License (can be found at http://www.gnu.org/copyleft/gpl.html) (2) Artistic License (can be found at http://www.perl.com/pub/language/misc/Artistic.html)

GENERAL INFORMATION

This module was developed using ActivePerl build 804, version 5.8.0, under Windows 2000 Professional. It needs to be placed in the root directory of your perl libraries.

This module was written entirely in Perl, with dependency on Exporter and Carp.

USAGE

use TieConstant;

tieconstant $constant, value; untieconstant $constant; untie $constant;

DESCRIPTION

Module TieConstant allows the creation of true scalar constants. I am aware of the constant module with the default Perl distribution, and the Tie::Const module on CPAN; however, I wanted true scalar constants for my own purposes, AND I wanted to learn about tied data structures in Perl. TMTOWTDI!

TieConstant uses tied scalars to preserve constant values even through attempted reassignment. Any attempt at scalar reassignment or double instantiation will result in a fatal error. This behavior is intentional - I presume you want to keep constants constant for a reason.

You can assign a new value to a constant through use of the untieconstant function. You can obliterate constant binding of the scalar by using the untie function.

Because the functions tieconstant and untieconstant are implemented using prototypes, you can invoke them without parentheses.

FUNCTION DESCRIPTIONS AND USE

tieconstant($constant, value)

Function tieconstant binds value to $constant. Parameter value may be a literal or variable. If value is a variable, it is passed by value, so the tying operation has no effect on the original variable.

Once value is bound to $constant, the value of the constant cannot be changed by simple scalar assignment, i.e., $constant = value2 is not allowed.

To change the value of the constant, you must explicitly invoke function untieconstant.

To unbind the scalar from "constant behavior", use untie.

untieconstant($constant)

Function untieconstant allows reassignment of the scalar, and sets the constant value of the scalar to undef. WARNING: It does not actually untie the scalar. The scalar can then receive a new constant value using function tieconstant

untie($constant)

Function untie is not implemented by package TieConstant, but is instead provided by Perl. However, it is mentioned here, because you need to call it to break the binding between the scalar and its "constant behavior".

Once you invoke untie($foo), $foo can be treated like any other scalar, including assigning values by scalar assignment (e.g. $foo = 98.765).

However, UNLIKE untieconstant, untie will NOT reset the value of the scalar to undef, but instead previous value of the scalar will be retained.