1LV(3)                 User Contributed Perl Documentation                LV(3)
2
3
4

NAME

6       LV - LV ♥ lvalue
7

SYNOPSIS

9          use LV qw( lvalue get set );
10
11          my $xxx;
12          sub xxx :lvalue {
13             lvalue
14                get { $xxx }
15                set { $xxx = $_[0] }
16          }
17
18          xxx() = 42;
19          say xxx();    # says 42
20

DESCRIPTION

22       This module makes lvalue subroutines easy and practical to use.  It's
23       inspired by the lvalue module which is sadly problematic because of the
24       existence of another module on CPAN called Lvalue.  (They can get
25       confused on file-systems that have case-insensitive file names.)
26
27       LV comes with three different implementations, based on
28       Variable::Magic, Sentinel and "tie"; it will choose and use the best
29       available one. You can force LV to pick a particular implementation
30       using:
31
32          $ENV{PERL_LV_IMPLEMENTATION} = 'Magic'; # or 'Sentinel' or 'Tie'
33
34       The tie implementation is the slowest, but will work on Perl 5.6 with
35       only core modules.
36
37   Functions
38       "lvalue(%args)"
39           Creates the magic lvalue. This must be the last expression
40           evaluated by the lvalue sub (and thus will be returned by the sub)
41           but also must not be returned using an explicit "return" keyword
42           (which would break its lvaluedness).
43
44           As a matter of style, you may like to omit the optional semicolon
45           after calling this function, which will act as a reminder that no
46           statement should follow this one.
47
48           The arguments are "get" and "set", which each take a coderef:
49
50              sub xxx :lvalue {
51                 lvalue(
52                    get => sub { $xxx },
53                    set => sub { $xxx = $_[0] },
54                 ); # semicolon
55              }
56
57           Note that the "set" coderef gets passed the rvalue part as $_[0].
58
59       "get { BLOCK }",  "set { BLOCK }"
60           Convenience functions for defining "get" and "set" arguments for
61           "lvalue":
62
63              sub xxx :lvalue {
64                 lvalue
65                    get { $xxx }
66                    set { $xxx = $_[0] }
67              }
68
69           As well as populating %args for "lvalue", these functions also use
70           Sub::Name (if it's installed) to ensure that the anonymous coderefs
71           have sensible names for the purposes of stack traces, etc.
72
73           These functions are not exported by default.
74
75       "implementation()"
76           Can be used to determine the current backend.
77
78           Cannot be exported.
79

BUGS

81       Please report any bugs to
82       <http://rt.cpan.org/Dist/Display.html?Queue=LV>.
83

SEE ALSO

85       lvalue, Sentinel.
86

AUTHOR

88       Toby Inkster <tobyink@cpan.org>.
89
91       This software is copyright (c) 2013 by Toby Inkster.
92
93       This is free software; you can redistribute it and/or modify it under
94       the same terms as the Perl 5 programming language system itself.
95

DISCLAIMER OF WARRANTIES

97       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
98       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
99       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
100
101
102
103perl v5.32.0                      2020-07-28                             LV(3)
Impressum