File: ExtUtilsMakeMaker.pm

package info (click to toggle)
minilla 3.1.29-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 808 kB
  • sloc: perl: 3,804; sh: 131; makefile: 18
file content (131 lines) | stat: -rw-r--r-- 3,504 bytes parent folder | download | duplicates (4)
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
package Minilla::ModuleMaker::ExtUtilsMakeMaker;
use strict;
use warnings;
use utf8;
use Data::Section::Simple qw(get_data_section);
use Text::MicroTemplate qw(render_mt);
use Data::Dumper;
use File::Spec::Functions qw(catdir rel2abs);
use File::Find ();
use TAP::Harness::Env;
use Cwd;

# This module is EXPERIMENTAL.
# You can use this. But I may change the behaviour...

use Moo;

no Moo;

use Minilla::Util qw(spew_raw);

sub generate {
    my ($self, $project) = @_;

    local $Data::Dumper::Terse = 1;
    local $Data::Dumper::Useqq = 1;
    local $Data::Dumper::Purity = 1;
    local $Data::Dumper::Indent = 1;
    local $Data::Dumper::Sortkeys = 1;
    my $content = get_data_section('Makefile.PL');
    my $mt = Text::MicroTemplate->new(template => $content, escape_func => sub { $_[0] });
    my $src = $mt->build->($project);
    spew_raw('Makefile.PL', $src);
}

sub prereqs {
    my ($self, $project) = @_;

    my %configure_requires = (
        'ExtUtils::MakeMaker' => $self->_eumm_minimum_version($project),
    );

    my $prereqs = +{
        configure => {
            requires => {
                %configure_requires,
            }
        }
    };

    for my $key (qw(tap_harness_args use_xsutil c_source allow_pureperl requires_external_bin)) {
        if( $project->$key ){
            die "$key does not supported by " . __PACKAGE__;
        }
    }
    return $prereqs;
}

sub _eumm_minimum_version {
    my ($self, $project) = @_;

    if (@{ $project->unsupported->os }) {
        return '7.26'; # os_unsupported
    }
    return '6.64'; # TEST_REQUIRES (and MYMETA)
}

sub run_tests {
    my $harness = TAP::Harness::Env->create({
        verbosity => 0,
        lib       => [ map { rel2abs(catdir(qw/blib/, $_), cwd) } qw/arch lib/ ],
        color     => -t STDOUT
    });
    my @tests = sort +_find(qr/\.t$/, 't');
    if ($ENV{RELEASE_TESTING}) {
        push @tests, sort +_find(qr/\.t$/, 'xt');
    }
    $harness->runtests(@tests)->has_errors and die;
}

sub _find {
    my ($pattern, $dir) = @_;
    my @ret;
    File::Find::find(sub { push @ret, $File::Find::name if /$pattern/ && -f }, $dir) if -d $dir;
    return @ret;
}

1;
__DATA__

@@ Makefile.PL
? my $project = shift;
? use Data::Dumper;
# =========================================================================
# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA.
# DO NOT EDIT DIRECTLY.
# =========================================================================

use 5.006;
use strict;

use ExtUtils::MakeMaker <?= $project->module_maker->_eumm_minimum_version($project) ?>;

? if ( @{ $project->unsupported->os } ) {
?   for my $os ( @{ $project->unsupported->os } ) {
os_unsupported if $^O eq <?= B::perlstring($os) ?>;
?   }

? }
? if ( @{ $project->requires_external_bin || [] } ) {
use Devel::CheckBin;

?   for my $bin ( @{ $project->requires_external_bin } ) {
check_bin('<?= $bin ?>');
?   }

? }
? my $prereqs = $project->cpan_meta->effective_prereqs;
? my $d = sub { Dumper($prereqs->merged_requirements([$_[0]], ['requires'])->as_string_hash) };
my %WriteMakefileArgs = (
    NAME     => '<?= $project->name ?>',
    DISTNAME => '<?= $project->dist_name ?>',
    VERSION  => '<?= $project->version ?>',
    EXE_FILES => [<?= $project->script_files ?>],
    CONFIGURE_REQUIRES => <?= $d->('configure') ?>,
    BUILD_REQUIRES     => <?= $d->('build') ?>,
    TEST_REQUIRES      => <?= $d->('test') ?>,
    PREREQ_PM          => <?= $d->('runtime') ?>,
);

WriteMakefile(%WriteMakefileArgs);