NAME
Acme::Lvalue - Generalized lvalue subroutines
SYNOPSIS
use Acme::Lvalue qw(:builtins)
my $x;
sqrt($x) = 3; # $x == 9
hex($x) = 212; # $x eq "d4"
$x = 2;
length(sqrt($x)) = 5; # $x == 1.999396
DESCRIPTION
This module makes a number of perl builtins return lvalues, letting you assign to them. This lets you do things like:
reverse(hex $x) = '9558295373';
# $x eq 'deadbeef'
# because hex 'deadbeef' == 3735928559
# and reverse '3735928559' eq '9558295373'
When you load this module, you can pass a list of 0 or more import specifications. If you don't pass any, nothing is exported. Every import specification must be one of the following:
The string
:builtins
.This overrides the following builtins:
chr
,cos
,defined
,exp
,hex
,length
,log
,oct
,ord
,quotemeta
,reverse
,sin
,sqrt
.Any of the builtins listed above.
This lets you pick and choose which builtins to override.
An array reference of the form [NAME, CODEREF_1, CODEREF_2].
This lets you create customized invertible lvalue functions. NAME is the name of the function that should be generated, CODEREF_1 is the implementation that should be called by the function, and CODEREF_2 is the inverse operation that should be called when the result is assigned to.
That is, after
use Acme::Lvalue ['foo', $REF_1, $REF_2]
, usingfoo($x)
as normal is equivalent to$REF_1->($x)
while usingfoo($x) = $y
is equivalent to$x = $REF_2->($y)
.Example:
use Acme::Lvalue ['succ', sub { $_[0] + 1 }, sub { $_[0] - 1 }]; my $x = succ 4; # $x == 5 succ($x) = 43; # $x == 42
AUTHOR
Lukas Mai, <l.mai at web.de>
COPYRIGHT & LICENSE
Copyright 2011-2012 Lukas Mai.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.