Lexical::SingleAssignment - Single assignment lexical variables
# lexically scoped, like use strict
# declare a lexical normally and give it a value
my $x = "Foo";
# compile time error, no initial value provided
# compile time error, assignment after declaration
$x = "bar";
# runtime error, read only variable
my $ref = \$x;
$$ref = "bar";
# runtime error, $x is still readonly from parent scope
$x = "bar";
# no error, module not in enabled in this scope
$inner = 3;
This module implements lexically scoped single assignment lexicals.
When this module is in scope all lexical variables must be assigned a value at their declaration site, and cannot be modified afterwords.
In other words, when this module is in effect all lexicals must be assigned to exactly once, whereas normally you may assign zero or more times.
This is somewhat similar to immutable name bindings in other languages, but the SVs created are still copies (they are just readonly copies).
This module is maintained using git. You can get the latest version from git://github.com/nothingmuch/Lexical-SingleAssignment.git.
Yuval Kogman <firstname.lastname@example.org>
Copyright (c) 2009 Yuval Kogman. All rights reserved
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
To install Lexical::SingleAssignment, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.