| 1 |
NAME |
| 2 |
Scalar::Readonly - functions for controlling whether any scalar variable |
| 3 |
is read-only |
| 4 |
|
| 5 |
SYNOPSIS |
| 6 |
use Scalar::Readonly ':all'; |
| 7 |
my $foo = "foo"; |
| 8 |
readonly_on($foo); |
| 9 |
$foo = "bar"; #ERROR! |
| 10 |
|
| 11 |
if (readonly($foo)) { |
| 12 |
readonly_off($foo); |
| 13 |
} |
| 14 |
|
| 15 |
readonly_off($]); |
| 16 |
$] = "6.0"; |
| 17 |
|
| 18 |
print "This is Perl v$]"; |
| 19 |
|
| 20 |
DESCRIPTION |
| 21 |
This simple module can make scalars read-only. Useful to protect |
| 22 |
configuration variables, for example. |
| 23 |
|
| 24 |
This module can also be used to subvert Perl's many read-only variables |
| 25 |
to potential evil trickery. |
| 26 |
|
| 27 |
readonly |
| 28 |
Ths function takes a scalar variable and tells you whether it is |
| 29 |
read-only. It returns 0 if the scalar isn't read-only, and a positive |
| 30 |
number if it is. |
| 31 |
|
| 32 |
readonly_on |
| 33 |
Makes the passed scalar variable read-only. If you try and modify a |
| 34 |
read-only scalar, your code will die with the following error message: |
| 35 |
|
| 36 |
Modification of a read-only value attempted at |
| 37 |
|
| 38 |
readonly_off |
| 39 |
Makes the passed scalar variable read-write. You can even do this to |
| 40 |
read-only special variables, though you almost certainly don't want to |
| 41 |
do that. |
| 42 |
|
| 43 |
EXPORT |
| 44 |
':all' => readonly, readonly_on, readonly_off |
| 45 |
|
| 46 |
SEE ALSO |
| 47 |
Scalar::Util, Attribute::Constant, Const::Fast. |
| 48 |
|
| 49 |
AUTHOR |
| 50 |
Philippe M. Chiasson, <[email protected]> |
| 51 |
|
| 52 |
COPYRIGHT AND LICENSE |
| 53 |
Copyright (C) 2004 by Philippe M. Chiasson |
| 54 |
|
| 55 |
This library is free software; you can redistribute it and/or modify it |
| 56 |
under the same terms as Perl itself, either Perl version 5.8.3 or, at |
| 57 |
your option, any later version of Perl 5 you may have available. |
| 58 |
|