NAME
Data::Lock - makes variables (im)?mutable
VERSION
$Id: Lock.pm,v 1.0 2013/04/03 06:49:25 dankogai Exp dankogai $
SYNOPSIS
use Data::Lock qw/dlock dunlock/;
# note parentheses and equal
dlock( my $sv = $initial_value );
dlock( my $ar = [@values] );
dlock( my $hr = { key => value, key => value, ... } );
dunlock $sv;
dunlock $ar; dunlock \@av;
dunlock $hr; dunlock \%hv;
DESCRIPTION
dlock
makes the specified variable immutable like Readonly. Unlike Readonly which implements immutability via tie
, dlock
makes use of the internal flag of perl SV so it imposes almost no penalty.
Like Readonly, dlock
locks not only the variable itself but also elements therein.
As of verion 0.03, you can dlock
objects as well. Below is an example constructor that returns an immutable object:
sub new {
my $pkg = shift;
my $self = { @_ };
bless $self, $pkg;
dlock($self);
$self;
}
Or consider using Moose.
EXPORT
Like List::Util and Scalar::Util, functions are exported only explicitly. This module comes with dlock
and dunlock
.
use Data::Lock; # nothing imported;
use Data::Lock qw/dlock dunlock/; # imports dlock() and dunlock()
FUNCTIONS
dlock
dlock($scalar);
Locks $scalar and if $scalar is a reference, recursively locks referents.
dunlock
Does the opposite of dlock
.
SEE ALSO
AUTHOR
Dan Kogai, <dankogai+gmail at gmail.com>
BUGS
Please report any bugs or feature requests to bug-data-lock at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Lock. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Data::Lock
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2008-2013 Dan Kogai, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.