1package Minilla::ModuleMaker::ModuleBuildTiny;
2use strict;
3use warnings;
4use utf8;
5use Data::Section::Simple qw(get_data_section);
6use Text::MicroTemplate qw(render_mt);
7use Data::Dumper;
8use File::Spec::Functions qw(catdir rel2abs);
9use File::Find ();
10use TAP::Harness::Env;
11use Cwd;
12
13use Moo;
14
15no Moo;
16
17use Minilla::Util qw(spew_raw);
18
19sub generate {
20    my ($self, $project) = @_;
21
22    local $Data::Dumper::Terse = 1;
23    local $Data::Dumper::Useqq = 1;
24    local $Data::Dumper::Purity = 1;
25    local $Data::Dumper::Indent = 0;
26    my $content = get_data_section('Build.PL');
27    my $mt = Text::MicroTemplate->new(template => $content, escape_func => sub { $_[0] });
28    my $src = $mt->build->($project);
29    spew_raw('Build.PL', $src);
30}
31
32sub validate {
33    my $self = shift;
34
35    if (-d 'bin/') {
36        warn "[ERROR] Module::Build::Tiny doesn't install bin/ directory. You should rename bin/ to script/\n";
37        return 0;
38    }
39    return 1; # Yes. It's valid project.
40}
41
42sub prereqs {
43    my ($self, $project) = @_;
44
45    my %configure_requires = (
46        'Module::Build::Tiny' => '0.035',
47    );
48    if ( @{$project->requires_external_bin || []} ) {
49        $configure_requires{'Devel::CheckBin'} = 0;
50    }
51
52    my $prereqs = +{
53        configure => {
54            requires => {
55                %configure_requires,
56            }
57        }
58    };
59
60    for my $key (qw(tap_harness_args use_xsutil c_source allow_pureperl)) {
61        if( $project->$key ){
62            die "$key does not supported by " . __PACKAGE__;
63        }
64    }
65    for my $key (qw(PL_files)) {
66        if( $project->$key && ref($project->$key) eq 'HASH' && %{$project->$key} > 0 ){
67            die "$key does not supported by " . __PACKAGE__;
68        }
69    }
70    return $prereqs;
71}
72
73sub run_tests {
74    my $harness = TAP::Harness::Env->create({
75        verbosity => 0,
76        lib       => [ map { rel2abs(catdir(qw/blib/, $_), cwd) } qw/arch lib/ ],
77        color     => -t STDOUT
78    });
79    my @tests = sort +_find(qr/\.t$/, 't');
80    if ($ENV{RELEASE_TESTING}) {
81        push @tests, sort +_find(qr/\.t$/, 'xt');
82    }
83    $harness->runtests(@tests)->has_errors and die;
84}
85
86sub _find {
87    my ($pattern, $dir) = @_;
88    my @ret;
89    File::Find::find(sub { push @ret, $File::Find::name if /$pattern/ && -f }, $dir) if -d $dir;
90    return @ret;
91}
92
931;
94__DATA__
95
96@@ Build.PL
97? my $project = shift;
98# =========================================================================
99# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA.
100# DO NOT EDIT DIRECTLY.
101# =========================================================================
102
103use 5.008_001;
104use strict;
105
106use Module::Build::Tiny 0.035;
107
108? if ( @{ $project->requires_external_bin || [] } ) {
109use Devel::CheckBin;
110
111?   for my $bin ( @{ $project->requires_external_bin } ) {
112check_bin('<?= $bin ?>');
113?   }
114
115? }
116Build_PL();
117
118