/usr/share/perl5/Test/MinimumVersion.pm is in libtest-minimumversion-perl 0.101082-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | use 5.006;
use strict;
use warnings;
package Test::MinimumVersion;
$Test::MinimumVersion::VERSION = '0.101082';
# ABSTRACT: does your code require newer perl than you think?
use base 'Exporter';
#pod =head1 SYNOPSIS
#pod
#pod Example F<minimum-perl.t>:
#pod
#pod #!perl
#pod use Test::MinimumVersion;
#pod all_minimum_version_ok('5.008');
#pod
#pod =cut
use CPAN::Meta;
use File::Find::Rule;
use File::Find::Rule::Perl;
use Perl::MinimumVersion 1.32; # numerous bugfies
use version 0.70;
use Test::Builder;
@Test::MinimumVersion::EXPORT = qw(
minimum_version_ok
all_minimum_version_ok
all_minimum_version_from_metayml_ok
all_minimum_version_from_metajson_ok
all_minimum_version_from_mymetayml_ok
all_minimum_version_from_mymetajson_ok
);
sub import {
my($self) = shift;
my $pack = caller;
my $Test = Test::Builder->new;
$Test->exported_to($pack);
$Test->plan(@_);
$self->export_to_level(1, $self, @Test::MinimumVersion::EXPORT);
}
sub _objectify_version {
my ($version) = @_;
$version = eval { $version->isa('version') }
? $version
: version->new($version);
}
#pod =func minimum_version_ok
#pod
#pod minimum_version_ok($file, $version);
#pod
#pod This test passes if the given file does not seem to require any version of perl
#pod newer than C<$version>, which may be given as a version string or a version
#pod object.
#pod
#pod =cut
sub minimum_version_ok {
my ($file, $version) = @_;
my $Test = Test::Builder->new;
$version = _objectify_version($version);
my $pmv = Perl::MinimumVersion->new($file);
unless (defined $pmv) {
$Test->ok(0, $file);
$Test->diag(
"$file could not be parsed: " . PPI::Document->errstr
);
return;
}
my $explicit_minimum = $pmv->minimum_explicit_version || 0;
my $minimum = $pmv->minimum_syntax_version($explicit_minimum) || 0;
my $is_syntax = 1
if $minimum and $minimum > $explicit_minimum;
$minimum = $explicit_minimum
if $explicit_minimum and $explicit_minimum > $minimum;
my %min = $pmv->version_markers;
if ($minimum <= $version) {
$Test->ok(1, $file);
} else {
$Test->ok(0, $file);
$Test->diag(
"$file requires $minimum "
. ($is_syntax ? 'due to syntax' : 'due to explicit requirement')
);
if ($is_syntax and my $markers = $min{ $minimum }) {
$Test->diag("version markers for $minimum:");
$Test->diag("- $_ ") for @$markers;
}
}
}
#pod =func all_minimum_version_ok
#pod
#pod all_minimum_version_ok($version, \%arg);
#pod
#pod Given either a version string or a L<version> object, this routine produces a
#pod test plan (if there is no plan) and tests each relevant file with
#pod C<minimum_version_ok>.
#pod
#pod Relevant files are found by L<File::Find::Rule::Perl>.
#pod
#pod C<\%arg> is optional. Valid arguments are:
#pod
#pod paths - in what paths to look for files; defaults to (bin, script, t, lib,
#pod xt/smoke, and any .pm or .PL files in the current working
#pod directory) if it contains files, they will be checked
#pod no_plan - do not plan the tests about to be run
#pod skip - files to skip; this can be useful in weird cases like gigantic
#pod files, files falsely detected as Perl, or code that uses
#pod a source filter; this should be an arrayref of filenames
#pod
#pod =cut
sub all_minimum_version_ok {
my ($version, $arg) = @_;
$arg ||= {};
$arg->{paths} ||= [
qw(bin script lib t xt/smoke),
glob("*.pm"),
glob("*.PL"),
];
$arg->{skip} ||= [];
my $Test = Test::Builder->new;
$version = _objectify_version($version);
my @perl_files;
for my $path (@{ $arg->{paths} }) {
if (-f $path and -s $path) {
push @perl_files, $path;
} elsif (-d $path) {
push @perl_files, File::Find::Rule->perl_file->in($path);
}
}
my %skip = map {; $_ => 1 } @{ $arg->{skip} };
@perl_files = grep {; ! $skip{$_} } @perl_files;
unless ($Test->has_plan or $arg->{no_plan}) {
$Test->plan(tests => scalar @perl_files);
}
minimum_version_ok($_, $version) for @perl_files;
}
#pod =func all_minimum_version_from_metayml_ok
#pod
#pod all_minimum_version_from_metayml_ok(\%arg);
#pod
#pod This routine checks F<META.yml> for an entry in F<requires> for F<perl>. If no
#pod META.yml file or no perl version is found, all tests are skipped. If a version
#pod is found, the test proceeds as if C<all_minimum_version_ok> had been called
#pod with that version.
#pod
#pod =cut
sub __version_from_meta {
my ($fn) = @_;
my $meta = CPAN::Meta->load_file($fn, { lazy_validation => 1 })->as_struct;
my $version = $meta->{prereqs}{runtime}{requires}{perl};
}
sub __from_meta {
my ($fn, $arg) = @_;
$arg ||= {};
my $Test = Test::Builder->new;
$Test->plan(skip_all => "$fn could not be found")
unless -f $fn and -r _;
$Test->plan(skip_all => "no minimum perl version could be determined")
unless my $version = __version_from_meta($fn);
all_minimum_version_ok($version, $arg);
}
sub all_minimum_version_from_metayml_ok {
__from_meta('META.yml', @_);
}
#pod =func all_minimum_version_from_metajson_ok
#pod
#pod all_minimum_version_from_metajson_ok(\%arg);
#pod
#pod This routine checks F<META.json> for an entry in F<requires> for F<perl>. If
#pod no META.json file or no perl version is found, all tests are skipped. If a
#pod version is found, the test proceeds as if C<all_minimum_version_ok> had been
#pod called with that version.
#pod
#pod =cut
sub all_minimum_version_from_metajson_ok { __from_meta('META.json', @_); }
#pod =func all_minimum_version_from_mymetayml_ok
#pod
#pod all_minimum_version_from_mymetayml_ok(\%arg);
#pod
#pod This routine checks F<MYMETA.yml> for an entry in F<requires> for F<perl>. If
#pod no MYMETA.yml file or no perl version is found, all tests are skipped. If a
#pod version is found, the test proceeds as if C<all_minimum_version_ok> had been
#pod called with that version.
#pod
#pod =cut
sub all_minimum_version_from_mymetayml_ok { __from_meta('MYMETA.yml', @_); }
#pod =func all_minimum_version_from_mymetajson_ok
#pod
#pod all_minimum_version_from_mymetajson_ok(\%arg);
#pod
#pod This routine checks F<MYMETA.json> for an entry in F<requires> for F<perl>. If
#pod no MYMETA.json file or no perl version is found, all tests are skipped. If a
#pod version is found, the test proceeds as if C<all_minimum_version_ok> had been
#pod called with that version.
#pod
#pod =cut
sub all_minimum_version_from_mymetajson_ok { __from_meta('MYMETA.json', @_); }
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Test::MinimumVersion - does your code require newer perl than you think?
=head1 VERSION
version 0.101082
=head1 SYNOPSIS
Example F<minimum-perl.t>:
#!perl
use Test::MinimumVersion;
all_minimum_version_ok('5.008');
=head1 FUNCTIONS
=head2 minimum_version_ok
minimum_version_ok($file, $version);
This test passes if the given file does not seem to require any version of perl
newer than C<$version>, which may be given as a version string or a version
object.
=head2 all_minimum_version_ok
all_minimum_version_ok($version, \%arg);
Given either a version string or a L<version> object, this routine produces a
test plan (if there is no plan) and tests each relevant file with
C<minimum_version_ok>.
Relevant files are found by L<File::Find::Rule::Perl>.
C<\%arg> is optional. Valid arguments are:
paths - in what paths to look for files; defaults to (bin, script, t, lib,
xt/smoke, and any .pm or .PL files in the current working
directory) if it contains files, they will be checked
no_plan - do not plan the tests about to be run
skip - files to skip; this can be useful in weird cases like gigantic
files, files falsely detected as Perl, or code that uses
a source filter; this should be an arrayref of filenames
=head2 all_minimum_version_from_metayml_ok
all_minimum_version_from_metayml_ok(\%arg);
This routine checks F<META.yml> for an entry in F<requires> for F<perl>. If no
META.yml file or no perl version is found, all tests are skipped. If a version
is found, the test proceeds as if C<all_minimum_version_ok> had been called
with that version.
=head2 all_minimum_version_from_metajson_ok
all_minimum_version_from_metajson_ok(\%arg);
This routine checks F<META.json> for an entry in F<requires> for F<perl>. If
no META.json file or no perl version is found, all tests are skipped. If a
version is found, the test proceeds as if C<all_minimum_version_ok> had been
called with that version.
=head2 all_minimum_version_from_mymetayml_ok
all_minimum_version_from_mymetayml_ok(\%arg);
This routine checks F<MYMETA.yml> for an entry in F<requires> for F<perl>. If
no MYMETA.yml file or no perl version is found, all tests are skipped. If a
version is found, the test proceeds as if C<all_minimum_version_ok> had been
called with that version.
=head2 all_minimum_version_from_mymetajson_ok
all_minimum_version_from_mymetajson_ok(\%arg);
This routine checks F<MYMETA.json> for an entry in F<requires> for F<perl>. If
no MYMETA.json file or no perl version is found, all tests are skipped. If a
version is found, the test proceeds as if C<all_minimum_version_ok> had been
called with that version.
=head1 AUTHOR
Ricardo Signes
=head1 CONTRIBUTORS
=for stopwords Ricardo SIGNES Steve Hay
=over 4
=item *
Ricardo SIGNES <rjbs@codesimply.com>
=item *
Ricardo SIGNES <rjbs@cpan.org>
=item *
Steve Hay <steve.m.hay@googlemail.com>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2007 by Ricardo Signes.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|