Readonly::Tiny - Simple, correct readonly values
use Readonly::Tiny; my $x = readonly [1, 2, 3]; # $x is not readonly, but the array it points to is. my @y = (4, 5, 6); readonly \@y; # @y is readonly, as well as its contents.
Readonly::Tiny provides a simple and correct way of making values readonly. Unlike Readonly it does not cause arrays and hashes to be tied, it just uses the core SvREADONLY flag.
SvREADONLY
my $ro = readonly $ref, \%opts;
Make a data structure readonly. $ref must be a reference; the referenced value, and any values referenced recursively, will be made readonly. $ref is returned, but it will not itself be readonly; it is possible to make a variable readonly by passing a reference to it, as in the "SYNOPSIS".
$ref
%opts is a hashref of options:
%opts
Normally blessed references will not be looked through. The scalar holding the reference will be made readonly (so a different object cannot be assigned) but the contents of the object itself will be left alone. Supplying peek => 1 allows blessed refs to be looked through.
peek => 1
This should be a hashref keyed by refaddr. Any object whose refaddr is in the hash will be skipped.
Note that making a hash readonly has the same effect as calling Hash::Util::lock_hash; in particular, it causes restricted hashes to be re-restricted to their current set of keys.
Hash::Util::lock_hash
my $rw = readwrite $ref, \%opts;
Undo the effects of readonly. %opts is the same. Note that making a hash readwrite will undo any restrictions put in place using Hash::Util.
readonly
BE VERY CAREFUL calling this on values you have not made readonly yourself. It will silently ignore attempts to make the core values PL_sv_undef, PL_sv_yes and PL_sv_no readwrite, but there are many other values the core makes readonly, usually with good reason. Recent versions of perl will not allow you to make readwrite a value the core has set readonly, but you should probably not rely on this.
PL_sv_undef
PL_sv_yes
PL_sv_no
Readonly my $x, 1; Readonly my @y, 2, 3, 4; Readonly my %z, foo => 5;
This is a compatibility shim for Readonly. It is prototyped to take a reference to its first argument, and assigns the rest of the argument list to that argument before making the whole thing readonly.
readonly is exported by default. readwrite and Readonly are exported on request.
readwrite
Readonly
Please report bugs to <bug-Readonly-Tiny@rt.cpan.org>.
Ben Morrow <ben@morrow.me.uk>
Copyright 2015 Ben Morrow.
Released under the 2-clause BSD licence.
To install Readonly::Tiny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Readonly::Tiny
CPAN shell
perl -MCPAN -e shell install Readonly::Tiny
For more information on module installation, please visit the detailed CPAN module installation guide.