@@ -13,6 +13,12 @@ use File::Path qw/mkpath/;
13
13
use File::Spec::Functions qw/ catfile catdir rel2abs abs2rel splitdir curdir/ ;
14
14
use Getopt::Long 2.36 qw/ GetOptionsFromArray/ ;
15
15
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
+
16
22
sub new {
17
23
my ($class , %args ) = @_ ;
18
24
bless {
@@ -43,21 +49,40 @@ sub find {
43
49
return @ret ;
44
50
}
45
51
52
+ sub contains_pod {
53
+ my ($file ) = @_ ;
54
+ return unless -T $file ;
55
+ return read_file($file ) =~ / ^\= (?:head|pod|item)/m ;
56
+ }
57
+
46
58
my %actions = (
47
59
build => sub {
48
60
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/ ));
53
68
make_executable($_ ) for values %scripts ;
54
69
mkpath(catdir(qw/ blib arch/ ), $opt {verbose });
55
70
56
71
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
+ }
58
78
}
59
79
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
+ }
61
86
}
62
87
1;
63
88
},
0 commit comments