#!perl
my
@modules
=
qw(
CPAN::Meta
CPAN::Meta::Requirements
Carp
ExtUtils::MakeMaker
File::Spec::Functions
Git::Wrapper
List::Util
Module::Build
Moo
Path::Tiny
Scalar::Util
Sort::Versions
Sub::Exporter::Progressive
Test::Fatal
Test::More
Test::Requires
Try::Tiny
perl
strict
utf8
warnings
)
;
my
%exclude
=
map
{;
$_
=> 1 }
qw(
)
;
my
(
$source
) =
grep
{ -f
$_
}
qw/MYMETA.json MYMETA.yml META.json/
;
$source
=
"META.yml"
unless
defined
$source
;
my
$cpan_meta
=
"CPAN::Meta"
;
my
$cpan_meta_req
=
"CPAN::Meta::Requirements"
;
my
$all_requires
;
if
( -f
$source
&&
eval
"require $cpan_meta"
) {
if
(
my
$meta
=
eval
{ CPAN::Meta->load_file(
$source
) } ) {
my
$prereqs
=
$meta
->prereqs;
delete
$prereqs
->{develop}
if
not
$ENV
{AUTHOR_TESTING};
my
%uniq
=
map
{
$_
=> 1}
map
{
keys
%$_
}
map
{
values
%$_
}
values
%$prereqs
;
$uniq
{
$_
} = 1
for
@modules
;
@modules
=
sort
grep
{ !
$exclude
{
$_
} }
keys
%uniq
;
if
( 1 ) {
$prereqs
=
$meta
->effective_prereqs;
if
(
eval
"require $cpan_meta_req; 1"
) {
$all_requires
=
$cpan_meta_req
->new;
for
my
$phase
(
qw/configure build test runtime develop/
) {
$all_requires
->add_requirements(
$prereqs
->requirements_for(
$phase
,
'requires'
)
);
}
}
}
}
}
my
@reports
= [
qw/Version Module/
];
my
@dep_errors
;
my
$req_hash
=
defined
(
$all_requires
) ?
$all_requires
->as_string_hash : {};
for
my
$mod
(
@modules
) {
next
if
$mod
eq
'perl'
;
my
$file
=
$mod
;
$file
=~ s{::}{/}g;
$file
.=
".pm"
;
my
(
$prefix
) =
grep
{ -e catfile(
$_
,
$file
) }
@INC
;
if
(
$prefix
) {
my
$ver
= MM->parse_version( catfile(
$prefix
,
$file
) );
$ver
=
"undef"
unless
defined
$ver
;
push
@reports
, [
$ver
,
$mod
];
if
( 1 &&
$all_requires
) {
my
$req
=
$req_hash
->{
$mod
};
if
(
defined
$req
&&
length
$req
) {
if
( !
defined
eval
{ version->parse(
$ver
) } ) {
push
@dep_errors
,
"$mod version '$ver' cannot be parsed (version '$req' required)"
;
}
elsif
( !
$all_requires
->accepts_module(
$mod
=>
$ver
) ) {
push
@dep_errors
,
"$mod version '$ver' is not in required range '$req'"
;
}
}
}
}
else
{
push
@reports
, [
"missing"
,
$mod
];
if
( 1 &&
$all_requires
) {
my
$req
=
$req_hash
->{
$mod
};
if
(
defined
$req
&&
length
$req
) {
push
@dep_errors
,
"$mod is not installed (version '$req' required)"
;
}
}
}
}
if
(
@reports
) {
my
$vl
= max
map
{
length
$_
->[0] }
@reports
;
my
$ml
= max
map
{
length
$_
->[1] }
@reports
;
splice
@reports
, 1, 0, [
"-"
x
$vl
,
"-"
x
$ml
];
diag
"\nVersions for all modules listed in $source (including optional ones):\n"
,
map
{
sprintf
(
" %*s %*s\n"
,
$vl
,
$_
->[0],-
$ml
,
$_
->[1])}
@reports
;
}
if
(
@dep_errors
) {
diag
join
(
"\n"
,
"\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"
,
"The following REQUIRED prerequisites were not satisfied:\n"
,
@dep_errors
,
"\n"
);
}
pass;