Front page | perl.perl5.porters |
Postings from July 2020
Re: Perl 7 - updates
From: Todd Rinaldo
July 4, 2020 00:10
Re: Perl 7 - updates
Message ID: A51A297B-FF3A-49C0-9797-1BF46618D5F2@cpanel.net
> On Jul 3, 2020, at 6:25 PM, Sawyer X <firstname.lastname@example.org> wrote:
> To summarize, the changes mentioned here are to essentially:
> * Use "use VERSION" instead of "use compat::perlX".
> * Change "use VERSION" to mean "protocol," so "use v8" on Perl 7 will work. (It's effectively "give me version 8" or "I'm writing for protocol version 8".)
> * Make this mechanism required by the user in future binaries.
> At first, I did object to this. This is because the goal, as stated by others on the list as well, I wanted zero entry barrier to beginners. While I think any obstacle is not the optimal behavior for a beginner, having a single line that is required is much more feasible and maintainable. This is because of the concept of the "protocol" (or whichever more accurate term we go with) to say that you're coding for a particular version or set of Perl features, and because making it required means it will *definitely* be there.
> It is important to note that with this change, we can provide helpful feedback for the user. If one were to run a newer binary with no "use VERSION", we could produce an output that says:
> You need to provide the version of Perl your code targets. This is done with a "use V<version number>". The following version numbers are supported:
> * "use v5": Perl 5 behavior - the previous version.
> * "use v7": Perl 7 behavior - the current version.
> * "use v8": Perl 8 behavior - the next version.
> Please pick and add one of these lines to the beginning of your code.
> ... or something to that effect. This can make it trivial to understand and add. Each version will show which versions it supports so you know what you can do. We could also explain (or include links to) which features each version has.
Concerning installing CPAN modules:
First of all, much XS code will break simply because it makes assumptions about MAJOR version and tests against MINOR version only. This is easily fixable. I've been working with atoomic and khw on it. We think that a combination of clever regexes and adding PERL_VERSION_LT & co macros to core and Devel::PPPort going forward we can address the XS issue.
I'm working on a module right now that will walk a file tree and auto-inject 'use v5;' at the top of any Perl code (as the first line of the file after any #!) that does not have use vX. It then also auto-updates the XS code with its faulty version checks. I think this will solve 99% of CPAN and the 1% outlier (I don't know of any outliers at the moment) can be fixed by hand if it needs it.
This would need to be invoked by cpan clients (not EUMM and friends) because remember: Makefile.PL is Perl code too.
I think making use vX mandatory solves many problems. It also makes for a way to label code debt. I can now easily grep my code and find out what was written during the vX era and make decisions based on that. It also makes it easy for parsers (PPI, PPR, github markdown, vim, emacs, etc.) to make better choices without guessing and sometimes getting it wrong.