Skip to content

Commit d309e62

Browse files
committed
Add a Dist::Build mode
1 parent f7f8b77 commit d309e62

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Revision history for App-ModuleBuildTiny
22

3+
- Add a Dist::Build mode
4+
35
0.044 2024-05-19 15:58:03+0200
46
- Add support for automatic resources
57

META.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"abstract" : "A standalone authoring tool for Module::Build::Tiny",
2+
"abstract" : "A standalone authoring tool for Module::Build::Tiny and Dist::Build",
33
"author" : [
44
"Leon Timmermans <[email protected]>"
55
],
@@ -54,6 +54,7 @@
5454
"POSIX" : "0",
5555
"Parse::CPAN::Meta" : "0",
5656
"Perl::PrereqScanner" : "0",
57+
"Perl::PrereqScanner::Scanner::DistBuild" : "0",
5758
"Pod::Escapes" : "0",
5859
"Pod::Simple::Methody" : "0",
5960
"Pod::Simple::Text" : "3.23",

META.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
abstract: 'A standalone authoring tool for Module::Build::Tiny'
2+
abstract: 'A standalone authoring tool for Module::Build::Tiny and Dist::Build'
33
author:
44
- 'Leon Timmermans <[email protected]>'
55
build_requires:
@@ -52,6 +52,7 @@ requires:
5252
POSIX: '0'
5353
Parse::CPAN::Meta: '0'
5454
Perl::PrereqScanner: '0'
55+
Perl::PrereqScanner::Scanner::DistBuild: '0'
5556
Pod::Escapes: '0'
5657
Pod::Simple::Methody: '0'
5758
Pod::Simple::Text: '3.23'

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NAME
22

33
App::ModuleBuildTiny - A standalone authoring tool for
4-
Module::Build::Tiny
4+
Module::Build::Tiny and Dist::Build
55

66
DESCRIPTION
77

