.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "LV 3pm" .TH LV 3pm "2020-01-14" "perl v5.30.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" LV \- LV ♥ lvalue .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use LV qw( lvalue get set ); \& \& my $xxx; \& sub xxx :lvalue { \& lvalue \& get { $xxx } \& set { $xxx = $_[0] } \& } \& \& xxx() = 42; \& say xxx(); # says 42 .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module makes lvalue subroutines easy and practical to use. It's inspired by the lvalue module which is sadly problematic because of the existence of another module on \s-1CPAN\s0 called Lvalue. (They can get confused on file-systems that have case-insensitive file names.) .PP \&\s-1LV\s0 comes with three different implementations, based on Variable::Magic, Sentinel and \f(CW\*(C`tie\*(C'\fR; it will choose and use the best available one. You can force \s-1LV\s0 to pick a particular implementation using: .PP .Vb 1 \& $ENV{PERL_LV_IMPLEMENTATION} = \*(AqMagic\*(Aq; # or \*(AqSentinel\*(Aq or \*(AqTie\*(Aq .Ve .PP The tie implementation is the slowest, but will work on Perl 5.6 with only core modules. .SS "Functions" .IX Subsection "Functions" .ie n .IP """lvalue(%args)""" 4 .el .IP "\f(CWlvalue(%args)\fR" 4 .IX Item "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 also must not be returned using an explicit \f(CW\*(C`return\*(C'\fR keyword (which would break its lvaluedness). .Sp As a matter of style, you may like to omit the optional semicolon after calling this function, which will act as a reminder that no statement should follow this one. .Sp The arguments are \f(CW\*(C`get\*(C'\fR and \f(CW\*(C`set\*(C'\fR, which each take a coderef: .Sp .Vb 6 \& sub xxx :lvalue { \& lvalue( \& get => sub { $xxx }, \& set => sub { $xxx = $_[0] }, \& ); # semicolon \& } .Ve .Sp Note that the \f(CW\*(C`set\*(C'\fR coderef gets passed the rvalue part as \&\f(CW$_[0]\fR. .ie n .IP """get { BLOCK }"", ""set { BLOCK }""" 4 .el .IP "\f(CWget { BLOCK }\fR, \f(CWset { BLOCK }\fR" 4 .IX Item "get { BLOCK }, set { BLOCK }" Convenience functions for defining \f(CW\*(C`get\*(C'\fR and \f(CW\*(C`set\*(C'\fR arguments for \&\f(CW\*(C`lvalue\*(C'\fR: .Sp .Vb 5 \& sub xxx :lvalue { \& lvalue \& get { $xxx } \& set { $xxx = $_[0] } \& } .Ve .Sp As well as populating \f(CW%args\fR for \f(CW\*(C`lvalue\*(C'\fR, these functions also use Sub::Name (if it's installed) to ensure that the anonymous coderefs have sensible names for the purposes of stack traces, etc. .Sp These functions are not exported by default. .ie n .IP """implementation()""" 4 .el .IP "\f(CWimplementation()\fR" 4 .IX Item "implementation()" Can be used to determine the current backend. .Sp Cannot be exported. .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" lvalue, Sentinel. .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2013 by Toby Inkster. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTIES" .IX Header "DISCLAIMER OF WARRANTIES" \&\s-1THIS PACKAGE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0