Alt-Lexical-Var-ButSupportModernPerl

 view release on metacpan or  search on metacpan

Var.xs  view on Meta::CPAN

 * and can also participate in constant folding.
 *
 * Lexical::Var generally needs to make ops that evaluate to fixed
 * identities, that being what a name that it handles represents.
 * Normally it can do this by means of an rv2xv op applied to a const op,
 * where the const op holds an RV that references the object of interest.
 * However, rv2xv can't undergo constant folding.  Where the object is
 * a readonly scalar, we'd like it to take part in constant folding.
 * The obvious way to make it work as a constant for folding is to use a
 * const op that directly holds the object.  However, in a Perl built for
 * ithreads, the value in a const op gets moved into the pad to achieve
 * clonability, and in the process the value may be copied rather than the
 * object merely rereferenced.  Generally, the const op only guarantees
 * to provide a fixed *value*, not a fixed object identity.
 *
 * Where a const op might not preserve object identity, we can achieve
 * preservation by means of a customised variant of the const op.  The op
 * directly holds an RV that references the object of interest, and its
 * variant pp function dereferences it (as rv2sv would).  The pad logic
 * operates on the op structure as normal, and may copy the RV without
 * preserving its identity, which is OK because the RV isn't what we

lib/Lexical/Var.pm  view on Meta::CPAN

Subroutine calls that have neither sigil nor parentheses (around the
argument list) are subject to an ambiguity with indirect object syntax.
If the first argument expression begins with a bareword or a scalar
variable reference then the Perl parser is liable to interpret the call as
an indirect method call.  Normally this syntax would be interpreted as a
subroutine call if the subroutine exists, but the parser doesn't look at
lexically-defined subroutines for this purpose.  The call interpretation
can be forced by prefixing the first argument expression with a C<+>,
or by wrapping the whole argument list in parentheses.

On Perls built for threading (even if threading is not actually used),
scalar constants that are defined by literals in the Perl source don't
reliably maintain their object identity.  What appear to be multiple
references to a single object can end up behaving as references
to multiple objects, in surprising ways.  The multiple objects all
initially have the correct value, but they can be writable even though the
original object is a constant.  See Perl bug reports [perl #109744] and
[perl #109746].  This can affect objects that are placed in the lexical
namespace, just as it can affect those in package namespaces or elsewhere.
C<Lexical::Var> avoids contributing to the problem itself, but certain
ways of building the parameters to C<Lexical::Var> can result in the

t/scalar_ident.t  view on Meta::CPAN

use warnings;
use strict;

use Test::More tests => 5*6;

BEGIN { $^H |= 0x20000 if "$]" < 5.008; }

$SIG{__WARN__} = sub { die "WARNING: $_[0]" };

# The \5 test fails unfairly under MAD+threads due to [perl #109746].
my $bug109746 = do { my $a = \123; my $b = \$$a; $a != $b };

our $x = undef;
our $y = 1;
our($oref, $aref, $bref, $cref, $dref);
foreach(
	\$x,
	\$y,
	do { my $x = 6; \$x },
	sub { my $x = 7; \$x }->(),



( run in 0.271 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )