logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Author

       Toby Inkster <tobyink@cpan.org>.

Bugs

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

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 CPAN called Lvalue.  (They can get
       confused on file-systems that have case-insensitive file names.)

       LV comes with three different implementations, based on Variable::Magic, Sentinel and "tie"; it will
       choose and use the best available one. You can force LV to pick a particular implementation using:

          $ENV{PERL_LV_IMPLEMENTATION} = 'Magic'; # or 'Sentinel' or 'Tie'

       The tie implementation is the slowest, but will work on Perl 5.6 with only core modules.

   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 also must not be returned using an explicit "return" keyword (which would
           break its lvaluedness).

           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.

           The arguments are "get" and "set", which each take a coderef:

              sub xxx :lvalue {
                 lvalue(
                    get => sub { $xxx },
                    set => sub { $xxx = $_[0] },
                 ); # semicolon
              }

           Note that the "set" coderef gets passed the rvalue part as $_[0].

       "get { BLOCK }",  "set { BLOCK }"
           Convenience functions for defining "get" and "set" arguments for "lvalue":

              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
           ensure that the anonymous coderefs have sensible names for the purposes of stack traces, etc.

           These functions are not exported by default.

       "implementation()"
           Can be used to determine the current backend.

           Cannot be exported.

Disclaimer Of Warranties

       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.

perl v5.36.0                                       2022-08-28                                            LV(3pm)

Name

       LV - LV ♥ lvalue

See Also

       lvalue, Sentinel.

Synopsis

          use LV qw( lvalue get set );

          my $xxx;
          sub xxx :lvalue {
             lvalue
                get { $xxx }
                set { $xxx = $_[0] }
          }

          xxx() = 42;
          say xxx();    # says 42

See Also