note
Tux
<p>Both [https://github.com/neilb/Perl-MinimumVersion/blob/master/script/perlver|<c>perlver</c>] (from [metamod://Perl::MinimumVersion]) and [https://github.com/tokuhirom/Perl-MinimumVersion-Fast/blob/master/script/perlver-fast|<c>perlver-fast</c>] (from [metamod://Perl::MinimumVersion::Fast], which is much faster, but requires perl-5.8.0 and up) are extremely useful, but both lack some covarage, and I personally miss support for <c>-e</c>.</p>
<p>Another problem is that both only report a single issue:</p>
<code>
$ cat test.pl
#!/usr/bin/perl
use strict;
use warnings; # Requires 5.6.0
my $a = 5;
-e -f -s $0 and print "0\n"; # Requires 5.8.0
1 < $a < 10 and print "1\n"; # Requires 5.31.11 / 5.32.0
$a //= 42; # Requires 5.10.0
$a =~ s{0\K}{}; # Requires 5.10.0
$b = $a =~ s{0}{1}r; # Requires 5.14.0
$ perlver --blame test.pl
------------------------------------------------------------
File : test.pl
Line : 12
Char : 12
Rule : _regex
Version : 5.013002
------------------------------------------------------------
s{0}{1}r
------------------------------------------------------------
</code>
<p><c>perlver-fast</c> does not support <c>--blame</c> :(</p>
<code>
$ perlver-fast test.pl
test.pl: 5.010
</code>
<p>If you replace the script of <c>perlver-fast</c> with this code:</p>
<code>
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long qw(:config bundling passthrough);
use Perl::MinimumVersion::Fast;
GetOptions (
"e:s" => \my $expr,
"v" => \my $verbose,
) or die;
if (@ARGV) {
report ($_, $_) for @ARGV;
}
elsif ($expr) {
report ("-e", \$expr);
}
else {
my $src = do { local $/; <> };
report ("STDIN", \$src);
}
sub report {
my ($in, $src) = @_;
my $v = Perl::MinimumVersion::Fast->new ($src);
printf "%s: %s / %s\n", $in, $v->minimum_version, $v->minimum_syntax_version;
$verbose or return;
my @markers = $v->version_markers;
while (@markers) {
my ($pv, $m) = splice @markers, 0, 2;
printf "%-10s %s\n", $pv, $_ for @$m;
}
}
</code>
<p>You have support for <c>-e</c>:</p>
<code>
$ perlver-fast -e '$a //= 4'
-e: 5.010 / 5.010
</code>
<p>where it would otherwise fail with <c>Unknown file: -e at ...</c></p>
<p>With this modified version you can also show the reason<b>s</b> (with <c>-v</c>)</p>
<code>
$ perlver-fast -ve '$a //= 4; package foo 0.04 { 1; }'
-e: 5.014 / 5.014
5.010 //= operator
5.012 package NAME VERSION
5.014 package NAME VERSION BLOCK
</code>
<p>It however does not (yet) detect <c>\K</c> or <c>s{}{}r</c> (issues are created)</p>
<code>
$ perlver-fast -ve '$a = "fo" =~ s{f\K}{o}r'
-e: 5.006 / 5.006
</code>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-200365">
<br />
Enjoy, Have FUN! H.Merijn
</div></div>
11124766
11124772