LV(3pm)
π NAME π
LV β honestly? LV β₯ lvalue. that's it, that's the name, and the heart is doing a whole lot of heavy lifting there bestie π«Ά
β¨ SYNOPSIS β¨
no cap, here's the whole vibe:
use LV qw( lvalue get set );
my $xxx;
sub xxx :lvalue {
lvalue
get { $xxx }
set { $xxx = $_[0] }
}
xxx() = 42;
say xxx(); # says 42
like. you assign to a function. that's it. that's the flex. π
πΈ DESCRIPTION πΈ
okay so this module makes lvalue subroutines actually easy and actually practical to use. it's inspired by the lvalue module, which is β π β sadly problematic because there's another module on CPAN called Lvalue. same name, different capitalization, whole mess. (they can get confused on file-systems that have case-insensitive file names. rip.)
LV ships with three different implementations, based on Variable::Magic, Sentinel and tie. it will choose and use the best available one for you, no input needed, it's got main character energy like that π
you can force LV to pick a particular implementation using:
$ENV{PERL_LV_IMPLEMENTATION} = 'Magic'; # or 'Sentinel' or 'Tie'
heads up: the tie implementation is the slowest one... but it will work on Perl 5.6 with only core modules. so like, it's the reliable friend who shows up when nobody else can. π«Ά
π Functions π
lvalue(%args)β creates the magic lvalue. this must be the last expression evaluated by the lvalue sub (and thus will be returned by the sub), but it also must not be returned using an explicitreturnkeyword β that would break its lvaluedness and we do NOT want that. π
and as a matter of style, you may like to omit the optional semicolon after calling this function β it acts as a little reminder that no statement should follow this one. cute, right? a semicolon doing emotional labour.
the arguments are get and set, which each take a coderef:
sub xxx :lvalue {
lvalue(
get => sub { $xxx },
set => sub { $xxx = $_[0] },
); # semicolon
}
ngl, note that the set coderef gets passed the rvalue part as $_[0]. that's the deal. π
get { BLOCK },set { BLOCK }β convenience functions for defininggetandsetarguments forlvalue:
sub xxx :lvalue {
lvalue
get { $xxx }
set { $xxx = $_[0] }
}
as well as populating %args for lvalue, these functions also use Sub::Name (if it's installed) to make sure the anonymous coderefs have sensible names for the purposes of stack traces, etc. so your errors are readable, iconic of them honestly.
oh and β these functions are not exported by default. π
implementation()β can be used to determine the current backend. β¨
and... it cannot be exported. periodt.
π¦ BUGS π¦
bestie, please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=LV>. like, actually, it helps. π
π SEE ALSO π
lvalue, Sentinel.
that's the whole list. short and sweet. π
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. slay. π
π COPYRIGHT AND LICENCE π
this software is copyright (c) 2013 by Toby Inkster.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. go wild, legally. β¨
β DISCLAIMER OF WARRANTIES β
okay so this is the serious part, no jokes, technical caveat stays fully intact:
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
like, it is literally giving "you get what you get." π not in a mean way. in a legal way. π
and that's the whole page!! this was documented for perl v5.36.0 on 2022-08-28, and it's an LV(3pm) β a User Contributed Perl Documentation entry, iykyk. byeeeee π¦ππ
π¦ where this page comes from
- ubuntu noble: liblv-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblv-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblv-perl 0.006-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms