NAME
PerlX::Let - Syntactic sugar for lexical constants
VERSION
version v0.2.0
SYNOPSIS
use PerlX::Let;
let $x = 1,
$y = "string" {
if ( ($a->($y} - $x) > ($b->{$y} + $x) )
{
something( $y, $x );
}
}
DESCRIPTION
This module allows you to define lexical constants using a new let
keyword, for example, code such as
if (defined $arg{username}) {
$row->update( { username => $arg{username} );
}
is liable to typos. You could simplify it with
let $key = "username" {
if (defined $arg{$key}) {
$row->update( { $key => $arg{$key} );
}
}
This is roughly equivalent to using
use Const::Fast;
{
const $key => "username";
if (defined $arg{$key}) {
$row->update( { $key => $arg{$key} );
}
}
However, if the variable is a scalar, or you are using Perl v5.28 or later, this uses state variables so that the value is only set once.
KNOWN ISSUES
This is an experimental version.
The parsing of assignments is rudimentary, and may fail when assigning to another variable or the result of a function.
SEE ALSO
AUTHOR
Robert Rothenberg <rrwo@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2019 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)