Subject: | constant sub construction on 5.19 |
Date: | Tue, 18 Jul 2017 08:21:52 +0100 |
To: | bug-Test-Simple [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
A small part of Test-Simple fails on Perl 5.19.<3-11> because of changes
in how constant subs are managed. The attached patch fixes it. It would
be nice to have Test-Simple working on these older versions to enable
testing of other modules that run into issues dependent on Perl version.
The problem that arises is that Test2::Util::HashBase wants to construct
subs that will be constant-foldable, but the way to do that changed.
Prior to 5.19.3, "sub(){$val}" was sufficient. Perl 5.19.3 stopped that
working, for the excellent reason that the $val variable can potentially
still be mutated, so the old optimisation was actually breaking the
closure abstraction. Perl 5.20.0 restored the old behaviour, for the
good but disheartening reason that that behaviour was documented, so
it shouldn't be changed without a deprecation cycle. We can anticipate
that this will change again in some future Perl version.
The patch that I have supplied keeps the module using the old mechanism
on all the unaffected Perl versions, where the module already works.
On 5.19.<3-11> it switches to a clunkier method that leaves the actual
sub construction to the "constant" pragma, which can be trusted to know
how to do it properly.
-zefram
Message body is not shown because sender requested not to inline it.