develooper Front page | perl.perl5.porters | Postings from July 2020

Re: Perl 7 - updates

Thread Previous | Thread Next
From:
Todd Rinaldo
Date:
July 4, 2020 06:21
Subject:
Re: Perl 7 - updates
Message ID:
040BCDE7-6057-49C4-B32C-1BC8291E55AB@cpanel.net


> On Jul 3, 2020, at 7:51 PM, Tomasz Konojacki <me@xenu.pl> wrote:
> 
> On Fri, 3 Jul 2020 19:35:58 -0500
> Todd Rinaldo <toddr@cpanel.net> wrote:
> 
>> 
>> 
>>> On Jul 3, 2020, at 7:28 PM, Kent Fredric <kentfredric@gmail.com> wrote:
>>> 
>>> On Sat, 4 Jul 2020 at 12:10, Todd Rinaldo <toddr@cpanel.net> wrote:
>>> 
>>>> 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.
>>> 
>>> Something to consider:
>>> 
>>> I recall seeing some perl scripts which had a nice little blob of code
>>> at the top, which did nothing on perl, but due to *also* being valid
>>> bash, prevented bash getting carried away trying to execute the rest
>>> of the code as bash script.
>>> 
>>> If there's a way to do that nicely, that'd be cool. ( Though I
>>> speculate this will very much fall into a hard basket, as `use vX`
>>> probably isn't valid bash )
>> 
>> This used to live at the top of some cPanel perl code until we found a better solution. It allowed the code to fall back to system perl in the event cPanel Perl was broken in some way.
>> 
>> #!/bin/sh
>> eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;'
>>  if 0;
>> 
>> #!/usr/bin/perl
>> 
>> 
>> As far as I understand, the Perl parser doesn't start parsing the code until it sees #!/usr/bin/perl in which case you just put use v7 after that line.
>> 
>> Todd
> 
> A much less obscure example of that are batch scripts generated by
> pl2bat, which is used for *all* scripts installed from CPAN on windows.
> For example, this is how cpan.bat (a wrapper of 'cpan' from CPAN.pm)
> looks like:
> 
> @rem = '--*-Perl-*--
> @echo off
> if "%OS%" == "Windows_NT" goto WinNT
> IF EXIST "%~dp0perl.exe" (
> "%~dp0perl.exe" -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
> ) ELSE IF EXIST "%~dp0..\..\bin\perl.exe" (
> "%~dp0..\..\bin\perl.exe" -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
> ) ELSE (
> perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
> )
> 
> goto endofperl
> :WinNT
> IF EXIST "%~dp0perl.exe" (
> "%~dp0perl.exe" -x -S %0 %*
> ) ELSE IF EXIST "%~dp0..\..\bin\perl.exe" (
> "%~dp0..\..\bin\perl.exe" -x -S %0 %*
> ) ELSE (
> perl -x -S %0 %*
> )
> 
> if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
> if %errorlevel% == 9009 echo You do not have Perl in your PATH.
> if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
> goto endofperl
> @rem ';
> #!/usr/local/bin/perl
> #line 29
> 
> BEGIN { pop @INC if $INC[-1] eq '.' }
> use strict;
> use vars qw($VERSION);
> 
> use App::Cpan;
> 
> # (...) more perl code
> 
> :endofperl
> 

Cool. The looks like -x will save the day here too and we can put use vX after #!/usr/local/bin/perl. Do you agree?

Todd

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About