lib/App/ModuleBuildTiny.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ sub modulebuildtiny {
560560

561561
=head1 NAME
562562
563-
App::ModuleBuildTiny - A standalone authoring tool for Module::Build::Tiny
563+
App::ModuleBuildTiny - A standalone authoring tool for Module::Build::Tiny and Dist::Build
564564
565565
=head1 DESCRIPTION
566566

lib/App/ModuleBuildTiny/Dist.pm

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ sub preflight_check {
150150
}
151151

152152
sub scan_files {
153-
my ($files, $omit) = @_;
153+
my ($files, $omit, %extra_args) = @_;
154154
my $combined = CPAN::Meta::Requirements->new;
155155
require Perl::PrereqScanner;
156-
my $scanner = Perl::PrereqScanner->new;
156+
my $scanner = Perl::PrereqScanner->new(\%extra_args);
157157
for my $file (@{$files}) {
158158
my $prereqs = $scanner->scan_file($file);
159159
$combined->add_requirements($prereqs);
@@ -164,19 +164,30 @@ sub scan_files {
164164

165165
sub _scan_prereqs {
166166
my ($omit, %opts) = @_;
167-
my (@runtime_files, @test_files);
167+
my (@runtime_files, @test_files, @planner_files);
168168
File::Find::find(sub { push @runtime_files, $File::Find::name if -f && /\.pm$/ }, 'lib') if -d 'lib';
169169
File::Find::find(sub { push @runtime_files, $File::Find::name if -f }, 'script') if -d 'script';
170170
File::Find::find(sub { push @test_files, $File::Find::name if -f && /\.(t|pm)$/ }, 't') if -d 't';
171171

172172
my $runtime = scan_files(\@runtime_files, $omit);
173173
my $test = scan_files(\@test_files, $omit);
174174

175-
my $prereqs = CPAN::Meta::Prereqs->new({
176-
runtime => { requires => $runtime->as_string_hash },
177-
test => { requires => $test->as_string_hash },
178-
configure => { requires => { 'Module::Build::Tiny' => mbt_version() } },
179-
});
175+
my %prereqs = (
176+
runtime => { requires => $runtime->as_string_hash },
177+
test => { requires => $test->as_string_hash },
178+
);
179+
180+
if (-d 'planner') {
181+
File::Find::find(sub { push @planner_files, $File::Find::name if -f && /\.pl$/ }, 'planner');
182+
require Perl::PrereqScanner::Scanner::DistBuild;
183+
my $configure = scan_files(\@planner_files, ['strict', 'warnings', @{$omit}], extra_scanners => [ 'DistBuild' ]);
184+
$configure->add_minimum('Dist::Build' => '0.003');
185+
$prereqs{configure} = { requires => $configure->as_string_hash };
186+
} else {
187+
$prereqs{configure} = { requires => { 'Module::Build::Tiny' => mbt_version() } };
188+
}
189+
190+
my $prereqs = CPAN::Meta::Prereqs->new(\%prereqs);
180191
require CPAN::Meta::Prereqs::Filter;
181192
return CPAN::Meta::Prereqs::Filter::filter_prereqs($prereqs, %opts);
182193
}
@@ -232,13 +243,19 @@ sub new {
232243
my $license = detect_license($pod_data, $filename, \@authors, $mergedata);
233244

234245
my $load_meta = !%{ $opts{regenerate} // {} } && uptodate('META.json', 'cpanfile', 'prereqs.json', 'prereqs.yml', $mergefile);
246+
247+
my $mode = -d 'planner' ? 'DB' : 'MBT';
235248
my $meta = $load_meta ? CPAN::Meta->load_file('META.json', { lazy_validation => 0 }) : do {
236249
my ($abstract) = ($pod_data->pod('NAME') // '') =~ / \A \s+ \S+ \s? - \s? (.+?) \s* \z /x or warn "Could not parse abstract from `=head1 NAME` in $filename";
237250
my $version = $data->version($data->name) // die "Cannot parse \$VERSION from $filename";
238251

239252
my $provides = Module::Metadata->provides(version => 2, dir => 'lib');
240253
my $prereqs = load_prereqs($provides, %opts);
241-
$prereqs->{configure}{requires}{'Module::Build::Tiny'} //= mbt_version();
254+
if ($mode eq 'MBT') {
255+
$prereqs->{configure}{requires}{'Module::Build::Tiny'} //= mbt_version();
256+
} else {
257+
$prereqs->{configure}{requires}{'Dist::Build'} //= '0.003';
258+
}
242259
$prereqs->{develop}{requires}{'App::ModuleBuildTiny'} //= $VERSION;
243260
my %resources = $class->generate_resources(%opts);
244261

@@ -299,9 +316,15 @@ sub new {
299316

300317
my $dist_name = $meta->name;
301318
$files{'Build.PL'} //= do {
302-
my $minimum_mbt = prereqs_for($meta, qw/configure requires Module::Build::Tiny/);
303319
my $minimum_perl = prereqs_for($meta, qw/runtime requires perl 5.008/);
304-
"# This Build.PL for $dist_name was generated by mbtiny $VERSION.\nuse $minimum_perl;\nuse Module::Build::Tiny $minimum_mbt;\nBuild_PL();\n";
320+
my $header = "# This Build.PL for $dist_name was generated by mbtiny $VERSION.";
321+
if ($mode eq 'MBT') {
322+
my $minimum_mbt = prereqs_for($meta, qw/configure requires Module::Build::Tiny/);
323+
"$header\nuse $minimum_perl;\nuse Module::Build::Tiny $minimum_mbt;\nBuild_PL();\n";
324+
} else {
325+
my $minimum_db = prereqs_for($meta, qw/configure requires Dist::Build/);
326+
"$header\nuse $minimum_perl;\nuse Dist::Build $minimum_db;\nBuild_PL(\\\@ARGV, \\\%ENV);\n";
327+
}
305328
};
306329
$files{'META.json'} //= $meta->as_string;
307330
$files{'META.yml'} //= $meta->as_string({ version => 1.4 });

script/mbtiny

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ The following files can be generated:
129129

130130
=item * Build.PL
131131

132-
The code needed to build the dist using L<Module::Build::Tiny|Module::Build::Tiny>.
132+
The code needed to build the dist using L<Module::Build::Tiny|Module::Build::Tiny> or L<Dist::Build|Dist::Build>.
133+
134+
It will use the former unless a C<planner/> directory is present.
133135

134136
=item * MANIFEST
135137

0 commit comments

Comments
 (0)