summaryrefslogtreecommitdiffstats
path: root/inc/MMPackageStash.pm
blob: a067fc73488f6b8db3558ce9b04ff4d04e5c77f9 (plain) (blame)
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
package inc::MMPackageStash;
use Moose;

extends 'Dist::Zilla::Plugin::MakeMaker::Awesome';

# XXX: this is pretty gross, it should be possible to clean this up later
around _build_MakeFile_PL_template => sub {
    my $orig = shift;
    my $self = shift;
    my $template = $self->$orig(@_);

    $template =~ s/(use ExtUtils::MakeMaker.*)/$1\n\ncheck_conflicts();/;

    $template .= <<'CHECK_CONFLICTS';
sub check_conflicts {
    my %conflicts = (
        'Class::MOP' => '1.09',
    );
    my $found = 0;
    for my $mod ( sort keys %conflicts ) {
        eval "require $mod";
        next if $@;

        my $installed = $mod->VERSION();
        if ( $installed le $conflicts{$mod} ) {

            print <<"EOF";

***
    This version of Package::Stash conflicts with the version of
    $mod ($installed) you have installed.

    You will need to upgrade $mod after installing
    this version of Package::Stash.
***

EOF

            $found = 1;
        }
    }

    return unless $found;

    # More or less copied from Module::Build
    return if  $ENV{PERL_MM_USE_DEFAULT};
    return unless -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT));

    sleep 4;
}
CHECK_CONFLICTS

    return $template;
};

__PACKAGE__->meta->make_immutable;
no Moose;

1;