Reputation: 3643
How to assert if the script is using too-modern version of modules?
#!/usr/bin/perl
use strict;
use warnings;
use Encode;
use version;
# no v5.00; # Works as I expected
# no Encode v2.80; # But this doesn't work
# What I want to do is:
BEGIN {
my $current = version->parse($Encode::VERSION);
my $fatal = version->parse('v2.80');
if ($current >= $fatal) {
die "Encode.pm since $fatal too modern--this is $current";
}
}
It seems like I can use function no
, to restrict module version. But no luck.
https://perldoc.perl.org/functions/no.html
no MODULE VERSION
Upvotes: 1
Views: 67
Reputation: 385764
no
performs the same check as use
.
For example, if you wanted to disable autovivification, and you needed one of the fixes in version 0.18 of the module, you'd use
no autovivification 0.18;
As such, you must indeed add your own check as you showed.
Specifically,
use Module v2.80;
is equivalent to
BEGIN {
require Module;
Module->VERSION(v2.80); # Make sure >= v2.80
Module->import();
}
while
no Module v2.80;
is equivalent to
BEGIN {
require Module;
Module->VERSION(v2.80); # Make sure >= v2.80
Module->unimport();
}
Upvotes: 1