1#!perl 2 3use strict; 4use warnings; 5 6# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.010 7 8use Test::More tests => 1; 9 10use ExtUtils::MakeMaker; 11use File::Spec::Functions; 12use List::Util qw/max/; 13 14my @modules = qw( 15 CPAN::Meta 16 CPAN::Meta::Requirements 17 ExtUtils::MakeMaker 18 File::Spec 19 File::Spec::Functions 20 IO::CaptureOutput 21 IO::Socket::SSL 22 List::Util 23 Mail::Box::IMAP4 24 Mail::Box::Manager 25 Mail::IMAPClient 26 Mail::Reporter 27 Mail::Transport::IMAP4 28 Probe::Perl 29 Proc::Background 30 Test::More 31 perl 32 strict 33 superclass 34 warnings 35); 36 37my %exclude = map {; $_ => 1 } qw( 38 39); 40 41my ($source) = grep { -f $_ } qw/MYMETA.json MYMETA.yml META.json/; 42$source = "META.yml" unless defined $source; 43 44# replace modules with dynamic results from MYMETA.json if we can 45# (hide CPAN::Meta from prereq scanner) 46my $cpan_meta = "CPAN::Meta"; 47my $cpan_meta_req = "CPAN::Meta::Requirements"; 48my $all_requires; 49if ( -f $source && eval "require $cpan_meta" ) { ## no critic 50 if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { 51 52 # Get ALL modules mentioned in META (any phase/type) 53 my $prereqs = $meta->prereqs; 54 delete $prereqs->{develop} if not $ENV{AUTHOR_TESTING}; 55 my %uniq = map {$_ => 1} map { keys %$_ } map { values %$_ } values %$prereqs; 56 $uniq{$_} = 1 for @modules; # don't lose any static ones 57 @modules = sort grep { ! $exclude{$_} } keys %uniq; 58 59 # If verifying, merge 'requires' only for major phases 60 if ( 1 ) { 61 $prereqs = $meta->effective_prereqs; # get the object, not the hash 62 if (eval "require $cpan_meta_req; 1") { ## no critic 63 $all_requires = $cpan_meta_req->new; 64 for my $phase ( qw/configure build test runtime/ ) { 65 $all_requires->add_requirements( 66 $prereqs->requirements_for($phase, 'requires') 67 ); 68 } 69 } 70 } 71 } 72} 73 74my @reports = [qw/Version Module/]; 75my @dep_errors; 76my $req_hash = defined($all_requires) ? $all_requires->as_string_hash : {}; 77 78for my $mod ( @modules ) { 79 next if $mod eq 'perl'; 80 my $file = $mod; 81 $file =~ s{::}{/}g; 82 $file .= ".pm"; 83 my ($prefix) = grep { -e catfile($_, $file) } @INC; 84 if ( $prefix ) { 85 my $ver = MM->parse_version( catfile($prefix, $file) ); 86 $ver = "undef" unless defined $ver; # Newer MM should do this anyway 87 push @reports, [$ver, $mod]; 88 89 if ( 1 && $all_requires ) { 90 my $req = $req_hash->{$mod}; 91 if ( defined $req && length $req ) { 92 if ( ! defined eval { version->parse($ver) } ) { 93 push @dep_errors, "$mod version '$ver' cannot be parsed (version '$req' required)"; 94 } 95 elsif ( ! $all_requires->accepts_module( $mod => $ver ) ) { 96 push @dep_errors, "$mod version '$ver' is not in required range '$req'"; 97 } 98 } 99 } 100 101 } 102 else { 103 push @reports, ["missing", $mod]; 104 105 if ( 1 && $all_requires ) { 106 my $req = $req_hash->{$mod}; 107 if ( defined $req && length $req ) { 108 push @dep_errors, "$mod is not installed (version '$req' required)"; 109 } 110 } 111 } 112} 113 114if ( @reports ) { 115 my $vl = max map { length $_->[0] } @reports; 116 my $ml = max map { length $_->[1] } @reports; 117 splice @reports, 1, 0, ["-" x $vl, "-" x $ml]; 118 diag "\nVersions for all modules listed in $source (including optional ones):\n", 119 map {sprintf(" %*s %*s\n",$vl,$_->[0],-$ml,$_->[1])} @reports; 120} 121 122if ( @dep_errors ) { 123 diag join("\n", 124 "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", 125 "The following REQUIRED prerequisites were not satisfied:\n", 126 @dep_errors, 127 "\n" 128 ); 129} 130 131pass; 132 133# vim: ts=2 sts=2 sw=2 et: 134