Skip to content

Commit 68061bf

Browse files
authored
Merge pull request #669 from skaji/update-static-builder
pull in updates from Module::Build::Tiny
2 parents 9c01dcb + 303b415 commit 68061bf

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

Menlo/lib/Menlo/Builder/Static.pm

+31-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ use File::Path qw/mkpath/;
1313
use File::Spec::Functions qw/catfile catdir rel2abs abs2rel splitdir curdir/;
1414
use Getopt::Long 2.36 qw/GetOptionsFromArray/;
1515

16+
sub read_file {
17+
my ($filename) = @_;
18+
open my $fh, '<', $filename or die "Could not open $filename: $!\n";
19+
return do { local $/; <$fh> };
20+
}
21+
1622
sub new {
1723
my($class, %args) = @_;
1824
bless {
@@ -43,21 +49,40 @@ sub find {
4349
return @ret;
4450
}
4551

52+
sub contains_pod {
53+
my ($file) = @_;
54+
return unless -T $file;
55+
return read_file($file) =~ /^\=(?:head|pod|item)/m;
56+
}
57+
4658
my %actions = (
4759
build => sub {
4860
my %opt = @_;
49-
my %modules = map { $_ => catfile('blib', $_) } find(qr/\.p(?:m|od)$/, 'lib');
50-
my %scripts = map { $_ => catfile('blib', $_) } find(qr//, 'script');
51-
my %shared = map { $_ => catfile(qw/blib lib auto share dist/, $opt{meta}->name, abs2rel($_, 'share')) } find(qr//, 'share');
52-
pm_to_blib({ %modules, %scripts, %shared }, catdir(qw/blib lib auto/));
61+
my %modules = map { $_ => catfile('blib', $_) } find(qr/\.pm$/, 'lib');
62+
my %docs = map { $_ => catfile('blib', $_) } find(qr/\.pod$/, 'lib');
63+
my %scripts = map { $_ => catfile('blib', $_) } find(qr/(?:)/, 'script');
64+
my %sdocs = map { $_ => delete $scripts{$_} } grep { /.pod$/ } keys %scripts;
65+
my %dist_shared = map { $_ => catfile(qw/blib lib auto share dist/, $opt{meta}->name, abs2rel($_, 'share')) } find(qr/(?:)/, 'share');
66+
my %module_shared = map { $_ => catfile(qw/blib lib auto share module/, abs2rel($_, 'module-share')) } find(qr/(?:)/, 'module-share');
67+
pm_to_blib({ %modules, %docs, %scripts, %dist_shared, %module_shared }, catdir(qw/blib lib auto/));
5368
make_executable($_) for values %scripts;
5469
mkpath(catdir(qw/blib arch/), $opt{verbose});
5570

5671
if ($opt{install_paths}->install_destination('bindoc') && $opt{install_paths}->is_default_installable('bindoc')) {
57-
manify($_, catfile('blib', 'bindoc', man1_pagename($_)), $opt{config}->get('man1ext'), \%opt) for keys %scripts;
72+
my $section = $opt{config}->get('man1ext');
73+
for my $input (keys %scripts, keys %sdocs) {
74+
next unless contains_pod($input);
75+
my $output = catfile('blib', 'bindoc', man1_pagename($input));
76+
manify($input, $output, $section, \%opt);
77+
}
5878
}
5979
if ($opt{install_paths}->install_destination('libdoc') && $opt{install_paths}->is_default_installable('libdoc')) {
60-
manify($_, catfile('blib', 'libdoc', man3_pagename($_)), $opt{config}->get('man3ext'), \%opt) for keys %modules;
80+
my $section = $opt{config}->get('man3ext');
81+
for my $input (keys %modules, keys %docs) {
82+
next unless contains_pod($input);
83+
my $output = catfile('blib', 'libdoc', man3_pagename($input));
84+
manify($input, $output, $section, \%opt);
85+
}
6186
}
6287
1;
6388
},

0 commit comments

Comments
 (0)